Eslint-plugin-sonarjs peerDependencies conflicts

I am writing a eslint-9 sharable-config that uses eslint-plugin-sonarjs.

Here’s my eslint config:

// index.js
import js from "@eslint/js";
import prettierConfig from "eslint-config-prettier";
import * as typescriptEslintPlugin from "@typescript-eslint/eslint-plugin";
import sonarjs from "eslint-plugin-sonarjs";

export default [
  js.configs.recommended,
  sonarjs.configs.recommended,
  prettierConfig,
  {
    files: ["**/*.{js,ts,jsx,tsx}"],
    languageOptions: {
      globals: {
        Atomics: "readonly",
        SharedArrayBuffer: "readonly",
        es6: true,
        node: true,
      },
      parser: typescriptEslintPlugin.parser,
      parserOptions: {
        ecmaVersion: 2018,
        sourceType: "module",
      },
    },
    plugins: {
      "@typescript-eslint": typescriptEslintPlugin,
      sonarjs,
    },
    rules: {
      "@typescript-eslint/no-use-before-define": "off",
      "@typescript-eslint/no-inferrable-types": "off",
      "@typescript-eslint/no-unused-vars": "error",
      "@typescript-eslint/interface-name-prefix": "off",
      "@typescript-eslint/consistent-type-assertions": [
        "error",
        { assertionStyle: "angle-bracket" },
      ],
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/explicit-function-return-type": "off",
    },
  },
  {
    files: ["**/*(specs|tests)/**", "**/*.spec.ts"],
    rules: {
      "@typescript-eslint/no-empty-function": "off",
    },
  },
];

And here’s the package.json for that sharable config:

{
  "name": "@myscope/eslint-config",
  "version": "2.1.3",
  "main": "index.js",
  "type": "module",
  "license": "ISC",
  "peerDependencies": {
    "eslint": ">= 9"
  },
  "dependencies": {
    "@eslint/js": "^9.14.0",
    "@types/eslint__js": "^8.42.3",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-sonarjs": "^2.0.4",
    "typescript-eslint": "^8.13.0"
  }
}

I am getting conflicting peer dependencies with eslint-plugin-sonarjs package:

