Configure tslint for typescript projects

  • To enable linting, install tslint: npm install -g tslint.
  • Next install the tslint extension in vscode.
  • Finally add tslint.json if you want custom rules ((Note that these override the default rules so better not do it) ) and add this to workspace settings "tslint.autoFixOnSave": true, "tslint.rulesDirectory": "./tslint.json". Here are some other options:
      • tslint.enable – enable/disable tslint.
      • tslint.jsEnable – enable/disable tslint for .js files, default is false.
      • tslint.run – run the linter onSave or onType, default is onType.
      • tslint.rulesDirectory – an additional rules directory, for user-created rules.
      • tslint.configFile – the configuration file that tslint should use instead of the default tslint.json.
      • tslint.ignoreDefinitionFiles – control if TypeScript definition files should be ignored.
      • tslint.exclude – configure glob patterns of file paths to exclude from linting.
      • tslint.validateWithDefaultConfig – validate a file for which there was no custom tslint confguration found. The default is false.
      • tslint.nodePath – use this setting load tslint from a different location than the current workspace or the globally installed npm modules`.
      • tslint.autoFixOnSave – fix auto fixable warnings when a file is saved. This option is ignored when files.autoSave is set to afterDelay.
  • Sample TSlint:
  • Core Rules: https://palantir.github.io/tslint/rules/
  • Formatters: https://palantir.github.io/tslint/formatters/

Sample Code: https://github.com/tkhemani/TSCode

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s