Skip to content

[eslint config] [breaking] enable quote-props rule. #632

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

Merged
merged 1 commit into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,28 @@ Other Style Guides
};
```

- [3.8](#3.8) <a name="3.8"></a> Only quote properties that are invalid identifiers.

> Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.

eslint rules: [`quote-props`](http://eslint.org/docs/rules/quote-props.html).

```javascript
// bad
const bad = {
'foo': 3,
'bar': 4,
'data-blah': 5,
};

// good
const good = {
foo: 3,
bar: 4,
'data-blah': 5,
};
```

**[⬆ back to top](#table-of-contents)**

## Arrays
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-airbnb/rules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ module.exports = {
// enforce padding within blocks
'padded-blocks': [2, 'never'],
// require quotes around object literal property names
'quote-props': 0,
// http://eslint.org/docs/rules/quote-props.html
'quote-props': [2, 'as-needed', { 'keywords': true, 'unnecessary': true, 'numbers': false }],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about 'new' keyword ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we recommend using babel, which takes care of quoting reserved property names in legacy engines, this is not a concern.

// specify whether double or single quotes should be used
'quotes': [2, 'single', 'avoid-escape'],
// require identifiers to match the provided regular expression
Expand Down