Skip to content

Commit e8b51b2

Browse files
committed
[eslint config] [*] [new] set ecmaVersion to 2017; enable object rest/spread; update babel-preset-airbnb
1 parent e5f4eb5 commit e8b51b2

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,26 @@ Other Style Guides
293293
console.log(has.call(object, key));
294294
```
295295

296+
<a name="objects--rest-spread"></a>
297+
- [3.10](#objects--rest-spread) Prefer the object spread operator over `Object.assign` to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.
298+
299+
```javascript
300+
// very bad
301+
const original = { a: 1, b: 2 };
302+
const copy = Object.assign(original, { c: 3 }); // this mutates `original` ಠ_ಠ
303+
delete copy.a; // so does this
304+
305+
// bad
306+
const original = { a: 1, b: 2 };
307+
const copy = Object.assign({}, original, { c: 3 }); // copy => { a: 1, b: 2, c: 3 }
308+
309+
// good
310+
const original = { a: 1, b: 2 };
311+
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
312+
313+
const { a, ...noA } = copy; // noA => { b: 2, c: 3 }
314+
```
315+
296316
**[⬆ back to top](#table-of-contents)**
297317

298318
## Arrays

packages/eslint-config-airbnb-base/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// disable requiring trailing commas because it might be nice to revert to
55
// being JSON at some point, and I don't want to make big changes now.
66
"comma-dangle": 0
7-
}
7+
},
88
}

packages/eslint-config-airbnb-base/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ module.exports = {
99
'./rules/imports',
1010
].map(require.resolve),
1111
parserOptions: {
12-
ecmaVersion: 2016,
12+
ecmaVersion: 2017,
1313
sourceType: 'module',
14+
ecmaFeatures: {
15+
experimentalObjectRestSpread: true,
16+
},
1417
},
1518
rules: {
1619
strict: 'error',
17-
}
20+
},
1821
};

packages/eslint-config-airbnb-base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"homepage": "https://github.com/airbnb/javascript",
4747
"devDependencies": {
48-
"babel-preset-airbnb": "^2.0.0",
48+
"babel-preset-airbnb": "^2.1.0",
4949
"babel-tape-runner": "^2.0.1",
5050
"eslint": "^3.6.0",
5151
"eslint-find-rules": "^1.13.2",

packages/eslint-config-airbnb-base/rules/best-practices.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ module.exports = {
187187
}, {
188188
property: '__defineSetter__',
189189
message: 'Please use Object.defineProperty instead.',
190+
}, {
191+
object: 'Object',
192+
property: 'assign',
193+
message: 'Please use the object spread operator (...) instead.',
190194
}],
191195

192196
// disallow use of assignment in return statement

packages/eslint-config-airbnb-base/test/.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"rules": {
3-
// disabled because I find it tedious to write tests while following this
4-
// rule
3+
// disabled because I find it tedious to write tests while following this rule
54
"no-shadow": 0,
65
// tests uses `t` for tape
76
"id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}],

packages/eslint-config-airbnb-base/test/test-base.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import test from 'tape';
44

55
import index from '../';
66

7-
const files = { index };
7+
const files = { ...{ index } }; // object spread is to test parsing
88

99
fs.readdirSync(path.join(__dirname, '../rules')).forEach((name) => {
1010
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
1111
});
1212

13-
Object.keys(files).forEach((name) => {
13+
Object.keys(files).forEach((
14+
name, // trailing function comma is to test parsing
15+
) => {
1416
const config = files[name];
1517

1618
test(`${name}: does not reference react`, (t) => {

packages/eslint-config-airbnb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"eslint-config-airbnb-base": "^7.1.0"
4949
},
5050
"devDependencies": {
51-
"babel-preset-airbnb": "^2.0.0",
51+
"babel-preset-airbnb": "^2.1.0",
5252
"babel-tape-runner": "^2.0.1",
5353
"eslint": "^3.6.0",
5454
"eslint-find-rules": "^1.13.2",

0 commit comments

Comments
 (0)