mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 07:04:54 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
53 lines
1.1 KiB
Markdown
53 lines
1.1 KiB
Markdown
# no-comma-dangle: disallow trailing commas in object and array literals
|
|
|
|
(removed) This rule was **removed** in ESLint v1.0 and **replaced** by the [comma-dangle](comma-dangle.md) rule.
|
|
|
|
Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec, however IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript.
|
|
|
|
```js
|
|
var foo = {
|
|
bar: "baz",
|
|
qux: "quux",
|
|
};
|
|
```
|
|
|
|
## Rule Details
|
|
|
|
This rule is aimed at detecting trailing commas in object literals. As such, it will warn whenever it encounters a trailing comma in an object literal.
|
|
|
|
Examples of **incorrect** code for this rule:
|
|
|
|
```js
|
|
var foo = {
|
|
bar: "baz",
|
|
qux: "quux",
|
|
};
|
|
|
|
var arr = [1,2,];
|
|
|
|
foo({
|
|
bar: "baz",
|
|
qux: "quux",
|
|
});
|
|
```
|
|
|
|
Examples of **correct** code for this rule:
|
|
|
|
```js
|
|
var foo = {
|
|
bar: "baz",
|
|
qux: "quux"
|
|
};
|
|
|
|
var arr = [1,2];
|
|
|
|
foo({
|
|
bar: "baz",
|
|
qux: "quux"
|
|
});
|
|
```
|
|
|
|
## When Not To Use It
|
|
|
|
If your code will not be run in IE8 or below (a Node.js application, for example) and you'd prefer to allow trailing commas, turn this rule off.
|