Skip to content

Commit 07e3cde

Browse files
committed
[eslint config] Update to eslint v2: Merge remote-tracking branch 'origin/harry-eslint-v2'
Closes airbnb#730.
2 parents 4574659 + 0f32b96 commit 07e3cde

File tree

9 files changed

+209
-42
lines changed

9 files changed

+209
-42
lines changed

README.md

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,54 @@ Other Style Guides
346346
const nodes = Array.from(foo);
347347
```
348348
349+
- [4.5](#4.5) <a name='4.5'></a> Use return statements in array method callbacks. It's ok to omit the return if the function body consists of a single statement following [8.2](#8.2). eslint: [`array-callback-return`](http://eslint.org/docs/rules/array-callback-return)
350+
351+
```javascript
352+
// good
353+
[1, 2, 3].map((x) => {
354+
const y = x + 1;
355+
return x * y;
356+
});
357+
358+
// good
359+
[1, 2, 3].map(x => x + 1);
360+
361+
// bad
362+
const flat = {};
363+
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
364+
const flatten = memo.concat(item);
365+
flat[index] = memo.concat(item);
366+
});
367+
368+
// good
369+
const flat = {};
370+
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
371+
const flatten = memo.concat(item);
372+
flat[index] = flatten;
373+
return flatten;
374+
});
375+
376+
// bad
377+
inbox.filter((msg) => {
378+
const { subject, author } = msg;
379+
if (subject === 'Mockingbird') {
380+
return author === 'Harper Lee';
381+
} else {
382+
return false;
383+
}
384+
});
385+
386+
// good
387+
inbox.filter((msg) => {
388+
const { subject, author } = msg;
389+
if (subject === 'Mockingbird') {
390+
return author === 'Harper Lee';
391+
}
392+
393+
return false;
394+
});
395+
```
396+
349397
**[⬆ back to top](#table-of-contents)**
350398
351399
## Destructuring
@@ -447,7 +495,7 @@ Other Style Guides
447495
```
448496
449497
<a name="es6-template-literals"></a>
450-
- [6.4](#6.4) <a name='6.4'></a> When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings)
498+
- [6.4](#6.4) <a name='6.4'></a> When programmatically building up strings, use template strings instead of concatenation. eslint: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html) [`template-curly-spacing`](http://eslint.org/docs/rules/template-curly-spacing) jscs: [`requireTemplateStrings`](http://jscs.info/rule/requireTemplateStrings)
451499
452500
> Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
453501
@@ -462,6 +510,11 @@ Other Style Guides
462510
return ['How are you, ', name, '?'].join();
463511
}
464512

513+
// bad
514+
function sayHi(name) {
515+
return `How are you, ${ name }?`;
516+
}
517+
465518
// good
466519
function sayHi(name) {
467520
return `How are you, ${name}?`;
@@ -535,7 +588,7 @@ Other Style Guides
535588
```
536589
537590
<a name="es6-rest"></a>
538-
- [7.6](#7.6) <a name='7.6'></a> Never use `arguments`, opt to use rest syntax `...` instead.
591+
- [7.6](#7.6) <a name='7.6'></a> Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
539592
540593
> Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.
541594
@@ -771,6 +824,19 @@ Other Style Guides
771824
});
772825
```
773826
827+
- [8.5](#8.5) <a name='8.5'></a> Avoid confusing arrow function syntax (`=>`) with comparison operators (`<=`, `>=`). eslint: [`no-confusing-arrow`](http://eslint.org/docs/rules/no-confusing-arrow)
828+
829+
```js
830+
// bad
831+
const itemHeight = item => item.height > 256 ? item.largeSize : item.smallSize;
832+
833+
// bad
834+
const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize;
835+
836+
// good
837+
const itemHeight = item => { return item.height > 256 ? item.largeSize : item.smallSize; }
838+
```
839+
774840
**[⬆ back to top](#table-of-contents)**
775841
776842
@@ -883,6 +949,34 @@ Other Style Guides
883949
}
884950
```
885951
952+
- [9.5](#9.5) <a name='9.5'></a> Classes have a default constructor if one is not specified. An empty constructor function or one that just delegates to a parent class is unnecessary. [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor)
953+
954+
```javascript
955+
// bad
956+
class Jedi {
957+
constructor() {}
958+
959+
getName() {
960+
return this.name;
961+
}
962+
}
963+
964+
// bad
965+
class Rey extends Jedi {
966+
constructor(...args) {
967+
super(args);
968+
}
969+
}
970+
971+
// good
972+
class Rey extends Jedi {
973+
constructor(...args) {
974+
super(args);
975+
this.name = 'Rey';
976+
}
977+
}
978+
```
979+
886980
**[⬆ back to top](#table-of-contents)**
887981

888982

@@ -1592,8 +1686,8 @@ Other Style Guides
15921686
})(this);↵
15931687
```
15941688

1595-
- [18.6](#18.6) <a name='18.6'></a> Use indentation when making long method chains. Use a leading dot, which
1596-
emphasizes that the line is a method call, not a new statement.
1689+
- [18.6](#18.6) <a name='18.6'></a> Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which
1690+
emphasizes that the line is a method call, not a new statement. eslint: [`newline-per-chained-call`](http://eslint.org/docs/rules/newline-per-chained-call) [`no-whitespace-before-property`](http://eslint.org/docs/rules/no-whitespace-before-property)
15971691

15981692
```javascript
15991693
// bad
@@ -1630,6 +1724,9 @@ Other Style Guides
16301724
.append('svg:g')
16311725
.attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
16321726
.call(tron.led);
1727+
1728+
// good
1729+
const leds = stage.selectAll('.led').data(data);
16331730
```
16341731

16351732
- [18.7](#18.7) <a name='18.7'></a> Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks)

packages/eslint-config-airbnb/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
6.0.0 / 2016-02-21
2+
==================
3+
- [breaking] enable `array-callback-return`
4+
- [breaking] enable `no-confusing-arrow`
5+
- [breaking] enable `no-new-symbol`
6+
- [breaking] enable `no-restricted-imports`
7+
- [breaking] enable `no-useless-constructor`
8+
- [breaking] enable `prefer-rest-params`
9+
- [breaking] enable `template-curly-spaces`
10+
- [breaking] enable `newline-per-chained-call`
11+
- [breaking] enable `one-var-declaration-per-line`
12+
- [breaking] enable `no-self-assign`
13+
- [breaking] enable `no-whitespace-before-property`
14+
- [breaking] [react] enable `react/jsx-space-before-closing`
15+
- [breaking] [react] enable `static-methods` at top of `react/sort-comp`
16+
- [breaking] [react] don't `ignoreTranspilerName` for `react/display-name`
17+
- [peer+dev deps] update `eslint`, `eslint-plugin-react`
18+
119
5.0.1 / 2016-02-13
220
==================
321
- [fix] `eslint` peerDep should not include breaking changes

packages/eslint-config-airbnb/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
"homepage": "https://github.com/airbnb/javascript",
4444
"devDependencies": {
4545
"babel-tape-runner": "1.2.0",
46-
"eslint": "^1.10.3",
47-
"eslint-plugin-react": "^3.16.1",
46+
"eslint": "^2.2.0",
47+
"eslint-plugin-react": "^4.0.0",
4848
"react": "^0.14.7",
4949
"tape": "^4.4.0",
5050
"parallelshell": "^2.0.0"
5151
},
5252
"peerDependencies": {
53-
"eslint": "^1.0.0",
54-
"eslint-plugin-react": "^3.16.1"
53+
"eslint": "^2.2.0",
54+
"eslint-plugin-react": "^4.0.0"
5555
}
5656
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ module.exports = {
22
'rules': {
33
// enforces getter/setter pairs in objects
44
'accessor-pairs': 0,
5+
// enforces return statements in callbacks of array's methods
6+
// http://eslint.org/docs/rules/array-callback-return
7+
'array-callback-return': 2,
58
// treat var statements as if they were block scoped
69
'block-scoped-var': 2,
710
// specify the maximum cyclomatic complexity allowed in a program
@@ -20,6 +23,9 @@ module.exports = {
2023
'eqeqeq': 2,
2124
// make sure for-in loops have an if statement
2225
'guard-for-in': 2,
26+
// Blacklist certain identifiers to prevent them being used
27+
// http://eslint.org/docs/rules/id-blacklist
28+
'id-blacklist': 0,
2329
// disallow the use of alert, confirm, and prompt
2430
'no-alert': 1,
2531
// disallow use of arguments.caller or arguments.callee
@@ -31,8 +37,9 @@ module.exports = {
3137
'no-div-regex': 0,
3238
// disallow else after a return in an if
3339
'no-else-return': 2,
34-
// disallow use of labels for anything other then loops and switches
35-
'no-empty-label': 2,
40+
// disallow Unnecessary Labels
41+
// http://eslint.org/docs/rules/no-extra-label
42+
'no-extra-label': 2,
3643
// disallow comparisons to null without a type-checking operator
3744
'no-eq-null': 0,
3845
// disallow use of eval()
@@ -53,8 +60,8 @@ module.exports = {
5360
'no-invalid-this': 0,
5461
// disallow usage of __iterator__ property
5562
'no-iterator': 2,
56-
// disallow use of labeled statements
57-
'no-labels': 2,
63+
// disallow use of labels for anything other then loops and switches
64+
'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }],
5865
// disallow unnecessary nested blocks
5966
'no-lone-blocks': 2,
6067
// disallow creation of functions within loops
@@ -96,8 +103,14 @@ module.exports = {
96103
'no-sequences': 2,
97104
// restrict what can be thrown as an exception
98105
'no-throw-literal': 2,
106+
// disallow unmodified conditions of loops
107+
// http://eslint.org/docs/rules/no-unmodified-loop-condition
108+
'no-unmodified-loop-condition': 0,
99109
// disallow usage of expressions in statement position
100110
'no-unused-expressions': 2,
111+
// disallow unused labels
112+
// http://eslint.org/docs/rules/no-unused-labels
113+
'no-unused-labels': 2,
101114
// disallow unnecessary .call() and .apply()
102115
'no-useless-call': 0,
103116
// disallow use of void operator
Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
module.exports = {
22
'env': {
3-
'es6': false
3+
'es6': true
44
},
5-
'ecmaFeatures': {
6-
'arrowFunctions': true,
7-
'blockBindings': true,
8-
'classes': true,
9-
'defaultParams': true,
10-
'destructuring': true,
11-
'forOf': true,
12-
'generators': false,
13-
'modules': true,
14-
'objectLiteralComputedProperties': true,
15-
'objectLiteralDuplicateProperties': false,
16-
'objectLiteralShorthandMethods': true,
17-
'objectLiteralShorthandProperties': true,
18-
'restParams': true,
19-
'spread': true,
20-
'superInFunctions': true,
21-
'templateStrings': true,
22-
'jsx': true
5+
'parserOptions': {
6+
'ecmaVersion': 6,
7+
'sourceType': 'module',
8+
'ecmaFeatures': {
9+
'jsx': true,
10+
'generators': false,
11+
'objectLiteralDuplicateProperties': false
12+
}
2313
},
2414
'rules': {
2515
// enforces no braces where they can be omitted
@@ -38,12 +28,24 @@ module.exports = {
3828
'generator-star-spacing': 0,
3929
// disallow modifying variables of class declarations
4030
'no-class-assign': 0,
31+
// disallow arrow functions where they could be confused with comparisons
32+
// http://eslint.org/docs/rules/no-confusing-arrow
33+
'no-confusing-arrow': 2,
4134
// disallow modifying variables that are declared using const
4235
'no-const-assign': 2,
36+
// disallow symbol constructor
37+
// http://eslint.org/docs/rules/no-new-symbol
38+
'no-new-symbol': 2,
39+
// disallow specific imports
40+
// http://eslint.org/docs/rules/no-restricted-imports
41+
'no-restricted-imports': 0,
4342
// disallow to use this/super before super() calling in constructors.
4443
'no-this-before-super': 0,
4544
// require let or const instead of var
4645
'no-var': 2,
46+
// disallow unnecessary constructor
47+
// http://eslint.org/docs/rules/no-useless-constructor
48+
'no-useless-constructor': 2,
4749
// require method and property shorthand syntax for object literals
4850
// https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md
4951
'object-shorthand': [2, 'always'],
@@ -55,10 +57,22 @@ module.exports = {
5557
'prefer-spread': 0,
5658
// suggest using Reflect methods where applicable
5759
'prefer-reflect': 0,
60+
// use rest parameters instead of arguments
61+
// http://eslint.org/docs/rules/prefer-rest-params
62+
'prefer-rest-params': 2,
5863
// suggest using template literals instead of string concatenation
5964
// http://eslint.org/docs/rules/prefer-template
6065
'prefer-template': 2,
6166
// disallow generator functions that do not have yield
62-
'require-yield': 0
67+
'require-yield': 0,
68+
// import sorting
69+
// http://eslint.org/docs/rules/sort-imports
70+
'sort-imports': 0,
71+
// enforce usage of spacing in template strings
72+
// http://eslint.org/docs/rules/template-curly-spacing
73+
'template-curly-spacing': 2,
74+
// enforce spacing around the * in yield* expressions
75+
// http://eslint.org/docs/rules/yield-star-spacing
76+
'yield-star-spacing': [2, 'after']
6377
}
6478
};

packages/eslint-config-airbnb/rules/react.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
'rules': {
1111
// Prevent missing displayName in a React component definition
1212
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
13-
'react/display-name': [0, { 'acceptTranspilerName': false }],
13+
'react/display-name': [0, { 'ignoreTranspilerName': false }],
1414
// Forbid certain propTypes (any, array, object)
1515
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
1616
'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }],
@@ -54,8 +54,8 @@ module.exports = {
5454
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
5555
'react/jsx-pascal-case': 0,
5656
// Enforce propTypes declarations alphabetical sorting
57-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md
58-
'react/jsx-sort-prop-types': [0, {
57+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
58+
'react/sort-prop-types': [0, {
5959
'ignoreCase': false,
6060
'callbacksLast': false,
6161
}],
@@ -116,10 +116,14 @@ module.exports = {
116116
// Prevent extra closing tags for components without children
117117
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
118118
'react/self-closing-comp': 2,
119+
// Enforce spaces before the closing bracket of self-closing JSX elements
120+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
121+
'react/jsx-space-before-closing': [2, 'always'],
119122
// Enforce component methods order
120123
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
121124
'react/sort-comp': [2, {
122125
'order': [
126+
'static-methods',
123127
'lifecycle',
124128
'/^on.+$/',
125129
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',

0 commit comments

Comments
 (0)