Skip to content

Commit

Permalink
fix(no-unlocalized-strings): ignore Literals in computed MemberExpres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
timofei-iatsenko committed Oct 11, 2024
1 parent 3c6d349 commit 3c79d59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rules/no-unlocalized-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ export const rule = createRule<Option[], string>({
'Property > Literal'(node: TSESTree.Literal) {
onProperty(node)
},
'MemberExpression[computed=true] > Literal'(node: TSESTree.Literal) {
// obj["key with space"]
visited.add(node)
},
"AssignmentExpression[left.type='MemberExpression'] > Literal"(node: TSESTree.Literal) {
const assignmentExp = node.parent as TSESTree.AssignmentExpression
const memberExp = assignmentExp.left as TSESTree.MemberExpression
Expand Down Expand Up @@ -453,6 +457,10 @@ export const rule = createRule<Option[], string>({
visited.add(node)
}
},
'MemberExpression[computed=true] > TemplateLiteral'(node: TSESTree.TemplateLiteral) {
// obj[`key with space`]
visited.add(node)
},
'Property > TemplateLiteral'(node: TSESTree.TemplateLiteral) {
onProperty(node)
},
Expand Down
2 changes: 2 additions & 0 deletions tests/src/rules/no-unlocalized-strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ ruleTester.run<string, Option[]>(name, rule, {
code: `const test = { text: 'This is not localized' }`,
options: [{ ignoreProperty: ['text'] }],
},
{ code: `obj["key with space"] = 5` },
{ code: `obj[\`key with space\`] = 5` },
],

invalid: [
Expand Down

0 comments on commit 3c79d59

Please sign in to comment.