简体   繁体   English

角度4,使皮棉错误致命

[英]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错误显示在文件本身以及错误面板中,这对于与我一起工作的开发人员来说效果很好。

ng lint 在 Angular 14 中引发节点错误:UnhandledPromiseRejectionWarning:#<object><div id="text_translate"><p> 我将我的应用程序从 Angular 13 升级到 14,现在当我尝试使用安装了最新 eslint 的<strong>ng lint</strong>命令时,出现此错误:</p><pre> (node:15376) UnhandledPromiseRejectionWarning: #&lt;Object&gt; (Use `node --trace-warnings...` to show where the warning was created) (node:15376) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with.catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:15376) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</pre><p> 我不知道如何解决这个问题,而无需降级回 13。这是我的 devDependencies:</p><pre> "devDependencies": { "@angular-devkit/build-angular": "^14.2.1", "@angular-eslint/builder": "14.0.3", "@angular-eslint/eslint-plugin": "14.0.3", "@angular-eslint/eslint-plugin-template": "14.0.3", "@angular-eslint/schematics": "14.0.3", "@angular-eslint/template-parser": "14.0.3", "@angular/cli": "^14.2.1", "@angular/compiler-cli": "^14.2.0", "@angular/language-service": "^14.2.0", "@ngxs/devtools-plugin": "~3.7.1", "@progress/kendo-licensing": "~1.2.2", "@types/lodash": "~4.14.168", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", "@webcomponents/custom-elements": "^1.4.3", "eslint": "^8.18.0", "eslint-plugin-deprecation": "^1.3.2", "typescript": "^4.6.4" }</pre></div></object> - ng lint throws Node error in Angular 14: UnhandledPromiseRejectionWarning: #<Object>

暂无
暂无

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

相关问题 Angular / Typescript lint错误使“let”为“const” - Angular/Typescript lint error to make “let” as “const” Angular 8 - ng lint:超出最大调用堆栈大小错误 - Angular 8 - ng lint: Error in Maximum call stack size exceeded ng lint 在 Angular 14 中引发节点错误:UnhandledPromiseRejectionWarning:#<object><div id="text_translate"><p> 我将我的应用程序从 Angular 13 升级到 14,现在当我尝试使用安装了最新 eslint 的<strong>ng lint</strong>命令时,出现此错误:</p><pre> (node:15376) UnhandledPromiseRejectionWarning: #&lt;Object&gt; (Use `node --trace-warnings...` to show where the warning was created) (node:15376) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with.catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:15376) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</pre><p> 我不知道如何解决这个问题,而无需降级回 13。这是我的 devDependencies:</p><pre> "devDependencies": { "@angular-devkit/build-angular": "^14.2.1", "@angular-eslint/builder": "14.0.3", "@angular-eslint/eslint-plugin": "14.0.3", "@angular-eslint/eslint-plugin-template": "14.0.3", "@angular-eslint/schematics": "14.0.3", "@angular-eslint/template-parser": "14.0.3", "@angular/cli": "^14.2.1", "@angular/compiler-cli": "^14.2.0", "@angular/language-service": "^14.2.0", "@ngxs/devtools-plugin": "~3.7.1", "@progress/kendo-licensing": "~1.2.2", "@types/lodash": "~4.14.168", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", "@webcomponents/custom-elements": "^1.4.3", "eslint": "^8.18.0", "eslint-plugin-deprecation": "^1.3.2", "typescript": "^4.6.4" }</pre></div></object> - ng lint throws Node error in Angular 14: UnhandledPromiseRejectionWarning: #<Object> Angular 6 ng lint combineLatest 已弃用 - Angular 6 ng lint combineLatest is deprecated Angular中的ng lint --format = stylish和ng lint有什么区别 - What is difference between `ng lint --format=stylish` and `ng lint` in Angular angular 项目中 ng lint 期间未处理的异常 - Unhandled exception during ng lint in angular project 带有 Angular 7 和 `ng lint` 的 TypeScript 中的自定义 TSLint 规则 - Custom TSLint Rule in TypeScript with Angular 7 and `ng lint` 在文件保存时将 Angular 配置为“ng lint” - Configure Angular to 'ng lint' on file save 不确定如何在角度项目中使用 ng lint - Not sure how to use ng lint in angular project 如何在 angular 项目中调试 ng lint broken - How to debug ng lint broken in angular project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM