]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-comma-dangle.md
de0faf7f042b0780c474d95efe9e870259a0bce2
[pve-eslint.git] / eslint / docs / src / rules / no-comma-dangle.md
1 ---
2 title: no-comma-dangle
3 layout: doc
4
5 ---
6
7 Disallows trailing commas in object and array literals.
8
9 (removed) This rule was **removed** in ESLint v1.0 and **replaced** by the [comma-dangle](comma-dangle) rule.
10
11 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.
12
13 ```js
14 var foo = {
15 bar: "baz",
16 qux: "quux",
17 };
18 ```
19
20 ## Rule Details
21
22 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.
23
24 Examples of **incorrect** code for this rule:
25
26 ::: incorrect
27
28 ```js
29 var foo = {
30 bar: "baz",
31 qux: "quux",
32 };
33
34 var arr = [1,2,];
35
36 foo({
37 bar: "baz",
38 qux: "quux",
39 });
40 ```
41
42 :::
43
44 Examples of **correct** code for this rule:
45
46 ::: correct
47
48 ```js
49 var foo = {
50 bar: "baz",
51 qux: "quux"
52 };
53
54 var arr = [1,2];
55
56 foo({
57 bar: "baz",
58 qux: "quux"
59 });
60 ```
61
62 :::
63
64 ## When Not To Use It
65
66 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.