I’ve recently made some changes to my SonarQube TypeScript plugin pithily named ‘SonarTsPlugin’ that:
- Make it easier to keep up to date with changes to TsLint
- Fix minor bugs
- Support custom TsLint rules
In a breaking change, the plugin no longer generates a configuration file for TsLint based on your configured project settings, but instead requires that you specify the location of a tslint.json file to use for analysis via the sonar.ts.tslintconfigpath project-level setting.
There were several reasons for the change as detailed on the initial GitHub issue:
- The options for any given TsLint rule are somewhat fluid and change over time as the language evolves – either we model that with constant plugin changes, or we push the onus onto the developer
- Decouples the TsLint version from the plugin somewhat – so long as rules with the same names remain supported, a TsLint upgrade shouldn’t break anything
- Means your local build process and SonarQube analysis can use literally the same tslint.json configuration
Custom rule support
New to 0.3 is support for specifying a custom rule directory. TsLint supports user-created rules, and several large open-source projects have good examples – in fact, there’s a whole repository of them. You can now specify a path to find your custom rules via the sonar.ts.tslintrulesdir project property.
NCLOC accuracy improvements
A minor defect in NCLOC was fixed, where the inside of block comments longer than 3 lines were considered code.
To test the plugin against some larger and more interesting code-bases, there’s a SonarQube 5.4 demo installation with the plugin installed available for viewing. Sadly so far none of the projects I’ve analysed have any major issues versus their custom rule setup…
There remains minor work to do on the plugin, and I’ll keep it up to date with TsLint changes where possible.