简体   繁体   English

为什么在eslint的标准配置中不鼓励使用分号?

[英]Why is not using semicolon is encouraged in standard configuration of eslint?

My project extends 'standard' rules for javascript in .eslintrc.js file, and according to that Javascript code shouldn't have semicolon at the end of lines. 我的项目在.eslintrc.js文件中扩展了javascript的“标准”规则,并且根据该Javascript代码,不应在行尾添加分号。 I have never seen something like that. 我从未见过这样的事情。 Is it useful to leave it like that? 这样保留它有用吗? Or am I misunderstanding the whole thing? 还是我误会了整个事情?

"semi" rule from standard eslint rules: 标准 eslint规则中的“ semi”规则:

"semi": ["error", "never"]

Usage from eslint documentation : eslint文档中的用法:

/*eslint semi: ["error", "never"]*/

var name = "ESLint"

object.method = function() {
    // ...
}

var name = "ESLint"

;(function() {
    // ...
})()

As said in the standardjs docs , the point is not to tell it's better or not to use semicolons but simply to settle once and for all a rule 正如standardjs文档中所说的那样,重点并不是要告诉我们使用分号是更好还是不要,而是简单地一劳永逸地解决规则

I disagree with rule X, can you change it? 我不同意X规则,可以更改吗?

No. The whole point of standard is to save you time by avoiding bikeshedding about code style. 否。标准的全部目的是通过避免有关代码样式的问题来节省您的时间。 There are lots of debates online about tabs vs. spaces, etc. that will never be resolved. 在线上有很多关于制表符与空格等的争论,这些争论将永远无法解决。 These debates just distract from getting stuff done. 这些辩论只是分散注意力。 At the end of the day you have to 'just pick something', and that's the whole philosophy of standard -- its a bunch of sensible 'just pick something' opinions. 归根结底,您必须“随便选一个东西”,这就是整个标准的哲学-一堆明智的“随便选一个”意见。 Hopefully, users see the value in that over defending their own opinions. 希望用户能从中捍卫自己的观点中看到价值。

If you really want to configure hundreds of ESLint rules individually, you can always use eslint directly with eslint-config-standard to layer your changes on top. 如果确实要单独配置数百个ESLint规则,则始终可以将eslint与eslint-config-standard一起直接使用,以将更改放在最上面。 standard-eject can help you migrate from standard to eslint and eslint-config-standard. standard-eject可以帮助您从standard迁移到eslint和eslint-config-standard。

Pro tip: Just use standard and move on. 专家提示:只需使用标准并继续。 There are actual real problems that you could spend your time solving! 有实际的实际问题,您可以花时间解决! :P :P

Discussing about it is opinionated and will induce an endless debate which is not what we want. 关于它的讨论是有根据的,将引发无休止的辩论,这不是我们想要的。

"Standard" in this context refers to a style guide that dictates no semicolons as a default. 在这种情况下,“标准”是指样式指南,该指南不要求将分号作为默认值。 It shouldn't be taken as meaning "standard" as in a ECMA standard. 不应将其视为ECMA标准中的“标准”。

You can see the styleguide here: https://standardjs.com/ 您可以在这里查看样式指南: https ://standardjs.com/

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

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