Giter Club home page Giter Club logo

sonarts's Introduction

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

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 --type-check --project tsconfig.json -c tslint.json 'src/**/*.ts'

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
  • Different metrics
  • More rules

See the documentation here and example project here.

Also available online on โ˜๏ธ sonarcloud.io

Contribution

Create New Rule

  • Create file for rule implementation in src/rules. File name should start with lower case and have suffix Rule
  • Create test folder in test/rules with the name of the rule file
  • In this folder create files <rule file name>.test.ts and <rule file name>.lint.ts
  • Run Ruling test
  • Add rule key to tslint-sonarts.json
  • In folder docs/rules create rule documentation file <rule key>.md
  • In README.md add reference to the documentation file.

Testing

The awesome jest test runner is used. There is just a little configuration required to enable TypeScript support.

To run unit tests:

cd sonarts-core
yarn test

To run unit tests in watch mode:

cd sonarts-core
yarn test --watch

And finally to run unit tests with coverage:

cd sonarts-core
yarn test --coverage

When you run tests with coverage, the coverage/ directory will be created at the root. You can open the web version of the coverage report coverage/lcov-report/index.html to see which lines are covered by tests.

To run unit tests for SQ plugin part of the project

cd sonarts-sq-plugin
mvn clean install

To build SQ plugin part of the project

./build.sh

Ruling

The ruling test is a special integration test which launches the analysis of a large code base, and then compares those results to the set of expected issues (stored as snapshot files). To have this code base locally:

 git submodule init
 git submodule update

To run the ruling test:

cd sonarts-core
yarn ruling
yarn ruling --rule <RuleFileName> # to run ruling for a single rule
yarn ruling --update # to update the snapshots
yarn ruling --rule <RuleFileName> --update # it is possible to combine both options

Tools we use

  • Visual Studio Code
  • Prettier (and its extension for VSCode)

sonarts's People

Contributors

vilchik-elena avatar inverno avatar stas-vilchik avatar saberduck avatar hosszubalazs avatar viperx77 avatar

Watchers

James Cloos avatar songz avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.