Eslint-plugin-sonarjs error on "sonarjs/prefer-enum-initializers"

Hello,

I have an issue since the version 2 of the npmjs plug-in

The error is

ESLint: 8.57.0

TypeError: Cannot read properties of undefined (reading 'members')
Occurred while linting sonar-fail/src/index.ts:2
Rule: "sonarjs/prefer-enum-initializers"
    at anyInitialized (sonar-fail/node_modules/eslint-plugin-sonarjs/lib/S6572/decorator.js:49:21)
    at sonar-fail/node_modules/eslint-plugin-sonarjs/lib/S6572/decorator.js:42:13
    at Object.report (sonar-fail/node_modules/eslint-plugin-sonarjs/lib/helpers/decorators/interceptor.js:71:29)
    at sonar-fail/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-enum-initializers.js:25:29
    at Array.forEach (<anonymous>)
    at TSEnumDeclaration (sonar-fail/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-enum-initializers.js:22:21)
    at ruleErrorHandler (sonar-fail/node_modules/eslint/lib/linter/linter.js:1076:28)
    at sonar-fail/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (sonar-fail/node_modules/eslint/lib/linter/safe-emitter.js:45:38)

I provided a very simple repository GitHub - benoitf/sonarjs-failure

as you can see the only source code is

enum LogType {
  LOG,
  ERROR,
  WARN,
}

Hello @benoitf,

thank you very much for reporting this and for the reproducer, it has been very helpful.

Our plugin is still relying on typescript-eslint 7.16.1, while you are using 8.2.0. Seems the AST is generated differently since 8.0.0, as I’ve seen reported here.

I created a ticket to fix this.

Thanks again.
Victor

ok so I have other failures being reported but I guess that it may be related to the same conflict between the versions of typescript-eslint

ESLint: 9.9.1

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /home/runner/work/podman-desktop/podman-desktop/extensions/compose/src/cli-run.ts:29
Rule: "sonarjs/sonar-no-fallthrough"
    at SwitchCase:exit (/home/runner/work/podman-desktop/podman-desktop/node_modules/eslint-plugin-sonarjs/lib/S128/rule.js:85:69)
    at ruleErrorHandler (/home/runner/work/podman-desktop/podman-desktop/node_modules/eslint/lib/linter/linter.js:1088:48)
    at /home/runner/work/podman-desktop/podman-desktop/node_modules/eslint/lib/linter/safe-emitter.js:45:58

I suppose I need to wait that sonarjs plug-in updates its typescript-eslint dependency

Hi @benoitf,

yes, or any other fix we may come up with. In the meantime, feel free to disable that rule.

Cheers,
Victor

Hello @benoitf,

this has been fixed in version 2.0.3.

1 Like

ok thanks