`eslint-plugin-sonarjs` doesn’t work with eslint 9.15.0

Working with

  • eslint 9.15.0
  • eslint-plugin-sonarjs 2.0.4

I get this error

TypeError: Error while loading rule 'sonarjs/no-empty-function': Cannot read properties of undefined (reading 'allow')
Occurred while linting /Users/adrien/dev/myco/mystuff-mono/services/ui/src/test-setup.ts
    at Object.create (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint/lib/rules/no-empty-function.js:125:18)
    at create (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-empty-function.js:55:32)
    at Object.create (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:37:20)
    at Object.create (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint-plugin-sonarjs/cjs/typescript-eslint/sanitize.js:36:25)
    at Object.create (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint-plugin-sonarjs/cjs/helpers/decorators/interceptor.js:84:25)
    at createRuleListeners (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint/lib/linter/linter.js:944:21)
    at /Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint/lib/linter/linter.js:1082:84
    at Array.forEach (<anonymous>)
    at runRules (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint/lib/linter/linter.js:1013:34)
    at #flatVerifyWithoutProcessors (/Users/adrien/dev/myco/mystuff-mono/services/ui/node_modules/eslint/lib/linter/linter.js:1911:31)

It looks pretty familiar to this typescript-eslint issue which was fixed by this PR

Hello @Adrien-D,

Welcome to the Sonar community, and thank you for your feedback!

I apologize for the compatibility issue between the SonarJS ESLint plugin and ESLint version 9.15. We are aware of this problem and are actively working on a solution. We plan to release a fixed version of the plugin by the end of next week.

In the meantime, we recommend using ESLint version 9.14 as a temporary workaround.

I hope this helps!

Best regards,
Yassin

While we wait for a fix, the below patch gets things working for me. My intention is to remove the patch when the sonarjs fix is out.

diff --git a/node_modules/eslint/lib/.DS_Store b/node_modules/eslint/lib/.DS_Store
new file mode 100644
index 0000000..23bac10
Binary files /dev/null and b/node_modules/eslint/lib/.DS_Store differ
diff --git a/node_modules/eslint/lib/rules/no-empty-function.js b/node_modules/eslint/lib/rules/no-empty-function.js
index 16e611b..665e388 100644
--- a/node_modules/eslint/lib/rules/no-empty-function.js
+++ b/node_modules/eslint/lib/rules/no-empty-function.js
@@ -122,7 +122,8 @@ module.exports = {
     },
 
     create(context) {
-        const [{ allow }] = context.options;
+        const [opts] = context.options;
+        const allow = opts?.allow ?? [];
         const sourceCode = context.sourceCode;
 
         /**
diff --git a/node_modules/eslint/lib/rules/no-unused-expressions.js b/node_modules/eslint/lib/rules/no-unused-expressions.js
index fd1437c..2973453 100644
--- a/node_modules/eslint/lib/rules/no-unused-expressions.js
+++ b/node_modules/eslint/lib/rules/no-unused-expressions.js
@@ -71,12 +71,11 @@ module.exports = {
     },
 
     create(context) {
-        const [{
-            allowShortCircuit,
-            allowTernary,
-            allowTaggedTemplates,
-            enforceForJSX
-        }] = context.options;
+        const [opts] = context.options;
+        const allowShortCircuit = opts?.allowShortCircuit ?? false;
+        const allowTernary = opts?.allowTernary ?? false;
+        const allowTaggedTemplates = opts?.allowTaggedTemplates ?? false;
+        const enforceForJSX = opts?.enforceForJSX ?? false;
 
         /**
          * Has AST suggesting a directive.

A more active topic: Eslint 9.15 breaks the eslint plugin - #9 by szape89

Hello @David_Gettins and @Adrien-D,

can you please try with 3.0.1 and let us know if that fixes the issue, please?

Cheers

Hello Victor,

Thanks for getting back to me, I just tried with

  • eslint 9.16.0
  • eslint-plugin-sonarjs 3.0.1

and I get this error :

ESLint: 9.16.0

TypeError: Key "rules": Key "sonarjs/sonar-max-params": Could not find "sonar-max-params" in plugin "sonarjs".
 
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Hello,

yes, sorry I should have mentioned that since v3.0.0 we decided to drop some rules that were provided by other ESLint plugins. You can find the reasoning in this other post.

Cheers

Ok so that fixes the issue, now everything is back to normal. Thanks for your support !