GoLand 2018.2 Help

TSLint

You can use the TSLint code verification tool from inside GoLand 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.

The detected errors and warnings are marked with respect to the severity levels selected for rules enabled in the TSLint configuration file. By default, errors are highlighted with a red squiggly line, while warnings are marked with a yellow background. Hover over the highlighted code to see the description of the problem.

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

Installing TSLint

  • Open the embedded Terminal (View | Tool Windows | Terminal or Alt+F12) and type npm install tslint typescript --save-dev. Learn more from the TSLint Official website.

Activating and configuring TSLint in GoLand

  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, GoLand first looks for a tslint.json, tslint.yaml, or tslint.yml configuration file. GoLand 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 GoLand look for a tslint.json, tslint.yaml, or tslint.yml file, choose the Automatic search option. If the search fails, the default embedded configuration file will be used.
    • 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 the browseButton 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, tslint.yaml, tslint.yml, or from the above specified custom configuration file and accordingly will override them.

Importing code style from a TSLint configuration file

GoLand 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, GoLand 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:
    GoLand suggests importing the code style from tslint.json

TSLint quick-fixes

GoLand 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 choose 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
Last modified: 27 August 2018