eslint-plugin-sonarjs icon indicating copy to clipboard operation
eslint-plugin-sonarjs copied to clipboard

`no-duplicate-string` rule false positive on "isObjectPropertyKey" of Proxy

Open JeremyJonas opened this issue 2 years ago • 1 comments

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

  1. Create any Proxy object
  2. 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'];

JeremyJonas avatar Jul 21 '22 08:07 JeremyJonas

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;

electrovir avatar Jan 08 '24 15:01 electrovir

This issue has been migrated to Jira. ESLINTJS-24

Wohops avatar Apr 29 '24 08:04 Wohops