PyCharm integrates with the TSLint code verification tool so you can check your 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.
- Open the embedded Terminal ( or Alt+F12) and type
npm install tslint typescript --save-dev. Learn more from the TSLint Official website.
Activating and configuring TSLint in PyCharm
- In the Settings/Preferences dialog (Ctrl+Alt+S), choose TypeScript under Languages and Frameworks, then choose TSLint. The TSLint page opens.
- Select the Enable checkbox. 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, PyCharm first looks for a
tslint.jsonconfiguration file. PyCharm 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 PyCharm 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 of 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 PyCharm 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.
Importing code style from tslint.json
PyCharm understands some of the TSLint rules described in tslint.json and lets you apply them to the TypeScript code style configuration in your project.
- When you open your project for the first time, PyCharm imports the code style from the project tslint.json automatically.
- If tslint.json is updated (manually or from your version control), open it in the editor and choose Apply TSLint Code Style Rules on the context menu: Alternatively, just answer Yes to the "Apply code style from TSLint"? question on top of the file::
PyCharm 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.