Skip to end of metadata
Go to start of metadata

By SonarSource – GNU LGPL 3 – Issue TrackerSources – Supported by SonarSource
More versions
SonarTS 1.5 – Jan 26, 2018 – SonarQube 6.7+ (Compatible with LTS)
Support for SonarLint for VSCode
DownloadRelease notes

Description

Enables the powerful SonarTS analyzer.

Prerequisites

  • TypeScript version >=2.2

  • Node.js >=6

First Analysis of a TypeScript Project

  1. Install SonarQube Server (see Setup and Upgrade for more details)
  2. Install SonarQube Scanner and be sure your can call sonar-scanner from the directory where you have your source code
  3. Install SonarTS (see Installing a Plugin for more details)

  4. If missing, install node.js on the machine where you run analysis
  5. In your project, make sure to have typescript as a project dependency or dev dependency. If it's not the case, add it : cd your-project-folder; npm install --only=dev typescript

    1. If you can't have typescript as a project dependency you can set your 'NODE_PATH' variable to point to your globally installed typescript, but this is generally discouraged in the node.js documentation.

  6. Run your analysis with the SonarQube Scanner by executing the following command from the root directory of the project:

    sonar-scanner -Dsonar.projectKey=xxx -Dsonar.sources=.
  7. Follow the link provided at the end of the analysis to browse your project's quality in SonarQube UI

Further Analyses

Assuming steps 1-3 above have already been completed, you'll want to encapsulate your analysis parameters in a sonar-project.properties file at the root of your project (see a sample project on GitHub: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner). Then subsequent analyses can simply be run with:

sonar-scanner

Configuring Rule Profile

SonarTS provides 2 rule profiles out of the box: "Sonar way" (default) and "Sonar way Recommended".

"Sonar way" Profile

"Sonar way" profile is activated by default. It defines a trimmed list of high-value/low-noise rules useful in almost any TypeScript development context. You can check out the list of rules belonging to "Sonar way" on SonarCloud.

"Sonar way Recommended" Profile

"Sonar way Recommended" contains all rules from "Sonar way" (bugs and pitfall detection), plus more rules that mandate high code readability and long-term project evolution. You can check out the list of rules belonging to "Sonar way Recommended" on SonarCloud.

Above Predefined Rule Profiles

By using SonarQube UI you can create your own rule profiles and activate even more rules which are valuable in your development context.

SonarTS specific properties

SINCE 1.2.0

sonar.typescript.node

 

Can be used to explicitly set location of Node.js executable. If not set analysis will use node from the PATH

SINCE 1.3.0

sonar.typescript.exclusions


List of file path patterns to be excluded from analysis of TypeScript files. Default value is `**/node_modules/**,**/bower_components/**`




Advanced Usage

With SonarTS, you can also:

 

  • No labels