Skip to content

Commit 623c301

Browse files
authored
Changed rules about trailing commas
1 parent 73c865b commit 623c301

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ $ `npm i` - and you're ready to go!
13571357
```
13581358

13591359
<a name="functions--signature-invocation-indentation"></a><a name="7.16"></a>
1360-
- [7.16](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself and without a trailing comma on the last item. eslint: [`function-paren-newline`](https://eslint.org/docs/rules/function-paren-newline)
1360+
- [7.16](#functions--signature-invocation-indentation) Functions with multiline signatures, or invocations, should be indented just like every other multiline list in this guide: with each item on a line by itself and with a trailing comma on the last item. eslint: [`function-paren-newline`](https://eslint.org/docs/rules/function-paren-newline)
13611361

13621362
```javascript
13631363
// bad
@@ -1371,7 +1371,7 @@ $ `npm i` - and you're ready to go!
13711371
function foo(
13721372
bar,
13731373
baz,
1374-
quux
1374+
quux,
13751375
...
13761376
){
13771377
// ...
@@ -1386,7 +1386,7 @@ $ `npm i` - and you're ready to go!
13861386
console.log(
13871387
foo,
13881388
bar,
1389-
baz
1389+
baz,
13901390
...
13911391
);
13921392
```
@@ -3398,7 +3398,7 @@ $ `npm i` - and you're ready to go!
33983398
const x = [
33993399
foo,
34003400
bar,
3401-
baz
3401+
baz,
34023402
];
34033403
34043404
// bad
@@ -3414,60 +3414,60 @@ $ `npm i` - and you're ready to go!
34143414
foo: "foo1",
34153415
bar: "bar1",
34163416
baz: "baz1",
3417-
abc: "abc1"
3417+
abc: "abc1",
34183418
};
34193419
```
34203420

34213421
<a name="commas--dangling"></a><a name="20.2"></a>
3422-
- [20.2](#commas--dangling) Do not write additional trailing commas. eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html)
3422+
- [20.2](#commas--dangling) Write additional trailing commas. eslint: [`comma-dangle`](https://eslint.org/docs/rules/comma-dangle.html)
34233423

3424-
> Why? This may lead to cleaner git diffs but also can cause problems and bugs (especially in older browsers). For example, a comma must not appear after a [rest element](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). It is also more logical to expect _something_ after a comma. [Read more...](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas)
3424+
> Why? It leads to cleaner git diffs and allows easier copy-pasting. **Careful**: A comma must not appear after a [rest element](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). [Read more...](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas)
34253425

34263426
```diff
3427-
// git diff with trailing comma (bad anyway)
3428-
const foo = {
3429-
bar: "bar",
3430-
baz: "baz",
3431-
+ abc: [1, 2, 3],
3432-
};
3433-
3434-
// git diff without trailing comma (still good)
3427+
// git diff without trailing comma (bad)
34353428
const hero = {
34363429
bar: "bar",
34373430
- baz: "baz"
34383431
+ baz: "baz",
34393432
+ abc: [1, 2, 3]
34403433
};
3434+
3435+
// git diff with trailing comma (good)
3436+
const foo = {
3437+
bar: "bar",
3438+
baz: "baz",
3439+
+ abc: [1, 2, 3],
3440+
};
34413441
```
34423442

34433443
```javascript
34443444
// bad
34453445
const foo = {
34463446
bar: true,
3447-
baz: false,
3447+
baz: false
34483448
};
34493449
34503450
const foo = [
34513451
"bar",
3452-
"baz",
3452+
"baz"
34533453
];
34543454
34553455
// good
34563456
const foo = {
34573457
bar: true,
3458-
baz: false
3458+
baz: false,
34593459
};
34603460
34613461
const foo = [
34623462
"bar",
3463-
"baz"
3463+
"baz",
34643464
];
34653465
34663466
// bad
34673467
function foo(
34683468
arg1,
34693469
arg2,
3470-
agr3,
3470+
agr3
34713471
){
34723472
// ..
34733473
}
@@ -3476,7 +3476,7 @@ $ `npm i` - and you're ready to go!
34763476
function foo(
34773477
arg1,
34783478
arg2,
3479-
agr3
3479+
agr3,
34803480
){
34813481
// ..
34823482
}
@@ -3485,14 +3485,14 @@ $ `npm i` - and you're ready to go!
34853485
createUser(
34863486
firstName,
34873487
lastName,
3488-
birthday,
3488+
birthday
34893489
);
34903490
34913491
// good
34923492
createUser(
34933493
firstName,
34943494
lastName,
3495-
birthday
3495+
birthday,
34963496
);
34973497
```
34983498

0 commit comments

Comments
 (0)