简体   繁体   中英

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. 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:

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

Usage from eslint documentation :

/*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

I disagree with rule X, can you change it?

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. standard-eject can help you migrate from standard to eslint and eslint-config-standard.

Pro tip: Just use standard and move on. There are actual real problems that you could spend your time solving! :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.

You can see the styleguide here: https://standardjs.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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