[eslint config] [*] [new] set ecmaVersion to 2017; enable object rest/spread; update babel-preset-airbnb

This commit is contained in:
Jordan Harband
2016-09-21 17:17:27 -07:00
parent e5f4eb57b4
commit e8b51b2785
8 changed files with 37 additions and 9 deletions

View File

@@ -293,6 +293,26 @@ Other Style Guides
console.log(has.call(object, key));
```
<a name="objects--rest-spread"></a>
- [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.
```javascript
// very bad
const original = { a: 1, b: 2 };
const copy = Object.assign(original, { c: 3 }); // this mutates `original` ಠ_ಠ
delete copy.a; // so does this
// bad
const original = { a: 1, b: 2 };
const copy = Object.assign({}, original, { c: 3 }); // copy => { a: 1, b: 2, c: 3 }
// good
const original = { a: 1, b: 2 };
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
const { a, ...noA } = copy; // noA => { b: 2, c: 3 }
```
**[⬆ back to top](#table-of-contents)**
## Arrays

View File

@@ -4,5 +4,5 @@
// disable requiring trailing commas because it might be nice to revert to
// being JSON at some point, and I don't want to make big changes now.
"comma-dangle": 0
}
},
}

View File

@@ -9,10 +9,13 @@ module.exports = {
'./rules/imports',
].map(require.resolve),
parserOptions: {
ecmaVersion: 2016,
ecmaVersion: 2017,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
rules: {
strict: 'error',
}
},
};

View File

@@ -45,7 +45,7 @@
},
"homepage": "https://github.com/airbnb/javascript",
"devDependencies": {
"babel-preset-airbnb": "^2.0.0",
"babel-preset-airbnb": "^2.1.0",
"babel-tape-runner": "^2.0.1",
"eslint": "^3.6.0",
"eslint-find-rules": "^1.13.2",

View File

@@ -187,6 +187,10 @@ module.exports = {
}, {
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
}, {
object: 'Object',
property: 'assign',
message: 'Please use the object spread operator (...) instead.',
}],
// disallow use of assignment in return statement

View File

@@ -1,7 +1,6 @@
{
"rules": {
// disabled because I find it tedious to write tests while following this
// rule
// disabled because I find it tedious to write tests while following this rule
"no-shadow": 0,
// tests uses `t` for tape
"id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}],

View File

@@ -4,13 +4,15 @@ import test from 'tape';
import index from '../';
const files = { index };
const files = { ...{ index } }; // object spread is to test parsing
fs.readdirSync(path.join(__dirname, '../rules')).forEach((name) => {
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
});
Object.keys(files).forEach((name) => {
Object.keys(files).forEach((
name, // trailing function comma is to test parsing
) => {
const config = files[name];
test(`${name}: does not reference react`, (t) => {

View File

@@ -48,7 +48,7 @@
"eslint-config-airbnb-base": "^7.1.0"
},
"devDependencies": {
"babel-preset-airbnb": "^2.0.0",
"babel-preset-airbnb": "^2.1.0",
"babel-tape-runner": "^2.0.1",
"eslint": "^3.6.0",
"eslint-find-rules": "^1.13.2",