简体   繁体   English

如何在 Intellij 中执行自动 Tslint

[英]how to do auto Tslint in Intellij

I am using Intellij for doing angular project.我正在使用 Intellij 进行角度项目。 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 ?我在编写代码时遇到了很多 tslint 错误。有没有办法通过在 intellij 中使用命令来修复所有这些 lint 错误?

You can create File Watcher in Settings > Tools by the following configuration:您可以通过以下配置在Settings > Tools 中创建 File Watcher:

在此处输入图片说明

On save ( Ctrl + s ), your current file will be fixed.在保存( Ctrl + s )时,您当前的文件将被修复。

One of the quick way to fix all the tslint errors would be to install visual studio code.修复所有 tslint 错误的一种快速方法是安装 Visual Studio 代码。

It will have the auto-fix option to fix option to fix all the issues它将具有自动修复选项来修复选项以修复所有问题

Event intellij has the option to do the same事件intellij可以选择做同样的事情

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. Alt-Enter在突出显示的问题上并选择 TSLint:修复当前问题以仅修复此特定问题或 TSLint:修复当前文件以在可能的情况下将修复应用到整个文件。

在此处输入图片说明

The previous answers probably only refer to Webstorm, as Filewatchers are not available in the current IntelliJ Ultimate edition (2020.2).之前的答案可能只涉及 Webstorm,因为 Filewatchers 在当前的 IntelliJ Ultimate 版本 (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.但是,只要您拥有自己的tslint.json ,例如从 cli 生成 Angular 项目时,您就可以告诉 IntelliJ 使用指定的代码样式。 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.为此,请打开 tslint.json 文件(angular 项目的根目录),您应该会在屏幕顶部看到一个提示栏。 Accept the prompt "Apply code style from TSLint?"接受提示“从 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.使用应用的代码样式,您可以在想要重新格式化文件/目录时使用惯用的快捷方式(例如 Ctrl+Alt+L)。

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我在 Jetbrains 论坛上找到了这个解决方案(包括图片) 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.如果要对所有文件运行 tslint,则需要将其添加为外部工具。

A good write up from 2016 explains the process: https://blog.jetbrains.com/webstorm/2016/08/using-external-tools/ 2016 年的一篇好文章解释了这个过程: https : //blog.jetbrains.com/webstorm/2016/08/using-external-tools/

Or you can always run it from the command line as Sajeetharan mentioned.或者你总是可以像 Sajeetharan 提到的那样从命令行运行它。

Preferences => File Watchers => + ( create new )首选项 => 文件观察者 => +(新建)

Just remember to select the file type correct (its ok to create multiple watchers to handle other file types)请记住选择正确的文件类型(可以创建多个观察者来处理其他文件类型) 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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