$ npm i
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @typescript-eslint/eslint-plugin@7.16.1
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^8.56.0" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
npm WARN   @typescript-eslint/eslint-plugin@"7.16.1" from eslint-plugin-sonarjs@2.0.4
npm WARN   node_modules/eslint-plugin-sonarjs
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^8.56.0" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
npm WARN     @typescript-eslint/eslint-plugin@"7.16.1" from eslint-plugin-sonarjs@2.0.4
npm WARN     node_modules/eslint-plugin-sonarjs
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @typescript-eslint/parser@7.18.0
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^8.56.0" from @typescript-eslint/parser@7.18.0
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/parser
npm WARN   peer @typescript-eslint/parser@"^7.0.0" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^8.56.0" from @typescript-eslint/parser@7.18.0
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/parser
npm WARN     peer @typescript-eslint/parser@"^7.0.0" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN     node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @typescript-eslint/utils@7.16.1
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^8.56.0" from @typescript-eslint/utils@7.16.1
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils
npm WARN   @typescript-eslint/utils@"7.16.1" from eslint-plugin-sonarjs@2.0.4
npm WARN   node_modules/eslint-plugin-sonarjs
npm WARN   2 more (@typescript-eslint/eslint-plugin, @typescript-eslint/type-utils)
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^8.56.0" from @typescript-eslint/utils@7.16.1
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils
npm WARN     @typescript-eslint/utils@"7.16.1" from eslint-plugin-sonarjs@2.0.4
npm WARN     node_modules/eslint-plugin-sonarjs
npm WARN     2 more (@typescript-eslint/eslint-plugin, @typescript-eslint/type-utils)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: eslint-plugin-import@2.30.0
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from eslint-plugin-import@2.30.0
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import
npm WARN   eslint-plugin-import@"2.30.0" from eslint-plugin-sonarjs@2.0.4
npm WARN   node_modules/eslint-plugin-sonarjs
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from eslint-plugin-import@2.30.0
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import
npm WARN     eslint-plugin-import@"2.30.0" from eslint-plugin-sonarjs@2.0.4
npm WARN     node_modules/eslint-plugin-sonarjs
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: eslint-plugin-react-hooks@4.6.2
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from eslint-plugin-react-hooks@4.6.2
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
npm WARN   eslint-plugin-react-hooks@"4.6.2" from eslint-plugin-sonarjs@2.0.4
npm WARN   node_modules/eslint-plugin-sonarjs
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from eslint-plugin-react-hooks@4.6.2
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
npm WARN     eslint-plugin-react-hooks@"4.6.2" from eslint-plugin-sonarjs@2.0.4
npm WARN     node_modules/eslint-plugin-sonarjs
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @typescript-eslint/type-utils@7.16.1
npm WARN Found: eslint@9.14.0
npm WARN node_modules/eslint
npm WARN   peer eslint@">= 9" from the root project
npm WARN   10 more (@babel/eslint-parser, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint@"^8.56.0" from @typescript-eslint/type-utils@7.16.1
npm WARN node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils
npm WARN   @typescript-eslint/type-utils@"7.16.1" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
npm WARN 
npm WARN Conflicting peer dependency: eslint@8.57.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^8.56.0" from @typescript-eslint/type-utils@7.16.1
npm WARN   node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils
npm WARN     @typescript-eslint/type-utils@"7.16.1" from @typescript-eslint/eslint-plugin@7.16.1
npm WARN     node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin

Additional information:

$ npm ls eslint

npm ERR! code ELSPROBLEMS
npm ERR! invalid: eslint@9.14.0 /home/me/github/eslint-config/node_modules/eslint
@myscope/eslint-config@2.1.3 /home/me//github/eslint-config
β”œβ”€β”¬ eslint-config-prettier@9.1.0
β”‚ └── eslint@9.14.0 deduped
β”œβ”€β”¬ eslint-plugin-sonarjs@2.0.4
β”‚ β”œβ”€β”¬ @babel/eslint-parser@7.25.1
β”‚ β”‚ └── eslint@9.14.0 deduped
β”‚ β”œβ”€β”¬ @typescript-eslint/eslint-plugin@7.16.1
β”‚ β”‚ β”œβ”€β”¬ @typescript-eslint/parser@7.18.0
β”‚ β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/parser
β”‚ β”‚ β”œβ”€β”¬ @typescript-eslint/type-utils@7.16.1
β”‚ β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/parser, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin
β”‚ β”œβ”€β”¬ @typescript-eslint/utils@7.16.1
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils
β”‚ β”œβ”€β”¬ eslint-plugin-import@2.30.0
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import
β”‚ β”œβ”€β”¬ eslint-plugin-jsx-a11y@6.10.0
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import
β”‚ β”œβ”€β”¬ eslint-plugin-react-hooks@4.6.2
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
β”‚ β”œβ”€β”¬ eslint-plugin-react@7.36.1
β”‚ β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
β”‚ β”œβ”€β”€ eslint@9.14.0 deduped
β”‚ └─┬ vue-eslint-parser@9.4.3
β”‚   └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
β”œβ”€β”¬ eslint@9.14.0
β”‚ └─┬ @eslint-community/eslint-utils@4.4.0
β”‚   └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
└─┬ typescript-eslint@8.13.0
  β”œβ”€β”¬ @typescript-eslint/eslint-plugin@8.13.0
  β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
  β”œβ”€β”¬ @typescript-eslint/parser@8.13.0
  β”‚ └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks
  └─┬ @typescript-eslint/utils@8.13.0
    └── eslint@9.14.0 deduped invalid: "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/eslint-plugin, "^8.56.0" from node_modules/eslint-plugin-sonarjs/node_modules/@typescript-eslint/utils, "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-import, "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0" from node_modules/eslint-plugin-sonarjs/node_modules/eslint-plugin-react-hooks

This problem is talked about here:

I can’t say the solution is correct, but I added this overrides to package.json, and npm install stopped complaining about unresolved peer dependencies.

"overrides": {
    "@typescript-eslint/plugin": "^8.14.0",
    "@typescript-eslint/parser": "^8.14.0",
    "@typescript-eslint/utils": "^8.14.0",
    "@typescript-eslint/eslint-plugin": "^8.14.0",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-react-hooks": "^5.0.0"
  },

Hello @Brad_Arlt and @lola,

thanks for reporting this and sorry for the late reply.

Can you please use our new version 3.0.1? In v3 we removed many rules that were modified from external plugins (those were all added in 2.0.0). We decided that from now on, we will only publish rules that are our own implementation in the ESLint plugin. Otherwise, we were tightly coupled with specific versions of typescript-eslint and other dependencies that clashed with our users’ dependencies versions. The new README.md mentions here and here which rules are no longer part of our plugin and which plugin/rule to install if needed.

Cheers,
Victor

1 Like

Hi Victor, so what does it mean for people upgrading ? We need to import additional packages ?

Because if I compare the list of rules I got before and now, it’s different, see here:

Hello @lola,

yes, if you want to have all rules as v2, you should install and enable the rules listed here and here. Those rules were shipped in order to have a ESLint experience the most similar to SonarQube, but Sonar was not the maintainer of those rules, so we decided that it did not make sense for us to ship those rules in our ESLint plugin. Also, some users were already making use of those ESLint plugins and were having duplicated issues.

Since v3, we will only ship in the ESLint plugin the rules for which we are the maintainers.

Cheers

1 Like

Makes sense thanks