node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ¬Ľ

tslint-sonarts

SonarTS Build Status NPM version Quality Gate Coverage

Static code analyzer for TypeScript detecting bugs and suspicious patterns in your code.

Follow us on twitter

To analyze pure JavaScript code, see SonarJS

How does it work?

Rules

Bug Detection ūüźõ

Rules in this category aim to find places in code which has a high chance to be bugs, i.e. don't work as indented. Most of the time this is a result of bad copy-paste (no-identical-conditions) or improvident API usage (no-misleading-array-reverse). Some rules are raising issues on unused values (no-useless-increment), which is at best wasted code and at worst a bug.

Code Smell Detection ūüź∑

Code Smells issues, or Maintainability issues, are raised for places of code which might be costly to change in the future (cognitive-complexity). These rules also help to keep the high code quality and readability (no-commented-code, no-identical-functions, use-primitive-type). And finally some rules report issues on different suspicious code patters (no-dead-store, no-gratuitous-expressions).

Prerequisites

Node.js (>=6.x).

Use in TSLint

  • If you don't have TSLint yet configured for your project follow these instructions.
  • Install tslint-sonarts
npm install tslint-sonarts      # install in your project 
npm install tslint-sonarts -g   # or install globally 
  • Add tslint-sonarts to your tslint.json extends property:
{
  "extends": ["tslint:recommended", "tslint-sonarts"]
}
  • Some of the rules in SonarTS require type information. So in order to provide as much value as possible run TSLint with type-checker, for example:
tslint --project ./tsconfig.json 'src/**/*.{ts,tsx}'

Use in SonarQube

SonarTS is available as plugin for SonarQube. SonarQube is an open source platform for continuous inspection of code quality. Thanks to the platform, SonarTS provides additional features:

  • Code coverage import
  • Duplication detection
  • Various metrics
  • More rules

See the documentation here and example project here.

Also available online on ‚ėĀÔłŹ SonarCloud

Contributing

You want to participate to the development of our TypeScript analyzer? Have a look at our contributor guide!