简体   繁体   English

在 Angular 个项目的提交期间运行 ESLint

[英]Run ESLint during commit on Angular projects

I configured Eslint on an Angular project to check the code during commits.我在 Angular 项目上配置了Eslint ,以在提交期间检查代码。 I made an error on purpouse to test if my configuration works: I set the rule "no-console":"error" and I left a console.log() inside the code.我故意犯了一个错误来测试我的配置是否有效:我设置了规则"no-console":"error"并且我在代码中留下了一个console.log()

When committing ESLint gives me this error:当提交 ESLint 时给我这个错误:

...
✖ eslint --fix:

C:\project\src\app\app.component.ts
  12:5  error  Unexpected console statement  no-console

✖ 1 problem (1 error, 0 warnings)

husky - pre-commit hook exited with code 1 (error)

My doubt is about the fact that I see 2 lines signed with ✖.我怀疑我看到 2 行用 ✖ 签名的事实。

They refer to the same error (console.log) or one of them refers to an ESLint configuration problem?它们指的是相同的错误 (console.log) 还是其中之一指的是 ESLint 配置问题?

Thank for you help,谢谢你的帮助,

In Your example ESLint is saying that there is exactly one problem in file C:\project\src\app\app.component.ts - 12:5 error Unexpected console statement no-console在您的示例中,ESLint 表示文件C:\project\src\app\app.component.ts - 12:5 error Unexpected console statement no-console中确实存在一个问题

About the ✖ eslint --fix: - ESLint is just suggesting to run the command to automatically fix the files.关于✖ eslint --fix: - ESLint 只是建议运行命令来自动修复文件。

However, fix command only takes care of formatting, oyu would have to manually remove the console.log() call.但是, fix命令只负责格式化,oyu 必须手动删除console.log()调用。

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

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