Using TSLint Code Quality Tool
PhpStorm provides facilities to run TypeScript-specific code quality inspections through integration with the TSLint code verification tool. This tool registers itself as a PhpStorm 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.
On this page:
Before You Start
- 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.
- Integration with NodeJS and NPM is supported through the NodeJS plugin. The plugin is not bundled with PhpStorm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- Open the Settings / Preferences Dialog by choosing for Windows and Linux or for OS X, and click Node.js and NPM under Languages & Frameworks.
- On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click .
In the Available Packages dialog box that opens, select the
tslintpackage and click Install Package.
Learn more about installing tools through NPM in Installing and Removing External Software Using Node Package Manager.
Activating and Configuring the TSLint Tool
- Open the Settings / Preferences Dialog by choosing for Windows and Linux or for OS X.
- On the TSLint page that opens, select the Enable check box. After that all the controls in the page become available.
- Specify the location of the Node.js executable file and the path to the tslint package.
In the Configuration File area, appoint the configuration to use.
By default, PhpStorm first looks for a
tslint.jsonconfiguration file. PhpStorm 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.jsonfile is found, TSLint uses its default embedded configuration file. Accordingly, you have to define the configuration to apply either in a
tslint.jsonconfiguration file, or in a custom JSON configuration file, or rely on the default embedded configuration.
To have PhpStorm look for a
tslint.jsonfile, choose the Search for tslint.json option. If no
tslint.jsonfile 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 button and select the relevant file from the dialog box that opens.
- To have PhpStorm look for a
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.jsonor the above specified custom configuration file and accordingly will override them.