[英]Angular 4, Make ng lint error fatal
Angular CLI has a built in linter, running ng lint
will lint my code base and report any errors. Angular CLI具有内置的linter,运行ng lint
将使我的代码库变薄并报告任何错误。 It can even fix some automatically. 它甚至可以自动修复某些问题。
Is there a way I can make linter errors fatal whilst runnning the site with ng serve
? 在使用ng serve
站点时,有什么方法可以使linter错误致命吗? ie I want to display an error message on the front page of the site if any code isn't properly linted? 即,如果任何代码未正确插入,我想在网站的首页上显示错误消息吗?
This is not possible with today's tools. 今天的工具无法做到这一点。
What you can do is get a tslint
extension in your favourite editor. 您可以做的是在您喜欢的编辑器中获得一个tslint
扩展名。 This will show the errors in the editor. 这将在编辑器中显示错误。 For VS Code, just searching for tslint
will show the extension directly. 对于VS Code,仅搜索tslint
即可直接显示扩展名。
You can also make it part of an NPM script. 您也可以使其成为NPM脚本的一部分。 For example, in your package.json
: 例如,在您的package.json
:
"scripts": { "build": "ng lint && ng build" }
This is still not interactive, but you can a version of it that developers are required to run before pushing code, and your CI build tool runs as well. 它仍然不是交互式的,但是您可以提供一个版本,开发人员必须先运行它才能推送代码,并且CI构建工具也可以运行。
For interactive experience, a code editor extension is as close as this gets. 对于交互式体验,代码编辑器扩展功能已尽其所能。 In VS Code the tslint errors show in the file itself, and in the errors panel as well, which works nicely for the developers I work with. 在VS Code中,tslint错误显示在文件本身以及错误面板中,这对于与我一起工作的开发人员来说效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.