diff --git a/packages/eslint-plugin-fbtee/src/__tests__/no-untranslated-strings-test.tsx b/packages/eslint-plugin-fbtee/src/__tests__/no-untranslated-strings-test.tsx index 44fd5721..4e1d7040 100644 --- a/packages/eslint-plugin-fbtee/src/__tests__/no-untranslated-strings-test.tsx +++ b/packages/eslint-plugin-fbtee/src/__tests__/no-untranslated-strings-test.tsx @@ -72,7 +72,48 @@ ruleTester.run('no-untranslated-strings', rule, { }, { code: ` - <>Hello world + <>Hello world; + `, + errors: [ + { + messageId: 'unwrappedString', + }, + ], + }, + { + code: ` + {foo ? 'bar' : 'baz'}; + `, + errors: [ + { + messageId: 'unwrappedString', + }, + ], + }, + { + code: ` + {foo ?? 'bar'}; + `, + errors: [ + { + messageId: 'unwrappedString', + }, + ], + }, + { + code: ` + {foo || 'bar'}; + `, + errors: [ + { + messageId: 'unwrappedString', + }, + ], + }, + { + code: ` + const foo = true; + {foo && 'bar'}; `, errors: [ { @@ -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' + `, + }, ], }); diff --git a/packages/eslint-plugin-fbtee/src/utils.tsx b/packages/eslint-plugin-fbtee/src/utils.tsx index 3d2cce23..a3ba31db 100644 --- a/packages/eslint-plugin-fbtee/src/utils.tsx +++ b/packages/eslint-plugin-fbtee/src/utils.tsx @@ -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; }