Unofficial and no longer actively supported SonarQube plugin for TypeScript files.

Important - unofficial, and deprecated

For a few years this plugin was essentially the only way to get Typescript analysis, unit test and code coverage information into Sonarqube. However the official SonarTS plugin is much better supported, both in support of SonarQube version upgrades and linting rules.

There will be no further updates to this plugin, and it remains here for reference only. I don't have time to continue to support it, and there's little value in doing so when the official plugin covers off almost all its functionality.

Sample projects

Some sample projects are provided to demonstrate different configuration options in the samples/ folder.



This is plugin for SonarQube 5.6+ for analysing projects with TypeScript content that supports:





Example project configuration

This is an example of what a project configuration file ( could look like:

sonar.projectName=My Application


Global configuration options

sonar.ts.tslint.ruleConfigsOptionalA list of configurations to map custom TsLint rules to dedicated SonarQube rules & settings - see TsLint Custom Rules section below

Project-level configuration options

sonar.ts.tslint.pathOptionalPath to the installed copy of `tslint` to use - will be automatically sought in node_modules next to the file if not specified
sonar.ts.tslint.configPathOptionalPath to the tslint.json file that configures the rules to be used in linting - will be automatically sought in the same folder as the file if not specified
sonar.ts.tslint.outputPathOptionalIf your existing CI process already runs `tslint` you can have the plugin re-use its output using the `outputPath` setting. The output is expected to be in JSON form
sonar.ts.excludeTypeDefinitionFilesOptionalExcludes .d.ts files from analysis, defaults to true
sonar.ts.coverage.forceZeroIfUnspecifiedOptionalForces code coverage percentage to zero for all files when no LCOV report is supplied, defaults to false
sonar.ts.coverage.ignoreNotFoundOptionalControls if a single file should be reported as 0% covered if it doesn't appear in the LCOV report, defaults to false
sonar.ts.tslint.timeoutOptionalMax time to wait for `tslint` to finish processing a single file (in milliseconds), defaults to 60 seconds
sonar.ts.tslint.rulesDirOptionalPath to a folder containing custom `tslint` rules referenced in tslint.json, if any is required
sonar.ts.coverage.lcovReportPathOptionalPath to an LCOV code-coverage report to be used to calculate coverage metrics for your project
sonar.ts.tslint.nodePathOptionalPath to custom node to execute
sonar.ts.tslint.projectPathOptionalPath to tsconfig.json that describes the TypeScript files in your project to analyse, rather than letting SonarQube search for them automatically. Required to allow sonar.ts.tslint.typeCheck to work.
sonar.ts.tslint.typeCheckOptionalIf true, asks tslint to run type-checking, allowing tslint rules that need type information to operate. Requires that you have specified sonar.ts.tslint.projectPath.

TsLint installation and configuration

By default, SonarTsPlugin will look for a version of TsLint installed locally within your project (i.e. in node_modules\tslint\bin), relative to the file. This may not be what you want, so you can set this directly via the sonar.ts.tslint.path configuration setting:

If analysis is failing, run sonar-scanner with the -X option for more diagnostic information, including a note of where the plugin is searching for tslint. Bear in mind that if running on a build server, the account running the build will need access to the path to tslint.

By default, SonarTsPlugin will look for a tslint configuration file called tslint.json next to the file. You can override this using the sonar.ts.tslint.configPath configuration setting if this isn't the case for your project.

TsLint Custom Rules

To present custom tslint rules in SonarQube analysis, you can provide a configuration that maps the rules from your sonar.ts.tslint.rulesDir directory to dedicated Sonar rules for analysis.

The configuration for a tslint Sonar rule consists of a line declaring the TSLint rule id, a boolean switch to enable or disable the rule if needed and some attached properties that are used by Sonar for analysis and reporting.

For example, let's take the export-name rule from the tslint-microsoft-contrib package. A configuration for that rule in SonarTsPlugin could look as follows:

export-name=true name of the exported module must match the filename of the source file.
export-name.description=This is case-sensitive but ignores file extension. Since version 1.0, this rule takes a list of regular expressions as a parameter. Any export name matching that regular expression will be ignored.

You will need to restart the SonarQube server after configuring custom rules this way before subsequent analyses will pick them up. You will also need to activate the new rules after restart for any quality profile you want them to participate in - by default they will be disabled.




Thanks to the following for contributions to the plugin:

With thanks