eslint-plugin-sonarjs
eslint-plugin-sonarjs copied to clipboard
`no-duplicate-string` rule false positive on "isObjectPropertyKey" of Proxy
The no-duplicate-string
rule triggers FALSE POSITIVE for object property key of Proxy.
https://github.com/SonarSource/eslint-plugin-sonarjs/blob/b211bf18a9afe22e2e36c48a25b983d4db5312a9/src/rules/no-duplicate-string.ts#L129-L131
Repro Steps
- Create any Proxy object
- Use string literal key to access properties of the Proxy object multiple times in file (3 for default threshold)
const myProxy = new Proxy({},{});
myProxy['Foo-Bar'];
myProxy['Foo-Bar'];
myProxy['Foo-Bar'];
myProxy['Foo-Bar'];
myProxy['Foo-Bar'];
This is a problem with any object that happens (for whatever reason) to have string properties that require access via bracket notation []
(as shown above) vs dot notation .
:
const myObject = {
'my-property': 4,
myProperty: 5,
};
myObject['my-property'];
myObject['my-property'];
myObject['my-property'];
// fails no-duplicate-string
myObject['my-property'];
myObject.myProperty;
myObject.myProperty;
myObject.myProperty;
// does not fail no-duplicate-string (obviously)
myObject.myProperty;
This issue has been migrated to Jira. ESLINTJS-24