{"id":19939,"library":"eslint-plugin-sonarjs","title":"eslint-plugin-sonarjs","description":"ESLint plugin maintained by Sonar that provides original JS/TS rules from the SonarJS analyzer, including code smell, bug detection, testing, accessibility, and security rules. Version 4.0.3 supports ESLint 8/9/10 and ships TypeScript types. Release cadence is frequent with regular bug fixes and rule additions. Key differentiator: direct integration of SonarQube/SonarCloud rules into ESLint, offering a single recommended config for ESLint 9 and a legacy config for ESLint 8.","status":"active","version":"4.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/SonarSource/SonarJS","tags":["javascript","sonarjs","eslint","eslintplugin","typescript"],"install":[{"cmd":"npm install eslint-plugin-sonarjs","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-sonarjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-sonarjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: requires ESLint 8, 9, or 10","package":"eslint","optional":false}],"imports":[{"note":"Default import for ESLint 9 flat config. For ESLint 8 use require or the legacy config.","wrong":"const sonarjs = require('eslint-plugin-sonarjs')","symbol":"plugin","correct":"import sonarjs from 'eslint-plugin-sonarjs'"},{"note":"Recommended config for ESLint 9 flat config. For ESLint 8 use recommended-legacy.","wrong":"module.exports = { extends: ['plugin:sonarjs/recommended'] }","symbol":"recommended config","correct":"export default [sonarjs.configs.recommended]"},{"note":"Rules are prefixed with sonarjs/. Use string severity values like 'error' or 'warn'.","wrong":"rules: { 'sonarjs/no-implicit-dependencies': 2 }","symbol":"rules","correct":"rules: { 'sonarjs/no-implicit-dependencies': 'error' }"}],"quickstart":{"code":"import sonarjs from 'eslint-plugin-sonarjs';\n\nexport default [\n  sonarjs.configs.recommended,\n  {\n    rules: {\n      'sonarjs/cognitive-complexity': 'warn',\n      'sonarjs/no-identical-functions': 'error',\n    },\n  },\n];","lang":"typescript","description":"Shows usage with ESLint 9 flat config, importing plugin and enabling recommended config plus custom rules."},"warnings":[{"fix":"If using ESLint 8, use .eslintrc with extends: ['plugin:sonarjs/recommended-legacy'] instead of the flat config import.","message":"ESLint 8 users must use the recommended-legacy config, not the flat config recommended.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Check the rule list in the plugin documentation or SonarQube documentation for differences.","message":"The plugin only includes original SonarJS rules, not all rules from SonarQube JS/TS analyzer. Some popular rules (e.g., S3776 cognitive complexity) may have different behavior.","severity":"gotcha","affected_versions":"*"},{"fix":"Migrate to ESLint 9 flat config when possible.","message":"The legacy ESLint 8 config (recommended-legacy) may be removed in a future major version.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Ensure your Node.js version matches the requirement for your ESLint version.","message":"Node.js version requirements differ per ESLint version: ESLint 8 needs Node >=16, ESLint 9 needs Node ^18.18.0 || ^20.9.0 || >=21.","severity":"gotcha","affected_versions":"*"},{"fix":"Override rule severity in your config, e.g., 'sonarjs/cognitive-complexity': 'warn'.","message":"Rules enabled in recommended config have error severity by default, which may fail CI pipelines if not expected.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install eslint-plugin-sonarjs --save-dev' or the equivalent yarn command.","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'eslint-plugin-sonarjs'"},{"fix":"Ensure the plugin is properly declared in plugins field (ESLint 9) or in .eslintrc plugins array (ESLint 8). Check rule options are valid.","cause":"Using an incorrect rule configuration format or missing the plugin declaration.","error":"Configuration for rule \"sonarjs/no-identical-functions\" is invalid"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}