ark
ark

Reputation: 3805

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 ?

Upvotes: 5

Views: 14196

Answers (5)

Markus
Markus

Reputation: 111

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 appears at top of tslint.json file

With the applied code style you can use your accustomed shortcuts (e.g. 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

Upvotes: 1

Gregor Albert
Gregor Albert

Reputation: 841

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

enter image description here

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

Upvotes: 7

Ray Luxembourg
Ray Luxembourg

Reputation: 196

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

Just remember to select the file type correct (its ok to create multiple watchers to handle other file types) enter image description here

Upvotes: 0

Sam
Sam

Reputation: 97

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.

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222712

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.

enter image description here

Upvotes: 4

Related Questions