Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed changes to the JS Style Guide #697

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ Other Style Guides
const story = [
once,
upon,
aTime,
aTime
];

// bad
Expand All @@ -1743,50 +1743,33 @@ Other Style Guides
firstName: 'Ada',
lastName: 'Lovelace',
birthYear: 1815,
superPower: 'computers',
superPower: 'computers'
};
```

- [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)
- [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)

> 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.
> 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.

```javascript
// bad - git diff without trailing comma
const hero = {
firstName: 'Florence',
- lastName: 'Nightingale'
+ lastName: 'Nightingale',
+ inventorOf: ['coxcomb graph', 'modern nursing']
};

// good - git diff with trailing comma
const hero = {
firstName: 'Florence',
lastName: 'Nightingale',
+ inventorOf: ['coxcomb chart', 'modern nursing'],
};

// bad
const hero = {
firstName: 'Dana',
lastName: 'Scully'
lastName: 'Scully',
};

const heroes = [
'Batman',
'Superman'
'Superman',
];

// good
const hero = {
firstName: 'Dana',
lastName: 'Scully',
lastName: 'Scully'
};

const heroes = [
'Batman',
'Superman',
'Superman'
];
```

Expand Down