IntelliJ IDEA 2017.1 Help

Using TSLint Code Quality Tool

This feature is supported in the Ultimate edition only.

On this page:


IntelliJ IDEA provides facilities to run TypeScript-specific code quality inspections through integration with the TSLint code verification tool. This tool registers itself as a IntelliJ IDEA code inspection: it checks TypeScript code for most common mistakes and discrepancies without running the application. When the tool is activated, it launches automatically on the edited TypeScript file. Discrepancies are highlighted and reported in pop-up information windows, a pop-up window appears when you hover the mouse pointer over a stripe in the Validation sidebar. You can also press Alt+Enter to examine errors and apply suggested quick fixes. Learn more about inspections and intention actions at Code Inspection and Intention Actions.

Before you start

  1. The TSLint tool is run through NodeJS, therefore make sure the NodeJS runtime environment is downloaded and installed on your computer. The runtime environment also contains the Node Package Manager(npm) through which tslint is installed.
  2. Integration with NodeJS and NPM is supported through the NodeJS plugin. The plugin is not bundled with IntelliJ IDEA, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

Installing TSLint

Open the IntelliJ IDEA built-in Terminal (View | Tool Windows | Terminal or Alt+F12) and type npm install tslint typescript --save-dev. See TSLint for more information.

Activating and configuring the TSLint tool

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for macOS. Expand the Languages & Frameworks node, and then click TSLint under TypeScript.
  2. On the TSLint page that opens, select the Enable check box. After that all the controls in the page become available.
  3. Specify the location of the Node.js executable file and the path to the TSLint package.
  4. In the Configuration File area, appoint the configuration to use. By default, IntelliJ IDEA first looks for a tslint.json configuration file. IntelliJ IDEA starts the search from the folder where the file to be checked is stored, then searches in the parent folder, and so on until reaches the project root. If no tslint.json file is found, TSLint uses its default embedded configuration file. Accordingly, you have to define the configuration to apply either in a tslint.json configuration file, or in a custom JSON configuration file, or rely on the default embedded configuration.
    • To have IntelliJ IDEA look for a tslint.json file, choose the Search for tslint.json option. If no tslint.json file is found, the default embedded configuration file will be used.
    • To use a custom file, choose the Configuration File option and specify the location fo the file in the Path field. Choose the path from the drop-down list, or type it manually, or click the /help/img/idea/2017.1/browseButton.png button and select the relevant file from the dialog box that opens.
  5. If necessary, in the Additional Rules Directory field, specify the location of the files with additional code verification rules. These rules will be applied after the rules from tslint.json or the above specified custom configuration file and accordingly will override them.

TSLint quick-fixes

With IntelliJ IDEA, you can fix some of the issues reported by TSLint automatically.

  • To fix a specific error, place the cursor at the highlighted code, press Alt+Enter, and then choose TSLint: fix current error from the pop-up menu.
  • To fix all the issues detected in the file, choose TSLint: fix current file.

See Also

Last modified: 18 July 2017