简体   繁体   中英

how to do auto Tslint in Intellij

I am using Intellij for doing angular project. I am getting a lot of tslint errors while writing the code.Is there any way to fix all the these lint errors in by using a command in intellij ?

You can create File Watcher in Settings > Tools by the following configuration:

在此处输入图片说明

On save ( Ctrl + s ), your current file will be fixed.

One of the quick way to fix all the tslint errors would be to install visual studio code.

It will have the auto-fix option to fix option to fix all the issues

Event intellij has the option to do the same

Alt-Enter on the highlighted problem and select either TSLint: fix current problem to fix only this particular issue or TSLint: fix current file to apply the fixes when possible to the whole file.

在此处输入图片说明

The previous answers probably only refer to Webstorm, as Filewatchers are not available in the current IntelliJ Ultimate edition (2020.2).

However, whenever you have your own tslint.json , for example when generating an Angular Project from cli, you can tell IntelliJ to use the specified code styles. To do this, open the tslint.json file (root of angular project) and you should see a prompting-bar at the top of your screen. Accept the prompt "Apply code style from TSLint?"

bar 出现在 tslint.json 文件的顶部

With the applied code style you can use your accustomed shortcuts (eg Ctrl+Alt+L) whenever you want to reformat a file / directory.

I found this solution (including the picture) on the Jetbrains forums https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000047844-Angular-and-Tslint-for-code-reformat

If you want to run tslint against all files you would need to add it as an external tool.

A good write up from 2016 explains the process: https://blog.jetbrains.com/webstorm/2016/08/using-external-tools/

Or you can always run it from the command line as Sajeetharan mentioned.

Preferences => File Watchers => + ( create new )

Just remember to select the file type correct (its ok to create multiple watchers to handle other file types) 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM