You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Tom 0d0a872e85 first commit 1 year ago
public first commit 1 year ago
.eslintrc.js first commit 1 year ago first commit 1 year ago
index.js first commit 1 year ago
package.json first commit 1 year ago
yarn.lock first commit 1 year ago

EsLint SonarJS Example

This example project demonstrates how you can add sonarjs into your eslint pipeline to get Bug Detection and Code Smell Detection.

SonarJS is a plugin module used in SonarQube, it has several rules built out to provide insight into your source code:

  • Bug Detection
  • Code Smells

Setup Steps

  1. install eslint
  2. configure eslint
  3. install eslint-plugin-sonarjs
  4. configure eslint-plugin-sonarjs
  5. add to npm scripts
  6. add pre-commit hook using husky

Install eslint

yarn add -D eslint

configure eslint

npx eslint --init

Answer all the questions, based on your project type. The last question in regards to configuration file, I choose js

install eslint-plugin-sonarjs

yarn add -D eslint-plugin-sonarjs

configure sonarjs

Open .eslintrc.js

Add a plugins section if it does not exist and update the extends section to include sonarjs

module.exports = {
  "extends": ["eslint/recommended","plugin:sonarjs/recommended"],
  "plugins": ["sonarjs"]

add to npm scripts

Open the package.json file and add a new cmd to the scripts section.

  "scripts": {
    "lint": "eslint *.js"

or if you like the command-line:

npx json -I -f package.json -e 'this.scripts = {...this.scripts, lint: "eslint *.js"}'

add husky pre-commit hook

yarn add -D husky
npx json -I -f package.json -e 'this.hooks = {...this.hooks, "pre-commit": "yarn lint"}'

Typescript option is available too