简体   繁体   English

eslint semi rule:为什么规则配置中有“2”?

[英]eslint semi rule: why is there a "2" in the rule config?

ESLint says to use this config to enforce semicolons. ESLint 说使用这个配置来强制使用分号。

semi: [2, "always"]

What is the meaning of the 2? 2的含义是什么?

As the docs say , for each rule, you can have:正如文档所说,对于每条规则,您可以拥有:

  • "off" or 0 - turn the rule off "off" 或 0 - 关闭规则
  • "warn" or 1 - turn the rule on as a warning (doesn't affect exit code) "warn" 或 1 - 将规则作为警告打开(不影响退出代码)
  • "error" or 2 - turn the rule on as an error (exit code is 1 when triggered) “错误”或 2 - 将规则作为错误打开(触发时退出代码为 1)

So the 2 tells ESLint to treat violations of the rule as an error.所以 2 告诉 ESLint 将违反规则视为错误。

You could, equivalently, do你可以,等效地,做

semi: ['error', "always"]

which might make more sense at a glance.乍一看可能更有意义。

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

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