Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

SonarJS rules for ESLint

License

NotificationsYou must be signed in to change notification settings

SonarSource/eslint-plugin-sonarjs

Repository files navigation

This repository containseslint-plugin-sonarjs up to version^1.0.0. For versions>=2.0.0 please go to the repository of theSonarJS analyzer. The new versions ofeslint-plugin-sonarjs makes all SonarJS rules available for ESLint users, instead of a subset as it was with^1.0.0 living here.

No new changes are expected to land here.

eslint-plugin-sonarjsnpm versionBuild StatusQuality GateCoverage

SonarJS rules for ESLint to help developers produceClean Code by detecting bugs and suspicious patterns.

Rules

Bug Detection 🐛

Rules in this category aim to find places in code that have a high chance of being bugs, i.e. don't work as intended.

Code Smell Detection 🐷

Code Smells, or maintainability issues, are raised for places of code which might be costly to change in the future. These rules also help to keep the high code quality and readability. And finally, some rules report issues on different suspicious code patterns.

Prerequisites

  • Node.js (>=16.x).
  • ESLint 8.x or 9.x (peer dependency for the plugin).

Usage

  • If you don't have ESLint yet configured for your project, followthese instructions.
  • Installeslint-plugin-sonarjs usingnpm (oryarn) for your project or globally:
npm install eslint-plugin-sonarjs --save-dev# install for your projectnpm install eslint-plugin-sonarjs -g# or install globally
  • Addeslint-plugin-sonarjs to the plugins of your ESLint config.

For ESLint 9: addplugins option to youreslint.config.js and include the recommended config to enable all rules:

import sonarjs from "eslint-plugin-sonarjs";[  sonarjs.configs.recommended,  {    "plugins": {      sonarjs,    }  }]

For ESLint 8: addplugins option to your.eslintrc andplugin:sonarjs/recommended-legacy to theextends option to enable all recommended rules:

{"plugins": ["sonarjs"],"extends": ["plugin:sonarjs/recommended-legacy"]}
  • or enable only some rules manually:
{"rules": {"sonarjs/cognitive-complexity":"error","sonarjs/no-identical-expressions":"error"// etc.  }}
  • To allow each of the rules to fully perform, use@typescript-eslint/parser as a parser for ESLint (like we do) and set theparserOptions.project option. Thanks to it, type information is available, which is beneficial or even essential for some rules.

Available Configurations

This plugin provides only arecommended configuration. Almost all rules are activated in this profile with a few exceptions (check thedisabled tag in the rules list). Therecommended configuration activates rules witherror severity.We include arecommended-legacy configuration to be backward compatible with ESLint v8, with the same rule configuration..

ESLint and Sonar

This plugin exposes to ESLint users a subset of JS/TS rules from Sonar-* products (akaSonarJS). We extracted the rules that are not available in ESLint core or other ESLint plugins to be beneficial for the ESLint community.

If you are aSonarQube orSonarCloud user, to lint your code locally, we suggest usingSonarLint IDE extension (available for VSCode, JetBrains IDEs and Eclipse). You can connect SonarLint to your SonarQube/SonarCloud project to synchronize rules configuration, issue statuses, etc.

Contributing

Do you want to participate in the development of the project? Have a look at ourcontributing guide!


[8]ページ先頭

©2009-2025 Movatter.jp