What is the usage of this ?
"comma-dangle": [ 2, "never" ],
What is 2 and never here?
The first item 2
is a generic setting for any ESLint rule. When configuring rules you can set the severity level of the rule. You can use the numeric value or string value, both mean the same thing:
0
("off"
) to turn off the rule, so it does not trigger.1
("warning"
) to produce a warning if the rule is breached.2
("error"
) to produce an error if the rule is breached.For ESLint itself there is no difference between warnings or errors. In both cases your code does not conform to a rule. However, some tools might differentiate. It is common for build tools to fail the build if errors are encountered but still produce a successful build if there were warnings.
It is usually a good idea to leave relatively minor things as warnings only and serious problems as errors. For example, stylistic rules like spaces around =
might just produce a warning, while more serious issues like unreachable code might instead be errors because it is a potential bug.
The "never"
is a specific setting for the comma-dangle rule. Some rules are only a toggle on/off (with "on" being warning/error level) while others have extra settings. The comma-dangle rule can be configured for when and where dangling commas are allowed. The value "never"
means that they should never appear. From the documentation:
Examples of incorrect code for this rule with the default
"never"
option:/*eslint comma-dangle: ["error", "never"]*/ var foo = { bar: "baz", qux: "quux", }; var arr = [1,2,]; foo({ bar: "baz", qux: "quux", });
Examples of correct code for this rule with the default
"never"
option:/*eslint comma-dangle: ["error", "never"]*/ var foo = { bar: "baz", qux: "quux" }; var arr = [1,2]; foo({ bar: "baz", qux: "quux" });