CLion 2018.3 Help

TSLint

You can use the TSLint code verification tool from inside CLion and check your TypeScript code for most common mistakes without running the application. When the tool is activated, it lints all the opened TypeScript files and marks the detected problems.

To view the description of a problem, hover over the highlighted code.

TSLint: errors and warnings are highlighted, the description of a problem is shown in a tooltip.

Installing TSLint

  • Open the embedded Terminal (Alt+F12) and type npm install tslint typescript --save-dev.

    Learn more from the TSLint official website.

Activating and configuring TSLint in CLion

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), choose TypeScript under Languages and Frameworks, then choose TSLint. The TSLint page opens.

  2. Select the Enable checkbox. 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, CLion first looks for a tslint.json, tslint.yaml, or tslint.yml configuration file. CLion 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, tslint.yaml, or tslint.yml configuration file is found, TSLint uses its default embedded configuration file. Accordingly, you have to define the configuration to apply either in a tslint.json, tslint.yaml, or tslint.yml configuration file, or in a custom configuration file, or rely on the default embedded configuration.

    • To have CLion look for a tslint.json, tslint.yaml, or tslint.yml file, choose the Automatic search option.

    • To use a custom file, choose the Configuration File option and specify the location of the file in the Path field. Choose the path from the drop-down list, or type it manually, or click Browse 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, tslint.yaml, tslint.yml, or from the above specified custom configuration file and accordingly will override them.

Configuring highlighting for TSLint

By default, CLion marks the detected errors and warnings based on the severity levels from the TSLint configuration file. For example, errors are highlighted with a red squiggly line, while warnings are marked with a yellow background.

To change the severity level of a rule in the TSLint configuration

  • In TSLint configuration file, locate the rule you want to edit and set its ID to warning or to error. Learn more from the TSLint official website.

You can override the severities from the TSLint configuration file so that CLion ignores them and shows everything reported by the linter as errors, warnings, or in a custom color.

To ignore the severity levels from the configuration

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Editor | Inspections. The Inspections page opens.

  2. In the central pane, go to TypeScript | TSLint.

  3. In the right-hand pane, clear the Use rule severity from the configuration file checkbox and select the severity level to use instead of the default one.

    Specifying a custom severity level for TSLint

Importing code style from a TSLint configuration file

CLion understands some of the TSLint rules described in tslint.json, tslint.yaml, or tslint.yml configuration files and lets you apply them to the TypeScript code style configuration in your project.

  • When you open your project for the first time, CLion imports the code style from the project tslint.json, tslint.yaml, or tslint.yml automatically.

  • If tslint.json, tslint.yaml, or tslint.yml is updated (manually or from your version control), open it in the editor and choose Apply TSLint Code Style Rules on the context menu.

    Import TSLint code style rules from the editor: context menu

    Alternatively, just answer Yes to the "Apply code style from TSLint?" question on top of the file:

    CLion suggests importing the code style from tslint.json

TSLint quick-fixes

CLion lets you automatically fix some of the issues reported by TSLint.

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

  • To fix all the issues detected in the file, choose TSLint: fix current file.

    ws_tslint_quick_fixes.png

You can suppress TSLint rules for the current file and even for the current line. CLion automatically generates disable comments in the format /* tslint:disable:<rule name> or // tslint:disable-next-line:<rule name> and places them on top of the file or above the current line respectively.

To suppress a TSLint rule on the fly

  1. Place the cursor at an error or a warning reported by TSLint and press Alt+Enter.

  2. Select the quick-fix for the rule that you want to disable and press Right.

  3. From the list, select Suppress <rule name> for current file or Suppress <rule name> for current line.

    Disabling TSLint rules on the fly by adding disable comments

Last modified: 7 December 2018

See Also