Skip to content

Commit f5f02ff

Browse files
Proposed changes to the JS Style Guide
1 parent 2a7e19a commit f5f02ff

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

README.md

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ Other Style Guides
17271727
const story = [
17281728
once,
17291729
upon,
1730-
aTime,
1730+
aTime
17311731
];
17321732
17331733
// bad
@@ -1743,50 +1743,33 @@ Other Style Guides
17431743
firstName: 'Ada',
17441744
lastName: 'Lovelace',
17451745
birthYear: 1815,
1746-
superPower: 'computers',
1746+
superPower: 'computers'
17471747
};
17481748
```
17491749

1750-
- [19.2](#19.2) <a name='19.2'></a> Additional trailing comma: **Yup.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma)
1750+
- [19.2](#19.2) <a name='19.2'></a> Additional trailing comma: **Nope.** eslint: [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle.html) jscs: [`requireTrailingComma`](http://jscs.info/rule/requireTrailingComma)
17511751

1752-
> Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.
1752+
> Although this leads to cleaner git diffs, it looks strange to see a trailing comma on the last element. So we favor code readability over cleaner diffs, because we need to deal with code a lot more than we need to deal with diffs.
17531753

17541754
```javascript
1755-
// bad - git diff without trailing comma
1756-
const hero = {
1757-
firstName: 'Florence',
1758-
- lastName: 'Nightingale'
1759-
+ lastName: 'Nightingale',
1760-
+ inventorOf: ['coxcomb graph', 'modern nursing']
1761-
};
1762-
1763-
// good - git diff with trailing comma
1764-
const hero = {
1765-
firstName: 'Florence',
1766-
lastName: 'Nightingale',
1767-
+ inventorOf: ['coxcomb chart', 'modern nursing'],
1768-
};
1769-
17701755
// bad
1771-
const hero = {
1772-
firstName: 'Dana',
1773-
lastName: 'Scully'
1756+
const hero = {
1757+
firstName: 'Dana',
1758+
lastName: 'Scully',
17741759
};
1775-
17761760
const heroes = [
1777-
'Batman',
1778-
'Superman'
1761+
'Batman',
1762+
'Superman',
17791763
];
17801764
17811765
// good
1782-
const hero = {
1783-
firstName: 'Dana',
1784-
lastName: 'Scully',
1766+
const hero = {
1767+
firstName: 'Dana',
1768+
lastName: 'Scully'
17851769
};
1786-
17871770
const heroes = [
1788-
'Batman',
1789-
'Superman',
1771+
'Batman',
1772+
'Superman'
17901773
];
17911774
```
17921775

0 commit comments

Comments
 (0)