Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch untranslated text in conditional and logical expressions #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,48 @@ ruleTester.run('no-untranslated-strings', rule, {
},
{
code: `
<>Hello world</>
<>Hello world</>;
`,
errors: [
{
messageId: 'unwrappedString',
},
],
},
{
code: `
<span>{foo ? 'bar' : 'baz'}</span>;
`,
errors: [
{
messageId: 'unwrappedString',
},
],
},
{
code: `
<span>{foo ?? 'bar'}</span>;
`,
errors: [
{
messageId: 'unwrappedString',
},
],
},
{
code: `
<span>{foo || 'bar'}</span>;
`,
errors: [
{
messageId: 'unwrappedString',
},
],
},
{
code: `
const foo = true;
<span>{foo && 'bar'}</span>;
`,
errors: [
{
Expand Down Expand Up @@ -219,5 +260,20 @@ ruleTester.run('no-untranslated-strings', rule, {
foo.bar('Baz')
`,
},
{
code: `
const foo = isGreeting ? 'Hello' : 'Goodbye'
`,
},
{
code: `
const foo = helloGreeting ?? 'goodbye'
`,
},
{
code: `
const foo = helloGreeting || 'goodbye'
`,
},
],
});
14 changes: 14 additions & 0 deletions packages/eslint-plugin-fbtee/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ export function resolveNodeValue(
return resolveNodeValue(node.expression);
}

if (node.type === 'ConditionalExpression') {
const consequent = resolveNodeValue(node.consequent);
const alternate = resolveNodeValue(node.alternate);

return consequent || alternate || null;
}

if (node.type === 'LogicalExpression') {
const left = resolveNodeValue(node.left);
const right = resolveNodeValue(node.right);

return left || right || null;
}

return null;
}

Expand Down
Loading