Registry / testing / eslint-plugin-sonarjs

eslint-plugin-sonarjs

JSON →
library4.0.3jsnpmunverified

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.

npm install eslint-plugin-sonarjs
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-SONA
E
eslint-plugin-sonarjs
testingjavascriptv4.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
import sonarjs from 'eslint-plugin-sonarjs'
const sonarjs = require('eslint-plugin-sonarjs')
Default import for ESLint 9 flat config. For ESLint 8 use require or the legacy config.
recommended config
export default [sonarjs.configs.recommended]
module.exports = { extends: ['plugin:sonarjs/recommended'] }
Recommended config for ESLint 9 flat config. For ESLint 8 use recommended-legacy.
rules
rules: { 'sonarjs/no-implicit-dependencies': 'error' }
rules: { 'sonarjs/no-implicit-dependencies': 2 }
Rules are prefixed with sonarjs/. Use string severity values like 'error' or 'warn'.

Shows usage with ESLint 9 flat config, importing plugin and enabling recommended config plus custom rules.

import sonarjs from 'eslint-plugin-sonarjs'; export default [ sonarjs.configs.recommended, { rules: { 'sonarjs/cognitive-complexity': 'warn', 'sonarjs/no-identical-functions': 'error', }, }, ];
Debug
Known issues
breakingESLint 8 users must use the recommended-legacy config, not the flat config recommended.
fix
If using ESLint 8, use .eslintrc with extends: ['plugin:sonarjs/recommended-legacy'] instead of the flat config import.
affects: >=4.0.0
gotchaThe 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.
fix
Check the rule list in the plugin documentation or SonarQube documentation for differences.
affects: *
deprecatedThe legacy ESLint 8 config (recommended-legacy) may be removed in a future major version.
fix
Migrate to ESLint 9 flat config when possible.
affects: >=4.0.0
gotchaNode.js version requirements differ per ESLint version: ESLint 8 needs Node >=16, ESLint 9 needs Node ^18.18.0 || ^20.9.0 || >=21.
fix
Ensure your Node.js version matches the requirement for your ESLint version.
affects: *
gotchaRules enabled in recommended config have error severity by default, which may fail CI pipelines if not expected.
fix
Override rule severity in your config, e.g., 'sonarjs/cognitive-complexity': 'warn'.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'eslint-plugin-sonarjs'
Plugin not installed or not in node_modules.
fix
Run 'npm install eslint-plugin-sonarjs --save-dev' or the equivalent yarn command.
Configuration for rule "sonarjs/no-identical-functions" is invalid
Using an incorrect rule configuration format or missing the plugin declaration.
fix
Ensure the plugin is properly declared in plugins field (ESLint 9) or in .eslintrc plugins array (ESLint 8). Check rule options are valid.
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
eslintrequiredpeer dependency: requires ESLint 8, 9, or 10
Agent activity
26 hits · last 30 days
node
22
Resources
eslint-plugin-sonarjs — npm install eslint-plugin-sonarjs · libregistry