mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 13:28:05 -05:00
Compare commits
214 Commits
eslint-con
...
es5-deprec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4d8543f12 | ||
|
|
a6da4bb5b2 | ||
|
|
6857f7af97 | ||
|
|
cb36ed90c3 | ||
|
|
75c961a43f | ||
|
|
a533e2dd35 | ||
|
|
4425d3c76b | ||
|
|
49dfcc42de | ||
|
|
b2ea03ef2c | ||
|
|
4dbb2af7da | ||
|
|
1917968acb | ||
|
|
0165c13845 | ||
|
|
4c8f78921f | ||
|
|
eea5f0f5f5 | ||
|
|
1fb300c6c7 | ||
|
|
616233c8b2 | ||
|
|
bbfb9600dc | ||
|
|
da3eb59b39 | ||
|
|
892128366a | ||
|
|
9d598c3563 | ||
|
|
4921e03a7b | ||
|
|
df8627d72f | ||
|
|
3594ee94ac | ||
|
|
623dc44bb9 | ||
|
|
ca9c322790 | ||
|
|
762177eb3b | ||
|
|
2504e0f85c | ||
|
|
385fc9effe | ||
|
|
723e12a87d | ||
|
|
97da7b65c6 | ||
|
|
abcc0c681e | ||
|
|
325f8ba72f | ||
|
|
6039804cc3 | ||
|
|
af594687be | ||
|
|
5f02a6f98f | ||
|
|
b352ec6a4a | ||
|
|
a9bfee01cd | ||
|
|
3ad2404974 | ||
|
|
7fb8b03714 | ||
|
|
7816731d4d | ||
|
|
6db1af173c | ||
|
|
339861022e | ||
|
|
b3a02ae982 | ||
|
|
d282e059b1 | ||
|
|
82629f126d | ||
|
|
b45fdcd60f | ||
|
|
1f87054e4b | ||
|
|
9028379f87 | ||
|
|
c9bcc7ef36 | ||
|
|
17b773e613 | ||
|
|
36d1561596 | ||
|
|
34a9f076df | ||
|
|
28a04a3a45 | ||
|
|
a597da56ca | ||
|
|
d0973e8e36 | ||
|
|
622a3bc1ab | ||
|
|
51f9b0450c | ||
|
|
ee2cb41ec4 | ||
|
|
6980cce17f | ||
|
|
5651e607f3 | ||
|
|
001efc722c | ||
|
|
04138345ad | ||
|
|
343dc2c34a | ||
|
|
0afde8f136 | ||
|
|
0814be638f | ||
|
|
22f59b6e1b | ||
|
|
defa17e872 | ||
|
|
90f5a47c33 | ||
|
|
b4c49e9ec7 | ||
|
|
29eb575a52 | ||
|
|
f41b4df024 | ||
|
|
4700d99864 | ||
|
|
d9cb343b51 | ||
|
|
ab4baf457e | ||
|
|
89cfa0b81c | ||
|
|
eb76edea32 | ||
|
|
3fb9db5a74 | ||
|
|
267eec57c6 | ||
|
|
d97d62a2ff | ||
|
|
1db5522888 | ||
|
|
c247fd754b | ||
|
|
4c4210f23d | ||
|
|
199a0a700d | ||
|
|
a8839173cc | ||
|
|
b6e4b72fc2 | ||
|
|
429339ee37 | ||
|
|
8e125fa07c | ||
|
|
312cd01a95 | ||
|
|
43ccc3fe11 | ||
|
|
e32079d6c4 | ||
|
|
34ccf905d6 | ||
|
|
3948eb66d6 | ||
|
|
10f4dd88aa | ||
|
|
7a8083795d | ||
|
|
8d6d227848 | ||
|
|
638b312b6c | ||
|
|
4ac8aed126 | ||
|
|
c7faa91328 | ||
|
|
788fb2297a | ||
|
|
d68a067f2b | ||
|
|
5acae06653 | ||
|
|
db732788e7 | ||
|
|
d25a199c56 | ||
|
|
b660d4cc3f | ||
|
|
03c5a1f955 | ||
|
|
d95dc3d500 | ||
|
|
be5c90a417 | ||
|
|
56a524a47e | ||
|
|
ba5d9f0cd7 | ||
|
|
330169d15e | ||
|
|
8b396ab9ef | ||
|
|
1b31efc07e | ||
|
|
92a3d5570b | ||
|
|
36e088759f | ||
|
|
b20cf1966c | ||
|
|
83c431d655 | ||
|
|
e9aec9e94f | ||
|
|
fd5c71c0a9 | ||
|
|
6eec3a6df7 | ||
|
|
f9089d075a | ||
|
|
4540293d44 | ||
|
|
6c25bcf9c1 | ||
|
|
d1f2416ffa | ||
|
|
f806ed6bb3 | ||
|
|
dc4130cdbc | ||
|
|
31e8412231 | ||
|
|
d85abc587a | ||
|
|
56fd094e01 | ||
|
|
c81727accd | ||
|
|
33ff1adb2d | ||
|
|
3519daf60d | ||
|
|
d45349497a | ||
|
|
1e1772b340 | ||
|
|
7431ef13a0 | ||
|
|
a71bffa5e3 | ||
|
|
79af88d9d6 | ||
|
|
8f0f2890f2 | ||
|
|
d1383a7cf8 | ||
|
|
117196b3d0 | ||
|
|
44ae49ebcf | ||
|
|
2d81a2db4a | ||
|
|
49c5f3d862 | ||
|
|
f0b6eea9d6 | ||
|
|
277b08710f | ||
|
|
d0ddba17c3 | ||
|
|
f1ab4805b6 | ||
|
|
0207503bef | ||
|
|
3c915dd686 | ||
|
|
897732f6f0 | ||
|
|
37e1c3c6c9 | ||
|
|
d06147d279 | ||
|
|
2dfd520930 | ||
|
|
13cddaf51e | ||
|
|
02414502b6 | ||
|
|
763416260a | ||
|
|
52d3401f95 | ||
|
|
bdbecf23e2 | ||
|
|
8c63dd93a7 | ||
|
|
bf8677d1ac | ||
|
|
e856d93ada | ||
|
|
a9db06e1dd | ||
|
|
12d08b38dc | ||
|
|
e1cbcbecf6 | ||
|
|
6efcda314d | ||
|
|
140ce8b56c | ||
|
|
3efe10d42e | ||
|
|
c97bd772b4 | ||
|
|
48ab6d6e76 | ||
|
|
066c3b1a3c | ||
|
|
970848f1a2 | ||
|
|
c86cfaa6f9 | ||
|
|
f468a52d82 | ||
|
|
f268237c71 | ||
|
|
4ab741190c | ||
|
|
c29560441e | ||
|
|
cbd2c38da8 | ||
|
|
81d01645c2 | ||
|
|
fc1443b80f | ||
|
|
688ef3c2eb | ||
|
|
56e6815a84 | ||
|
|
eb4f7cb3a8 | ||
|
|
531950cc26 | ||
|
|
92a66ccc7c | ||
|
|
4af3f9755e | ||
|
|
0fe4f558a6 | ||
|
|
662519efc0 | ||
|
|
956f91527b | ||
|
|
9060fba34a | ||
|
|
bcc5c5d8dd | ||
|
|
93b0a10eb7 | ||
|
|
66ec951087 | ||
|
|
a929776d67 | ||
|
|
f5d6e9646c | ||
|
|
7c0bb0a6de | ||
|
|
7b5731157f | ||
|
|
6fd8fb60b3 | ||
|
|
c5366984b3 | ||
|
|
3f73e35b18 | ||
|
|
f697a15e50 | ||
|
|
0c3b13fe93 | ||
|
|
f2aca29ed9 | ||
|
|
acbddc1083 | ||
|
|
6e770062bb | ||
|
|
a2bdbb83d1 | ||
|
|
f21412cba9 | ||
|
|
6671a55556 | ||
|
|
76e1e4c1de | ||
|
|
5b9f081d1d | ||
|
|
062929ee5f | ||
|
|
5ec8765a28 | ||
|
|
9415b88afd | ||
|
|
81241b83cf | ||
|
|
24565121c1 | ||
|
|
5ce6fb1eae |
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
- "5"
|
||||
- "4"
|
||||
env:
|
||||
- 'TEST_DIR=packages/eslint-config-airbnb'
|
||||
- 'TEST_DIR=packages/eslint-config-airbnb-base'
|
||||
before_install:
|
||||
- 'cd $TEST_DIR'
|
||||
- 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi'
|
||||
- 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi'
|
||||
script:
|
||||
- 'npm run travis'
|
||||
sudo: false
|
||||
matrix:
|
||||
fast_finish: true
|
||||
298
README.md
298
README.md
@@ -3,6 +3,7 @@
|
||||
*A mostly reasonable approach to JavaScript*
|
||||
|
||||
[](https://www.npmjs.com/package/eslint-config-airbnb)
|
||||
[](https://www.npmjs.com/package/eslint-config-airbnb-base)
|
||||
[](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
Other Style Guides
|
||||
@@ -21,7 +22,7 @@ Other Style Guides
|
||||
1. [Strings](#strings)
|
||||
1. [Functions](#functions)
|
||||
1. [Arrow Functions](#arrow-functions)
|
||||
1. [Constructors](#constructors)
|
||||
1. [Classes & Constructors](#classes--constructors)
|
||||
1. [Modules](#modules)
|
||||
1. [Iterators and Generators](#iterators-and-generators)
|
||||
1. [Properties](#properties)
|
||||
@@ -287,8 +288,8 @@ Other Style Guides
|
||||
};
|
||||
```
|
||||
|
||||
<a name="objects-quoted-props"></a><a name="3.8"></a>
|
||||
- [3.8](#objects-quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
|
||||
<a name="objects--quoted-props"></a><a name="3.8"></a>
|
||||
- [3.8](#objects--quoted-props) Only quote properties that are invalid identifiers. eslint: [`quote-props`](http://eslint.org/docs/rules/quote-props.html) jscs: [`disallowQuotedKeysInObjects`](http://jscs.info/rule/disallowQuotedKeysInObjects)
|
||||
|
||||
> Why? In general we consider it subjectively easier to read. It improves syntax highlighting, and is also more easily optimized by many JS engines.
|
||||
|
||||
@@ -308,6 +309,26 @@ Other Style Guides
|
||||
};
|
||||
```
|
||||
|
||||
<a name="objects--prototype-builtins"></a>
|
||||
- [3.9](#objects--prototype-builtins) Do not call `Object.prototype` methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and `isPrototypeOf`.
|
||||
|
||||
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
console.log(object.hasOwnProperty(key));
|
||||
|
||||
// good
|
||||
console.log(Object.prototype.hasOwnProperty.call(object, key));
|
||||
|
||||
// best
|
||||
const has = Object.prototype.hasOwnProperty; // cache the lookup once, in module scope.
|
||||
/* or */
|
||||
const has = require('has');
|
||||
…
|
||||
console.log(has.call(object, key));
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Arrays
|
||||
@@ -324,7 +345,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="arrays--push"></a><a name="4.2"></a>
|
||||
- [4.2](#arrays--push) Use Array#push instead of direct assignment to add items to an array.
|
||||
- [4.2](#arrays--push) Use [Array#push](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push) instead of direct assignment to add items to an array.
|
||||
|
||||
```javascript
|
||||
const someStack = [];
|
||||
@@ -354,7 +375,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="arrays--from"></a><a name="4.4"></a>
|
||||
- [4.4](#arrays--from) To convert an array-like object to an array, use Array#from.
|
||||
- [4.4](#arrays--from) To convert an array-like object to an array, use [Array.from](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
|
||||
|
||||
```javascript
|
||||
const foo = document.querySelectorAll('.foo');
|
||||
@@ -378,7 +399,7 @@ Other Style Guides
|
||||
const flat = {};
|
||||
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
|
||||
const flatten = memo.concat(item);
|
||||
flat[index] = memo.concat(item);
|
||||
flat[index] = flatten;
|
||||
});
|
||||
|
||||
// good
|
||||
@@ -547,6 +568,20 @@ Other Style Guides
|
||||
<a name="strings--eval"></a><a name="6.5"></a>
|
||||
- [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities.
|
||||
|
||||
<a name="strings--escaping"></a>
|
||||
- [6.6](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape)
|
||||
|
||||
> Why? Backslashes harm readability, thus they should only be present when necessary.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const foo = '\'this\' \i\s \"quoted\"';
|
||||
|
||||
// good
|
||||
const foo = '\'this\' is "quoted"';
|
||||
const foo = `'this' is "quoted"`;
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
@@ -568,7 +603,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--iife"></a><a name="7.2"></a>
|
||||
- [7.2](#functions--iife) Immediately invoked function expressions: eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE)
|
||||
- [7.2](#functions--iife) Wrap immediately invoked function expressions in parentheses. eslint: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html) jscs: [`requireParenthesesAroundIIFE`](http://jscs.info/rule/requireParenthesesAroundIIFE)
|
||||
|
||||
> Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE.
|
||||
|
||||
@@ -618,7 +653,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="es6-rest"></a><a name="7.6"></a>
|
||||
- [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
|
||||
- [7.6](#es6-rest) Never use `arguments`, opt to use rest syntax `...` instead. eslint: [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
|
||||
|
||||
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
|
||||
|
||||
@@ -794,8 +829,6 @@ Other Style Guides
|
||||
|
||||
> Why? Syntactic sugar. It reads well when multiple functions are chained together.
|
||||
|
||||
> Why not? If you plan on returning an object.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
[1, 2, 3].map(number => {
|
||||
@@ -811,6 +844,11 @@ Other Style Guides
|
||||
const nextNumber = number + 1;
|
||||
return `A string containing the ${nextNumber}.`;
|
||||
});
|
||||
|
||||
// good
|
||||
[1, 2, 3].map((number, index) => ({
|
||||
index: number
|
||||
}));
|
||||
```
|
||||
|
||||
<a name="arrows--paren-wrap"></a><a name="8.3"></a>
|
||||
@@ -874,13 +912,19 @@ Other Style Guides
|
||||
const itemHeight = (item) => item.height > 256 ? item.largeSize : item.smallSize;
|
||||
|
||||
// good
|
||||
const itemHeight = (item) => { return item.height > 256 ? item.largeSize : item.smallSize; }
|
||||
const itemHeight = item => (item.height > 256 ? item.largeSize : item.smallSize);
|
||||
|
||||
// good
|
||||
const itemHeight = (item) => {
|
||||
const { height, largeSize, smallSize } = item;
|
||||
return height > 256 ? largeSize : smallSize;
|
||||
};
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
## Constructors
|
||||
## Classes & Constructors
|
||||
|
||||
<a name="constructors--use-class"></a><a name="9.1"></a>
|
||||
- [9.1](#constructors--use-class) Always use `class`. Avoid manipulating `prototype` directly.
|
||||
@@ -994,7 +1038,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="constructors--no-useless"></a><a name="9.5"></a>
|
||||
- [9.5](#constructors--no-useless) 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)
|
||||
- [9.5](#constructors--no-useless) 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. eslint: [`no-useless-constructor`](http://eslint.org/docs/rules/no-useless-constructor)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1022,6 +1066,30 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
<a name="classes--no-duplicate-members"></a>
|
||||
- [9.6](#classes--no-duplicate-members) Avoid duplicate class members. eslint: [`no-dupe-class-members`](http://eslint.org/docs/rules/no-dupe-class-members)
|
||||
|
||||
> Why? Duplicate class member declarations will silently prefer the last one - having duplicates is almost certainly a bug.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
class Foo {
|
||||
bar() { return 1; }
|
||||
bar() { return 2; }
|
||||
}
|
||||
|
||||
// good
|
||||
class Foo {
|
||||
bar() { return 1; }
|
||||
}
|
||||
|
||||
// good
|
||||
class Foo {
|
||||
bar() { return 2; }
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
@@ -1075,15 +1143,84 @@ Other Style Guides
|
||||
export default es6;
|
||||
```
|
||||
|
||||
<a name="modules--no-duplicate-imports"></a>
|
||||
- [10.4](#modules--no-duplicate-imports) Only import from a path in one place.
|
||||
eslint: [`no-duplicate-imports`](http://eslint.org/docs/rules/no-duplicate-imports)
|
||||
> Why? Having multiple lines that import from the same path can make code harder to maintain.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
import foo from 'foo';
|
||||
// … some other imports … //
|
||||
import { named1, named2 } from 'foo';
|
||||
|
||||
// good
|
||||
import foo, { named1, named2 } from 'foo';
|
||||
|
||||
// good
|
||||
import foo, {
|
||||
named1,
|
||||
named2,
|
||||
} from 'foo';
|
||||
```
|
||||
|
||||
<a name="modules--no-mutable-exports"></a>
|
||||
- [10.5](#modules--no-mutable-exports) Do not export mutable bindings.
|
||||
eslint: [`import/no-mutable-exports`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md)
|
||||
> Why? Mutation should be avoided in general, but in particular when exporting mutable bindings. While this technique may be needed for some special cases, in general, only constant references should be exported.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
let foo = 3;
|
||||
export { foo }
|
||||
|
||||
// good
|
||||
const foo = 3;
|
||||
export { foo }
|
||||
```
|
||||
|
||||
<a name="modules--prefer-default-export"></a>
|
||||
- [10.6](#modules--prefer-default-export) In modules with a single export, prefer default export over named export.
|
||||
eslint: [`import/prefer-default-export`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
export function foo() {}
|
||||
|
||||
// good
|
||||
export default function foo() {}
|
||||
```
|
||||
|
||||
<a name="modules--imports-first"></a>
|
||||
- [10.7](#modules--imports-first) Put all `import`s above non-import statements.
|
||||
eslint: [`import/imports-first`](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md)
|
||||
> Why? Since `import`s are hoisted, keeping them all at the top prevents surprising behavior.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
import foo from 'foo';
|
||||
foo.init();
|
||||
|
||||
import bar from 'bar';
|
||||
|
||||
// good
|
||||
import foo from 'foo';
|
||||
import bar from 'bar';
|
||||
|
||||
foo.init();
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Iterators and Generators
|
||||
|
||||
<a name="iterators--nope"></a><a name="11.1"></a>
|
||||
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html)
|
||||
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) [`no-restricted-syntax`](http://eslint.org/docs/rules/no-restricted-syntax)
|
||||
|
||||
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
|
||||
|
||||
> Use `map()` / `every()` / `filter()` / `find()` / `findIndex()` / `reduce()` / `some()` / ... to iterate over arrays, and `Object.keys()` / `Object.values()` / `Object.entries()` to produce arrays so you can iterate over objects.
|
||||
|
||||
```javascript
|
||||
const numbers = [1, 2, 3, 4, 5];
|
||||
|
||||
@@ -1110,6 +1247,50 @@ Other Style Guides
|
||||
|
||||
> Why? They don't transpile well to ES5.
|
||||
|
||||
<a name="generators--spacing"></a>
|
||||
- [11.3](#generators--spacing) If you must use generators, or if you disregard [our advice](#generators--nope), make sure their function signature is spaced properly. eslint: [`generator-star-spacing`](http://eslint.org/docs/rules/generator-star-spacing)
|
||||
|
||||
> Why? `function` and `*` are part of the same conceptual keyword - `*` is not a modifier for `function`, `function*` is a unique construct, different from `function`.
|
||||
|
||||
```js
|
||||
// bad
|
||||
function * foo() {
|
||||
}
|
||||
|
||||
const bar = function * () {
|
||||
}
|
||||
|
||||
const baz = function *() {
|
||||
}
|
||||
|
||||
const quux = function*() {
|
||||
}
|
||||
|
||||
function*foo() {
|
||||
}
|
||||
|
||||
function *foo() {
|
||||
}
|
||||
|
||||
// very bad
|
||||
function
|
||||
*
|
||||
foo() {
|
||||
}
|
||||
|
||||
const wat = function
|
||||
*
|
||||
() {
|
||||
}
|
||||
|
||||
// good
|
||||
function* foo() {
|
||||
}
|
||||
|
||||
const foo = function* () {
|
||||
}
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
@@ -1705,7 +1886,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="whitespace--around-keywords"></a><a name="18.3"></a>
|
||||
- [18.3](#whitespace--around-keywords) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords)
|
||||
- [18.3](#whitespace--around-keywords) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space between the argument list and the function name in function calls and declarations. eslint: [`keyword-spacing`](http://eslint.org/docs/rules/keyword-spacing.html) jscs: [`requireSpaceAfterKeywords`](http://jscs.info/rule/requireSpaceAfterKeywords)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1741,7 +1922,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="whitespace--newline-at-end"></a><a name="18.5"></a>
|
||||
- [18.5](#whitespace--newline-at-end) End files with a single newline character.
|
||||
- [18.5](#whitespace--newline-at-end) End files with a single newline character. eslint: [`eol-last`](https://github.com/eslint/eslint/blob/master/docs/rules/eol-last.md)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1939,7 +2120,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="whitespace--in-braces"></a><a name="18.11"></a>
|
||||
- [18.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`disallowSpacesInsideObjectBrackets`](http://jscs.info/rule/disallowSpacesInsideObjectBrackets)
|
||||
- [18.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html) jscs: [`requireSpacesInsideObjectBrackets`](http://jscs.info/rule/requireSpacesInsideObjectBrackets)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -2025,7 +2206,7 @@ Other Style Guides
|
||||
firstName: 'Florence',
|
||||
- lastName: 'Nightingale'
|
||||
+ lastName: 'Nightingale',
|
||||
+ inventorOf: ['coxcomb graph', 'modern nursing']
|
||||
+ inventorOf: ['coxcomb chart', 'modern nursing']
|
||||
};
|
||||
|
||||
// good - git diff with trailing comma
|
||||
@@ -2074,12 +2255,12 @@ Other Style Guides
|
||||
})()
|
||||
|
||||
// good
|
||||
(() => {
|
||||
(function () {
|
||||
const name = 'Skywalker';
|
||||
return name;
|
||||
}());
|
||||
|
||||
// good (guards against the function becoming an argument when two files with IIFEs are concatenated)
|
||||
// good, but legacy (guards against the function becoming an argument when two files with IIFEs are concatenated)
|
||||
;(() => {
|
||||
const name = 'Skywalker';
|
||||
return name;
|
||||
@@ -2171,7 +2352,7 @@ Other Style Guides
|
||||
// good
|
||||
const hasAge = Boolean(age);
|
||||
|
||||
// good
|
||||
// best
|
||||
const hasAge = !!age;
|
||||
```
|
||||
|
||||
@@ -2235,19 +2416,22 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="naming--leading-underscore"></a><a name="22.4"></a>
|
||||
- [22.4](#naming--leading-underscore) Use a leading underscore `_` when naming private properties. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores)
|
||||
- [22.4](#naming--leading-underscore) Do not use trailing or leading underscores. eslint: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html) jscs: [`disallowDanglingUnderscores`](http://jscs.info/rule/disallowDanglingUnderscores)
|
||||
|
||||
> Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won't count as breaking, or that tests aren't needed. tl;dr: if you want something to be “private”, it must not be observably present.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
this.__firstName__ = 'Panda';
|
||||
this.firstName_ = 'Panda';
|
||||
this._firstName = 'Panda';
|
||||
|
||||
// good
|
||||
this._firstName = 'Panda';
|
||||
this.firstName = 'Panda';
|
||||
```
|
||||
|
||||
<a name="naming--self-this"></a><a name="22.5"></a>
|
||||
- [22.5](#naming--self-this) Don't save references to `this`. Use arrow functions or Function#bind. jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes)
|
||||
- [22.5](#naming--self-this) Don't save references to `this`. Use arrow functions or [Function#bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). jscs: [`disallowNodeTypes`](http://jscs.info/rule/disallowNodeTypes)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -2275,24 +2459,39 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="naming--filename-matches-export"></a><a name="22.6"></a>
|
||||
- [22.6](#naming--filename-matches-export) If your file exports a single class, your filename should be exactly the name of the class.
|
||||
- [22.6](#naming--filename-matches-export) A base filename should exactly match the name of its default export.
|
||||
|
||||
```javascript
|
||||
// file contents
|
||||
// file 1 contents
|
||||
class CheckBox {
|
||||
// ...
|
||||
}
|
||||
export default CheckBox;
|
||||
|
||||
// file 2 contents
|
||||
export default function fortyTwo() { return 42; }
|
||||
|
||||
// file 3 contents
|
||||
export default function insideDirectory() {}
|
||||
|
||||
// in some other file
|
||||
// bad
|
||||
import CheckBox from './checkBox';
|
||||
import CheckBox from './checkBox'; // PascalCase import/export, camelCase filename
|
||||
import FortyTwo from './FortyTwo'; // PascalCase import/filename, camelCase export
|
||||
import InsideDirectory from './InsideDirectory'; // PascalCase import/filename, camelCase export
|
||||
|
||||
// bad
|
||||
import CheckBox from './check_box';
|
||||
import CheckBox from './check_box'; // PascalCase import/export, snake_case filename
|
||||
import forty_two from './forty_two'; // snake_case import/filename, camelCase export
|
||||
import inside_directory from './inside_directory'; // snake_case import, camelCase export
|
||||
import index from './inside_directory/index'; // requiring the index file explicitly
|
||||
import insideDirectory from './insideDirectory/index'; // requiring the index file explicitly
|
||||
|
||||
// good
|
||||
import CheckBox from './CheckBox';
|
||||
import CheckBox from './CheckBox'; // PascalCase export/import/filename
|
||||
import fortyTwo from './fortyTwo'; // camelCase export/import/filename
|
||||
import insideDirectory from './insideDirectory'; // camelCase export/import/directory name/implicit "index"
|
||||
// ^ supports both insideDirectory.js and insideDirectory/index.js
|
||||
```
|
||||
|
||||
<a name="naming--camelCase-default-export"></a><a name="22.7"></a>
|
||||
@@ -2306,7 +2505,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="naming--PascalCase-singleton"></a><a name="22.8"></a>
|
||||
- [22.8](#naming--PascalCase-singleton) Use PascalCase when you export a singleton / function library / bare object.
|
||||
- [22.8](#naming--PascalCase-singleton) Use PascalCase when you export a constructor / class / singleton / function library / bare object.
|
||||
|
||||
```javascript
|
||||
const AirbnbStyleGuide = {
|
||||
@@ -2331,16 +2530,26 @@ Other Style Guides
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
dragon.age();
|
||||
class Dragon {
|
||||
get age() {
|
||||
// ...
|
||||
}
|
||||
|
||||
set age(value) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
// good
|
||||
dragon.getAge();
|
||||
class Dragon {
|
||||
getAge() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// bad
|
||||
dragon.age(25);
|
||||
|
||||
// good
|
||||
dragon.setAge(25);
|
||||
setAge(value) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<a name="accessors--boolean-prefix"></a><a name="23.3"></a>
|
||||
@@ -2514,7 +2723,7 @@ Other Style Guides
|
||||
## Testing
|
||||
|
||||
<a name="testing--yup"></a><a name="28.1"></a>
|
||||
- [28.1](#esting--yup) **Yup.**
|
||||
- [28.1](#testing--yup) **Yup.**
|
||||
|
||||
```javascript
|
||||
function foo() {
|
||||
@@ -2543,6 +2752,7 @@ Other Style Guides
|
||||
- [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)
|
||||
- [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)
|
||||
- [Long String Concatenation](http://jsperf.com/ya-string-concat)
|
||||
- [Are Javascript functions like `map()`, `reduce()`, and `filter()` optimized for traversing arrays?](https://www.quora.com/JavaScript-programming-language-Are-Javascript-functions-like-map-reduce-and-filter-already-optimized-for-traversing-array/answer/Quildreen-Motta)
|
||||
- Loading...
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
@@ -2570,7 +2780,7 @@ Other Style Guides
|
||||
|
||||
**Other Style Guides**
|
||||
|
||||
- [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
|
||||
- [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml)
|
||||
- [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/)
|
||||
- [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js)
|
||||
|
||||
@@ -2633,6 +2843,7 @@ Other Style Guides
|
||||
|
||||
This is a list of organizations that are using this style guide. Send us a pull request and we'll add you to the list.
|
||||
|
||||
- **4Catalyzer**: [4Catalyzer/javascript](https://github.com/4Catalyzer/javascript)
|
||||
- **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
|
||||
- **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript)
|
||||
- **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
|
||||
@@ -2644,13 +2855,16 @@ Other Style Guides
|
||||
- **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/)
|
||||
- **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)
|
||||
- **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript)
|
||||
- **Chartboost**: [ChartBoost/javascript-style-guide](https://github.com/ChartBoost/javascript-style-guide)
|
||||
- **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)
|
||||
- **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
|
||||
- **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)
|
||||
- **DoSomething**: [DoSomething/eslint-config](https://github.com/DoSomething/eslint-config)
|
||||
- **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)
|
||||
- **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript)
|
||||
- **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide)
|
||||
- **Evolution Gaming**: [evolution-gaming/javascript](https://github.com/evolution-gaming/javascript)
|
||||
- **EvozonJs**: [evozonjs/javascript](https://github.com/evozonjs/javascript)
|
||||
- **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
|
||||
- **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md)
|
||||
- **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide)
|
||||
@@ -2667,6 +2881,7 @@ Other Style Guides
|
||||
- **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)
|
||||
- **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md)
|
||||
- **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
|
||||
- **KickorStick**: [kickorstick/javascript](https://github.com/kickorstick/javascript)
|
||||
- **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)
|
||||
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
|
||||
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
|
||||
@@ -2688,10 +2903,13 @@ Other Style Guides
|
||||
- **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
|
||||
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
|
||||
- **Springload**: [springload/javascript](https://github.com/springload/javascript)
|
||||
- **StratoDem Analytics**: [stratodem/javascript](https://github.com/stratodem/javascript)
|
||||
- **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)
|
||||
- **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide)
|
||||
- **Syzygy Warsaw**: [syzygypl/javascript](https://github.com/syzygypl/javascript)
|
||||
- **Target**: [target/javascript](https://github.com/target/javascript)
|
||||
- **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)
|
||||
- **The Nerdery**: [thenerdery/javascript-standards](https://github.com/thenerdery/javascript-standards)
|
||||
- **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)
|
||||
- **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide)
|
||||
- **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript)
|
||||
@@ -2713,7 +2931,7 @@ Other Style Guides
|
||||
-  **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)
|
||||
-  **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
|
||||
-  **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide)
|
||||
-  **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)
|
||||
-  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide)
|
||||
-  **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)
|
||||
-  **Polish**: [mjurczyk/javascript](https://github.com/mjurczyk/javascript)
|
||||
-  **Russian**: [uprock/javascript](https://github.com/uprock/javascript)
|
||||
|
||||
102
es5/README.md
102
es5/README.md
@@ -267,7 +267,7 @@
|
||||
|
||||
```javascript
|
||||
// anonymous function expression
|
||||
var anonymous = function() {
|
||||
var anonymous = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -277,9 +277,9 @@
|
||||
};
|
||||
|
||||
// immediately-invoked function expression (IIFE)
|
||||
(function() {
|
||||
(function () {
|
||||
console.log('Welcome to the Internet. Please follow me.');
|
||||
})();
|
||||
}());
|
||||
```
|
||||
|
||||
- Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.
|
||||
@@ -417,7 +417,7 @@
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
function () {
|
||||
test();
|
||||
console.log('doing stuff..');
|
||||
|
||||
@@ -433,7 +433,7 @@
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
function () {
|
||||
var name = getName();
|
||||
|
||||
test();
|
||||
@@ -449,7 +449,7 @@
|
||||
}
|
||||
|
||||
// bad - unnecessary function call
|
||||
function() {
|
||||
function () {
|
||||
var name = getName();
|
||||
|
||||
if (!arguments.length) {
|
||||
@@ -462,7 +462,7 @@
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
function () {
|
||||
var name;
|
||||
|
||||
if (!arguments.length) {
|
||||
@@ -517,7 +517,7 @@
|
||||
|
||||
anonymous(); // => TypeError anonymous is not a function
|
||||
|
||||
var anonymous = function() {
|
||||
var anonymous = function () {
|
||||
console.log('anonymous function expression');
|
||||
};
|
||||
}
|
||||
@@ -635,10 +635,10 @@
|
||||
}
|
||||
|
||||
// bad
|
||||
function() { return false; }
|
||||
function () { return false; }
|
||||
|
||||
// good
|
||||
function() {
|
||||
function () {
|
||||
return false;
|
||||
}
|
||||
```
|
||||
@@ -717,7 +717,7 @@
|
||||
function getType() {
|
||||
console.log('fetching type...');
|
||||
// set the default type to 'no type'
|
||||
var type = this._type || 'no type';
|
||||
var type = this.type || 'no type';
|
||||
|
||||
return type;
|
||||
}
|
||||
@@ -727,7 +727,7 @@
|
||||
console.log('fetching type...');
|
||||
|
||||
// set the default type to 'no type'
|
||||
var type = this._type || 'no type';
|
||||
var type = this.type || 'no type';
|
||||
|
||||
return type;
|
||||
}
|
||||
@@ -768,17 +768,17 @@
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
function () {
|
||||
∙∙∙∙var name;
|
||||
}
|
||||
|
||||
// bad
|
||||
function() {
|
||||
function () {
|
||||
∙var name;
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
function () {
|
||||
∙∙var name;
|
||||
}
|
||||
```
|
||||
@@ -847,14 +847,14 @@
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
(function(global) {
|
||||
(function (global) {
|
||||
// ...stuff...
|
||||
})(this);
|
||||
```
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
(function(global) {
|
||||
(function (global) {
|
||||
// ...stuff...
|
||||
})(this);↵
|
||||
↵
|
||||
@@ -862,7 +862,7 @@
|
||||
|
||||
```javascript
|
||||
// good
|
||||
(function(global) {
|
||||
(function (global) {
|
||||
// ...stuff...
|
||||
})(this);↵
|
||||
```
|
||||
@@ -925,19 +925,19 @@
|
||||
|
||||
// bad
|
||||
var obj = {
|
||||
foo: function() {
|
||||
foo: function () {
|
||||
},
|
||||
bar: function() {
|
||||
bar: function () {
|
||||
}
|
||||
};
|
||||
return obj;
|
||||
|
||||
// good
|
||||
var obj = {
|
||||
foo: function() {
|
||||
foo: function () {
|
||||
},
|
||||
|
||||
bar: function() {
|
||||
bar: function () {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1020,19 +1020,19 @@
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
(function() {
|
||||
(function () {
|
||||
var name = 'Skywalker'
|
||||
return name
|
||||
})()
|
||||
|
||||
// good
|
||||
(function() {
|
||||
(function () {
|
||||
var name = 'Skywalker';
|
||||
return name;
|
||||
})();
|
||||
|
||||
// good (guards against the function becoming an argument when two files with IIFEs are concatenated)
|
||||
;(function() {
|
||||
;(function () {
|
||||
var name = 'Skywalker';
|
||||
return name;
|
||||
})();
|
||||
@@ -1178,50 +1178,60 @@
|
||||
});
|
||||
```
|
||||
|
||||
- Use a leading underscore `_` when naming private properties.
|
||||
- Do not use trailing or leading underscores.
|
||||
|
||||
> Why? JavaScript does not have the concept of privacy in terms of properties or methods. Although a leading underscore is a common convention to mean “private”, in fact, these properties are fully public, and as such, are part of your public API contract. This convention might lead developers to wrongly think that a change won't count as breaking, or that tests aren't needed. tl;dr: if you want something to be “private”, it must not be observably present.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
this.__firstName__ = 'Panda';
|
||||
this.firstName_ = 'Panda';
|
||||
this._firstName = 'Panda';
|
||||
|
||||
// good
|
||||
this._firstName = 'Panda';
|
||||
this.firstName = 'Panda';
|
||||
```
|
||||
|
||||
- When saving a reference to `this` use `_this`.
|
||||
- Don't save references to this. Use Function#bind.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
function() {
|
||||
function () {
|
||||
var self = this;
|
||||
return function() {
|
||||
return function () {
|
||||
console.log(self);
|
||||
};
|
||||
}
|
||||
|
||||
// bad
|
||||
function() {
|
||||
function () {
|
||||
var that = this;
|
||||
return function() {
|
||||
return function () {
|
||||
console.log(that);
|
||||
};
|
||||
}
|
||||
|
||||
// good
|
||||
function() {
|
||||
// bad
|
||||
function () {
|
||||
var _this = this;
|
||||
return function() {
|
||||
return function () {
|
||||
console.log(_this);
|
||||
};
|
||||
}
|
||||
|
||||
// good
|
||||
function () {
|
||||
return function () {
|
||||
console.log(this);
|
||||
}.bind(this);
|
||||
}
|
||||
```
|
||||
|
||||
- Name your functions. This is helpful for stack traces.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var log = function(msg) {
|
||||
var log = function (msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
@@ -1297,11 +1307,11 @@
|
||||
this.set('lightsaber', lightsaber);
|
||||
}
|
||||
|
||||
Jedi.prototype.set = function(key, val) {
|
||||
Jedi.prototype.set = function set(key, val) {
|
||||
this[key] = val;
|
||||
};
|
||||
|
||||
Jedi.prototype.get = function(key) {
|
||||
Jedi.prototype.get = function get(key) {
|
||||
return this[key];
|
||||
};
|
||||
```
|
||||
@@ -1343,12 +1353,12 @@
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
Jedi.prototype.jump = function() {
|
||||
Jedi.prototype.jump = function jump() {
|
||||
this.jumping = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
Jedi.prototype.setHeight = function(height) {
|
||||
Jedi.prototype.setHeight = function setHeight(height) {
|
||||
this.height = height;
|
||||
};
|
||||
|
||||
@@ -1357,12 +1367,12 @@
|
||||
luke.setHeight(20); // => undefined
|
||||
|
||||
// good
|
||||
Jedi.prototype.jump = function() {
|
||||
Jedi.prototype.jump = function jump() {
|
||||
this.jumping = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
Jedi.prototype.setHeight = function(height) {
|
||||
Jedi.prototype.setHeight = function setHeight(height) {
|
||||
this.height = height;
|
||||
return this;
|
||||
};
|
||||
@@ -1404,7 +1414,7 @@
|
||||
|
||||
...
|
||||
|
||||
$(this).on('listingUpdated', function(e, listingId) {
|
||||
$(this).on('listingUpdated', function (e, listingId) {
|
||||
// do something with listingId
|
||||
});
|
||||
```
|
||||
@@ -1417,7 +1427,7 @@
|
||||
|
||||
...
|
||||
|
||||
$(this).on('listingUpdated', function(e, data) {
|
||||
$(this).on('listingUpdated', function (e, data) {
|
||||
// do something with data.listingId
|
||||
});
|
||||
```
|
||||
@@ -1435,7 +1445,7 @@
|
||||
```javascript
|
||||
// fancyInput/fancyInput.js
|
||||
|
||||
!function(global) {
|
||||
!function (global) {
|
||||
'use strict';
|
||||
|
||||
var previousFancyInput = global.FancyInput;
|
||||
@@ -1530,7 +1540,7 @@
|
||||
- **Yup.**
|
||||
|
||||
```javascript
|
||||
function() {
|
||||
function () {
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"node": true,
|
||||
|
||||
// Allow ES6.
|
||||
"esnext": true,
|
||||
"esversion": 6,
|
||||
|
||||
/*
|
||||
* ENFORCING OPTIONS
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
## `.eslintrc`
|
||||
|
||||
Our `.eslintrc` requires the following NPM packages:
|
||||
|
||||
```
|
||||
npm install --save-dev \
|
||||
eslint-config-airbnb \
|
||||
eslint \
|
||||
babel-eslint \
|
||||
eslint-plugin-react
|
||||
```
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
// Warn when variables are defined but never used.
|
||||
"unused": true,
|
||||
|
||||
|
||||
// Enforce line length to 80 characters
|
||||
"maxlen": 80,
|
||||
|
||||
|
||||
11
package.json
11
package.json
@@ -3,8 +3,15 @@
|
||||
"version": "2.0.0",
|
||||
"description": "A mostly reasonable approach to JavaScript.",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"publish-all": "npm publish && cd ./packages/eslint-config-airbnb && npm publish"
|
||||
"preinstall": "npm run install:config && npm run install:config:base",
|
||||
"install:config": "cd packages/eslint-config-airbnb && npm prune && npm install",
|
||||
"install:config:base": "cd packages/eslint-config-airbnb-base && npm prune && npm install",
|
||||
"test": "npm run --silent test:config && npm run --silent test:config:base",
|
||||
"test:config": "cd packages/eslint-config-airbnb; npm test",
|
||||
"test:config:base": "cd packages/eslint-config-airbnb-base; npm test",
|
||||
"travis": "npm run --silent travis:config && npm run --silent travis:config:base",
|
||||
"travis:config": "cd packages/eslint-config-airbnb; npm run travis",
|
||||
"travis:config:base": "cd packages/eslint-config-airbnb-base; npm run travis"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
3
packages/eslint-config-airbnb-base/.babelrc
Normal file
3
packages/eslint-config-airbnb-base/.babelrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["airbnb"]
|
||||
}
|
||||
8
packages/eslint-config-airbnb-base/.eslintrc
Normal file
8
packages/eslint-config-airbnb-base/.eslintrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./index.js",
|
||||
"rules": {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
84
packages/eslint-config-airbnb-base/CHANGELOG.md
Normal file
84
packages/eslint-config-airbnb-base/CHANGELOG.md
Normal file
@@ -0,0 +1,84 @@
|
||||
5.0.1 / 2016-07-29
|
||||
==================
|
||||
- [patch] `no-unused-expressions`: flesh out options
|
||||
- [deps] update `eslint` to `v3.2`, `eslint-plugin-import` to `v1.12`
|
||||
- [tests] improve prepublish script
|
||||
|
||||
5.0.0 / 2016-07-24
|
||||
==================
|
||||
- [breaking] enable `import/newline-after-import`
|
||||
- [breaking] enable overlooked rules: `linebreak-style`, `new-parens`, `no-continue`, `no-lonely-if`, `operator-assignment`, `space-unary-ops`, `dot-location`, `no-extra-boolean-cast`, `no-this-before-super`, `require-yield`, `no-path-concat`, `no-label-var`, `no-void`, `constructor-super`, `prefer-spread`, `no-new-require`, `no-undef-init`, `no-unexpected-multiline`
|
||||
- [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-import`, `babel-tape-runner`; add `babel-preset-airbnb`
|
||||
- [patch] flesh out defaults: `jsx-quotes`
|
||||
- [docs] update the peer dep install command to dynamically look up the right version numbers when installing peer deps
|
||||
- [tests] fix prepublish scripts
|
||||
|
||||
4.0.2 / 2016-07-14
|
||||
==================
|
||||
- [fix] repair accidental comma-dangle change
|
||||
|
||||
4.0.1 / 2016-07-14 (unpublished)
|
||||
==================
|
||||
- [fix] Prevent trailing commas in the legacy config (#950)
|
||||
- [deps] update `eslint-plugin-import`
|
||||
|
||||
4.0.0 / 2016-07-02
|
||||
==================
|
||||
- [breaking] [deps] update `eslint` to v3; drop support for < node 4
|
||||
- [breaking] enable `rest-spread-spacing` rule
|
||||
- [breaking] enable `no-mixed-operators` rule
|
||||
- [breaking] enable `import` rules: `no-named-as-default`, `no-named-as-default-member`, `no-extraneous-dependencies`
|
||||
- [breaking] enable `object-property-newline` rule
|
||||
- [breaking] enable `no-prototype-builtins` rule
|
||||
- [breaking] enable `no-useless-rename` rule
|
||||
- [breaking] enable `unicode-bom` rule
|
||||
- [breaking] Enforce proper generator star spacing (#887)
|
||||
- [breaking] Enable imports/imports-first rule (#882)
|
||||
- [breaking] re-order rules; put import rules in separate file (#881)
|
||||
- [patch] `newline-per-chained-call`: bump the limit to 4
|
||||
- [patch] `object-shorthand`: do not warn when the concise form would have a string literal as a name
|
||||
- [patch] Loosen `prefer-const` to not warn when the variable is “read” before being assigned to
|
||||
- [refactor] fix quoting of rule properties (#885)
|
||||
- [refactor] `quotes`: Use object option form rather than deprecated string form.
|
||||
- [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules`, `tape`
|
||||
- [tests] Only run `eslint-find-rules` on prepublish, not in tests
|
||||
|
||||
3.0.1 / 2016-05-08
|
||||
==================
|
||||
- [patch] re-disable `no-extra-parens` (#869, #867)
|
||||
|
||||
3.0.0 / 2016-05-07
|
||||
==================
|
||||
- [breaking] enable `import/no-mutable-exports`
|
||||
- [breaking] enable `no-class-assign` rule, to pair with `no-func-assign`
|
||||
- [breaking] widen `no-extra-parens` to include everything, except `nestedBinaryExpressions`
|
||||
- [breaking] Re-enabling `newline-per-chained-call` (#748)
|
||||
- [minor] enable `import/no-amd`
|
||||
- [patch] enable `import/no-duplicates`
|
||||
- [deps] update `eslint`, `eslint-plugin-import`, `eslint-find-rules`
|
||||
|
||||
2.0.0 / 2016-04-29
|
||||
==================
|
||||
- [breaking] enable `no-unsafe-finally` rule
|
||||
- [semver-minor] enable `no-useless-computed-key` rule
|
||||
- [deps] update `eslint`, `eslint-plugin-import`
|
||||
|
||||
1.0.4 / 2016-04-26
|
||||
==================
|
||||
- [deps] update `eslint-find-rules`, `eslint-plugin-import`
|
||||
|
||||
1.0.3 / 2016-04-21
|
||||
==================
|
||||
- [patch: loosen rules] Allow empty class/object methods
|
||||
|
||||
1.0.2 / 2016-04-20
|
||||
==================
|
||||
- [patch: loosen rules] Allow `break` (#840)
|
||||
|
||||
1.0.1 / 2016-04-19
|
||||
==================
|
||||
- [patch: loosen rules] Allow `== null` (#542)
|
||||
|
||||
1.0.0 / 2016-04-19
|
||||
==================
|
||||
- Initial commmit; moved content over from `eslint-config-airbnb` package.
|
||||
59
packages/eslint-config-airbnb-base/README.md
Normal file
59
packages/eslint-config-airbnb-base/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# eslint-config-airbnb-base
|
||||
|
||||
[](http://badge.fury.io/js/eslint-config-airbnb-base)
|
||||
|
||||
This package provides Airbnb's base JS .eslintrc as an extensible shared config.
|
||||
|
||||
## Usage
|
||||
|
||||
We export two ESLint configurations for your usage.
|
||||
|
||||
### eslint-config-airbnb-base
|
||||
|
||||
Our default export contains all of our ESLint rules, including ECMAScript 6+. It requires `eslint` and `eslint-plugin-import`.
|
||||
|
||||
1. Ensure packages are installed with correct version numbers by running:
|
||||
```sh
|
||||
(
|
||||
export PKG=eslint-config-airbnb-base;
|
||||
npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG"
|
||||
)
|
||||
```
|
||||
|
||||
Which produces and runs a command like:
|
||||
|
||||
```sh
|
||||
npm install --save-dev eslint-config-airbnb-base eslint@^3.0.1 eslint-plugin-import@^1.10.3
|
||||
```
|
||||
|
||||
2. Add `"extends": "airbnb-base"` to your .eslintrc
|
||||
|
||||
### eslint-config-airbnb-base/legacy
|
||||
|
||||
Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
|
||||
|
||||
1. Ensure packages are installed with correct version numbers by running:
|
||||
```sh
|
||||
(
|
||||
export PKG=eslint-config-airbnb-base;
|
||||
npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG"
|
||||
)
|
||||
```
|
||||
|
||||
Which produces and runs a command like:
|
||||
|
||||
```sh
|
||||
npm install --save-dev eslint-config-airbnb-base eslint@^3.0.1 eslint-plugin-import@^1.10.3
|
||||
```
|
||||
|
||||
2. Add `"extends": "airbnb-base/legacy"` to your .eslintrc
|
||||
|
||||
See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb), [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript), and the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information.
|
||||
|
||||
## Improving this config
|
||||
|
||||
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
|
||||
|
||||
You can run tests with `npm test`.
|
||||
|
||||
You can make sure this module lints with itself using `npm run lint`.
|
||||
18
packages/eslint-config-airbnb-base/index.js
Normal file
18
packages/eslint-config-airbnb-base/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./rules/best-practices',
|
||||
'./rules/errors',
|
||||
'./rules/node',
|
||||
'./rules/style',
|
||||
'./rules/variables',
|
||||
'./rules/es6',
|
||||
'./rules/imports',
|
||||
].map(require.resolve),
|
||||
parserOptions: {
|
||||
ecmaVersion: 7,
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
strict: 2,
|
||||
}
|
||||
};
|
||||
21
packages/eslint-config-airbnb-base/legacy.js
Normal file
21
packages/eslint-config-airbnb-base/legacy.js
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./rules/best-practices',
|
||||
'./rules/errors',
|
||||
'./rules/node',
|
||||
'./rules/style',
|
||||
'./rules/variables'
|
||||
].map(require.resolve),
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
amd: false,
|
||||
mocha: false,
|
||||
jasmine: false
|
||||
},
|
||||
ecmaFeatures: {},
|
||||
globals: {},
|
||||
rules: {
|
||||
'comma-dangle': [2, 'never']
|
||||
}
|
||||
};
|
||||
63
packages/eslint-config-airbnb-base/package.json
Normal file
63
packages/eslint-config-airbnb-base/package.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb-base",
|
||||
"version": "5.0.1",
|
||||
"description": "Airbnb's base JS ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test)",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"travis": "npm run --silent test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/airbnb/javascript"
|
||||
},
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"eslintconfig",
|
||||
"config",
|
||||
"airbnb",
|
||||
"javascript",
|
||||
"styleguide"
|
||||
],
|
||||
"author": "Jake Teton-Landis (https://twitter.com/@jitl)",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jake Teton-Landis",
|
||||
"url": "https://twitter.com/jitl"
|
||||
},
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
},
|
||||
{
|
||||
"name": "Harrison Shoff",
|
||||
"url": "https://twitter.com/hshoff"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/airbnb/javascript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"babel-preset-airbnb": "^2.0.0",
|
||||
"babel-tape-runner": "^2.0.1",
|
||||
"eslint": "^3.2.0",
|
||||
"eslint-find-rules": "^1.11.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"in-publish": "^2.0.0",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^3.2.0",
|
||||
"eslint-plugin-import": "^1.12.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
}
|
||||
@@ -1,132 +1,235 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
rules: {
|
||||
// enforces getter/setter pairs in objects
|
||||
'accessor-pairs': 0,
|
||||
|
||||
// enforces return statements in callbacks of array's methods
|
||||
// http://eslint.org/docs/rules/array-callback-return
|
||||
'array-callback-return': 2,
|
||||
|
||||
// treat var statements as if they were block scoped
|
||||
'block-scoped-var': 2,
|
||||
|
||||
// specify the maximum cyclomatic complexity allowed in a program
|
||||
'complexity': [0, 11],
|
||||
complexity: [0, 11],
|
||||
|
||||
// require return statements to either always or never specify values
|
||||
'consistent-return': 2,
|
||||
|
||||
// specify curly brace conventions for all control statements
|
||||
'curly': [2, 'multi-line'],
|
||||
curly: [2, 'multi-line'],
|
||||
|
||||
// require default case in switch statements
|
||||
'default-case': 2,
|
||||
'default-case': [2, { commentPattern: '^no default$' }],
|
||||
|
||||
// encourages use of dot notation whenever possible
|
||||
'dot-notation': [2, { 'allowKeywords': true }],
|
||||
'dot-notation': [2, { allowKeywords: true }],
|
||||
|
||||
// enforces consistent newlines before or after dots
|
||||
'dot-location': 0,
|
||||
// http://eslint.org/docs/rules/dot-location
|
||||
'dot-location': [2, 'property'],
|
||||
|
||||
// require the use of === and !==
|
||||
'eqeqeq': 2,
|
||||
// http://eslint.org/docs/rules/eqeqeq
|
||||
eqeqeq: [2, 'allow-null'],
|
||||
|
||||
// make sure for-in loops have an if statement
|
||||
'guard-for-in': 2,
|
||||
// Blacklist certain identifiers to prevent them being used
|
||||
// http://eslint.org/docs/rules/id-blacklist
|
||||
'id-blacklist': 0,
|
||||
|
||||
// disallow the use of alert, confirm, and prompt
|
||||
'no-alert': 1,
|
||||
|
||||
// disallow use of arguments.caller or arguments.callee
|
||||
'no-caller': 2,
|
||||
|
||||
// disallow lexical declarations in case/default clauses
|
||||
// http://eslint.org/docs/rules/no-case-declarations.html
|
||||
'no-case-declarations': 2,
|
||||
|
||||
// disallow division operators explicitly at beginning of regular expression
|
||||
// http://eslint.org/docs/rules/no-div-regex
|
||||
'no-div-regex': 0,
|
||||
|
||||
// disallow else after a return in an if
|
||||
'no-else-return': 2,
|
||||
|
||||
// disallow empty functions, except for standalone funcs/arrows
|
||||
// http://eslint.org/docs/rules/no-empty-function
|
||||
'no-empty-function': [2, {
|
||||
allow: [
|
||||
'arrowFunctions',
|
||||
'functions',
|
||||
'methods',
|
||||
]
|
||||
}],
|
||||
|
||||
// disallow empty destructuring patterns
|
||||
// http://eslint.org/docs/rules/no-empty-pattern
|
||||
'no-empty-pattern': 2,
|
||||
|
||||
// disallow comparisons to null without a type-checking operator
|
||||
'no-eq-null': 0,
|
||||
|
||||
// disallow use of eval()
|
||||
'no-eval': 2,
|
||||
|
||||
// disallow adding to native types
|
||||
'no-extend-native': 2,
|
||||
|
||||
// disallow unnecessary function binding
|
||||
'no-extra-bind': 2,
|
||||
|
||||
// disallow Unnecessary Labels
|
||||
// http://eslint.org/docs/rules/no-extra-label
|
||||
'no-extra-label': 2,
|
||||
// disallow comparisons to null without a type-checking operator
|
||||
'no-eq-null': 0,
|
||||
// disallow use of eval()
|
||||
'no-eval': 2,
|
||||
// disallow adding to native types
|
||||
'no-extend-native': 2,
|
||||
// disallow unnecessary function binding
|
||||
'no-extra-bind': 2,
|
||||
|
||||
// disallow fallthrough of case statements
|
||||
'no-fallthrough': 2,
|
||||
|
||||
// disallow the use of leading or trailing decimal points in numeric literals
|
||||
'no-floating-decimal': 2,
|
||||
// disallow the type conversions with shorter notations
|
||||
'no-implicit-coercion': 0,
|
||||
|
||||
// disallow implicit type conversions
|
||||
// http://eslint.org/docs/rules/no-implicit-coercion
|
||||
'no-implicit-coercion': [0, {
|
||||
boolean: false,
|
||||
number: true,
|
||||
string: true,
|
||||
allow: [],
|
||||
}],
|
||||
|
||||
// disallow var and named functions in global scope
|
||||
// http://eslint.org/docs/rules/no-implicit-globals
|
||||
'no-implicit-globals': 0,
|
||||
|
||||
// disallow use of eval()-like methods
|
||||
'no-implied-eval': 2,
|
||||
|
||||
// disallow this keywords outside of classes or class-like objects
|
||||
'no-invalid-this': 0,
|
||||
|
||||
// disallow usage of __iterator__ property
|
||||
'no-iterator': 2,
|
||||
|
||||
// disallow use of labels for anything other then loops and switches
|
||||
'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }],
|
||||
'no-labels': [2, { allowLoop: false, allowSwitch: false }],
|
||||
|
||||
// disallow unnecessary nested blocks
|
||||
'no-lone-blocks': 2,
|
||||
|
||||
// disallow creation of functions within loops
|
||||
'no-loop-func': 2,
|
||||
|
||||
// disallow magic numbers
|
||||
// http://eslint.org/docs/rules/no-magic-numbers
|
||||
'no-magic-numbers': [0, {
|
||||
ignore: [],
|
||||
ignoreArrayIndexes: true,
|
||||
enforceConst: true,
|
||||
detectObjects: false,
|
||||
}],
|
||||
|
||||
// disallow use of multiple spaces
|
||||
'no-multi-spaces': 2,
|
||||
|
||||
// disallow use of multiline strings
|
||||
'no-multi-str': 2,
|
||||
|
||||
// disallow reassignments of native objects
|
||||
'no-native-reassign': 2,
|
||||
|
||||
// disallow use of new operator when not part of the assignment or comparison
|
||||
'no-new': 2,
|
||||
|
||||
// disallow use of new operator for Function object
|
||||
'no-new-func': 2,
|
||||
|
||||
// disallows creating new instances of String, Number, and Boolean
|
||||
'no-new-wrappers': 2,
|
||||
|
||||
// disallow use of (old style) octal literals
|
||||
'no-octal': 2,
|
||||
|
||||
// disallow use of octal escape sequences in string literals, such as
|
||||
// var foo = 'Copyright \251';
|
||||
'no-octal-escape': 2,
|
||||
|
||||
// disallow reassignment of function parameters
|
||||
// disallow parameter object manipulation
|
||||
// rule: http://eslint.org/docs/rules/no-param-reassign.html
|
||||
'no-param-reassign': [2, { 'props': true }],
|
||||
// disallow use of process.env
|
||||
'no-process-env': 0,
|
||||
'no-param-reassign': [2, { props: true }],
|
||||
|
||||
// disallow usage of __proto__ property
|
||||
'no-proto': 2,
|
||||
|
||||
// disallow declaring the same variable more then once
|
||||
'no-redeclare': 2,
|
||||
|
||||
// disallow use of assignment in return statement
|
||||
'no-return-assign': 2,
|
||||
|
||||
// disallow use of `javascript:` urls.
|
||||
'no-script-url': 2,
|
||||
|
||||
// disallow self assignment
|
||||
// http://eslint.org/docs/rules/no-self-assign
|
||||
'no-self-assign': 2,
|
||||
|
||||
// disallow comparisons where both sides are exactly the same
|
||||
'no-self-compare': 2,
|
||||
|
||||
// disallow use of comma operator
|
||||
'no-sequences': 2,
|
||||
|
||||
// restrict what can be thrown as an exception
|
||||
'no-throw-literal': 2,
|
||||
|
||||
// disallow unmodified conditions of loops
|
||||
// http://eslint.org/docs/rules/no-unmodified-loop-condition
|
||||
'no-unmodified-loop-condition': 0,
|
||||
|
||||
// disallow usage of expressions in statement position
|
||||
'no-unused-expressions': 2,
|
||||
'no-unused-expressions': [2, {
|
||||
allowShortCircuit: false,
|
||||
allowTernary: false,
|
||||
}],
|
||||
|
||||
// disallow unused labels
|
||||
// http://eslint.org/docs/rules/no-unused-labels
|
||||
'no-unused-labels': 2,
|
||||
|
||||
// disallow unnecessary .call() and .apply()
|
||||
'no-useless-call': 0,
|
||||
|
||||
// disallow useless string concatenation
|
||||
// http://eslint.org/docs/rules/no-useless-concat
|
||||
'no-useless-concat': 2,
|
||||
|
||||
// disallow unnecessary string escaping
|
||||
// http://eslint.org/docs/rules/no-useless-escape
|
||||
'no-useless-escape': 2,
|
||||
|
||||
// disallow use of void operator
|
||||
'no-void': 0,
|
||||
// http://eslint.org/docs/rules/no-void
|
||||
'no-void': 2,
|
||||
|
||||
// disallow usage of configurable warning terms in comments: e.g. todo
|
||||
'no-warning-comments': [0, { 'terms': ['todo', 'fixme', 'xxx'], 'location': 'start' }],
|
||||
'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }],
|
||||
|
||||
// disallow use of the with statement
|
||||
'no-with': 2,
|
||||
|
||||
// require use of the second argument for parseInt()
|
||||
'radix': 2,
|
||||
radix: 2,
|
||||
|
||||
// requires to declare all vars on top of their containing scope
|
||||
'vars-on-top': 2,
|
||||
|
||||
// require immediate function invocation to be wrapped in parentheses
|
||||
// http://eslint.org/docs/rules/wrap-iife.html
|
||||
'wrap-iife': [2, 'outside'],
|
||||
|
||||
// require or disallow Yoda conditions
|
||||
'yoda': 2
|
||||
yoda: 2
|
||||
}
|
||||
};
|
||||
@@ -1,58 +1,103 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
rules: {
|
||||
// require trailing commas in multiline object literals
|
||||
'comma-dangle': [2, 'always-multiline'],
|
||||
|
||||
// disallow assignment in conditional expressions
|
||||
'no-cond-assign': [2, 'always'],
|
||||
|
||||
// disallow use of console
|
||||
'no-console': 1,
|
||||
|
||||
// disallow use of constant expressions in conditions
|
||||
'no-constant-condition': 1,
|
||||
|
||||
// disallow control characters in regular expressions
|
||||
'no-control-regex': 2,
|
||||
|
||||
// disallow use of debugger
|
||||
'no-debugger': 1,
|
||||
'no-debugger': 2,
|
||||
|
||||
// disallow duplicate arguments in functions
|
||||
'no-dupe-args': 2,
|
||||
|
||||
// disallow duplicate keys when creating object literals
|
||||
'no-dupe-keys': 2,
|
||||
|
||||
// disallow a duplicate case label.
|
||||
'no-duplicate-case': 2,
|
||||
// disallow the use of empty character classes in regular expressions
|
||||
'no-empty-character-class': 2,
|
||||
|
||||
// disallow empty statements
|
||||
'no-empty': 2,
|
||||
|
||||
// disallow the use of empty character classes in regular expressions
|
||||
'no-empty-character-class': 2,
|
||||
|
||||
// disallow assigning to the exception in a catch block
|
||||
'no-ex-assign': 2,
|
||||
|
||||
// disallow double-negation boolean casts in a boolean context
|
||||
'no-extra-boolean-cast': 0,
|
||||
// http://eslint.org/docs/rules/no-extra-boolean-cast
|
||||
'no-extra-boolean-cast': 2,
|
||||
|
||||
// disallow unnecessary parentheses
|
||||
'no-extra-parens': [2, 'functions'],
|
||||
// http://eslint.org/docs/rules/no-extra-parens
|
||||
'no-extra-parens': [0, 'all', {
|
||||
conditionalAssign: true,
|
||||
nestedBinaryExpressions: false,
|
||||
returnAssign: false,
|
||||
}],
|
||||
|
||||
// disallow unnecessary semicolons
|
||||
'no-extra-semi': 2,
|
||||
|
||||
// disallow overwriting functions written as function declarations
|
||||
'no-func-assign': 2,
|
||||
|
||||
// disallow function or variable declarations in nested blocks
|
||||
'no-inner-declarations': 2,
|
||||
|
||||
// disallow invalid regular expression strings in the RegExp constructor
|
||||
'no-invalid-regexp': 2,
|
||||
|
||||
// disallow irregular whitespace outside of strings and comments
|
||||
'no-irregular-whitespace': 2,
|
||||
|
||||
// disallow negation of the left operand of an in expression
|
||||
'no-negated-in-lhs': 2,
|
||||
|
||||
// disallow the use of object properties of the global object (Math and JSON) as functions
|
||||
'no-obj-calls': 2,
|
||||
|
||||
// disallow use of Object.prototypes builtins directly
|
||||
// http://eslint.org/docs/rules/no-prototype-builtins
|
||||
'no-prototype-builtins': 2,
|
||||
|
||||
// disallow multiple spaces in a regular expression literal
|
||||
'no-regex-spaces': 2,
|
||||
|
||||
// disallow sparse arrays
|
||||
'no-sparse-arrays': 2,
|
||||
|
||||
// Avoid code that looks like two expressions but is actually one
|
||||
// http://eslint.org/docs/rules/no-unexpected-multiline
|
||||
'no-unexpected-multiline': 2,
|
||||
|
||||
// disallow unreachable statements after a return, throw, continue, or break statement
|
||||
'no-unreachable': 2,
|
||||
|
||||
// disallow return/throw/break/continue inside finally blocks
|
||||
// http://eslint.org/docs/rules/no-unsafe-finally
|
||||
'no-unsafe-finally': 2,
|
||||
|
||||
// disallow comparisons with the value NaN
|
||||
'use-isnan': 2,
|
||||
|
||||
// ensure JSDoc comments are valid
|
||||
// http://eslint.org/docs/rules/valid-jsdoc
|
||||
'valid-jsdoc': 0,
|
||||
|
||||
// ensure that the results of typeof are compared against a valid string
|
||||
'valid-typeof': 2,
|
||||
// Avoid code that looks like two expressions but is actually one
|
||||
'no-unexpected-multiline': 0
|
||||
'valid-typeof': 2
|
||||
}
|
||||
};
|
||||
@@ -1,80 +1,143 @@
|
||||
module.exports = {
|
||||
'env': {
|
||||
'es6': true
|
||||
env: {
|
||||
es6: true
|
||||
},
|
||||
'parserOptions': {
|
||||
'ecmaVersion': 6,
|
||||
'sourceType': 'module',
|
||||
'ecmaFeatures': {
|
||||
'jsx': true,
|
||||
'generators': false,
|
||||
'objectLiteralDuplicateProperties': false
|
||||
parserOptions: {
|
||||
ecmaVersion: 6,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: {
|
||||
generators: false,
|
||||
objectLiteralDuplicateProperties: false
|
||||
}
|
||||
},
|
||||
'rules': {
|
||||
|
||||
rules: {
|
||||
// enforces no braces where they can be omitted
|
||||
// http://eslint.org/docs/rules/arrow-body-style
|
||||
'arrow-body-style': [2, 'as-needed'],
|
||||
|
||||
// require parens in arrow function arguments
|
||||
'arrow-parens': 0,
|
||||
|
||||
// require space before/after arrow function's arrow
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/arrow-spacing.md
|
||||
'arrow-spacing': [2, { 'before': true, 'after': true }],
|
||||
// require trailing commas in multiline object literals
|
||||
'comma-dangle': [2, 'always-multiline'],
|
||||
// http://eslint.org/docs/rules/arrow-spacing
|
||||
'arrow-spacing': [2, { before: true, after: true }],
|
||||
|
||||
// verify super() callings in constructors
|
||||
'constructor-super': 0,
|
||||
'constructor-super': 2,
|
||||
|
||||
// enforce the spacing around the * in generator functions
|
||||
'generator-star-spacing': 0,
|
||||
// http://eslint.org/docs/rules/generator-star-spacing
|
||||
'generator-star-spacing': [2, { before: false, after: true }],
|
||||
|
||||
// disallow modifying variables of class declarations
|
||||
'no-class-assign': 0,
|
||||
// http://eslint.org/docs/rules/no-class-assign
|
||||
'no-class-assign': 2,
|
||||
|
||||
// disallow arrow functions where they could be confused with comparisons
|
||||
// http://eslint.org/docs/rules/no-confusing-arrow
|
||||
'no-confusing-arrow': [2, {
|
||||
'allowParens': true,
|
||||
allowParens: true,
|
||||
}],
|
||||
|
||||
// disallow modifying variables that are declared using const
|
||||
'no-const-assign': 2,
|
||||
|
||||
// disallow duplicate class members
|
||||
// http://eslint.org/docs/rules/no-dupe-class-members
|
||||
'no-dupe-class-members': 2,
|
||||
|
||||
// disallow importing from the same path more than once
|
||||
// http://eslint.org/docs/rules/no-duplicate-imports
|
||||
'no-duplicate-imports': 2,
|
||||
|
||||
// disallow symbol constructor
|
||||
// http://eslint.org/docs/rules/no-new-symbol
|
||||
'no-new-symbol': 2,
|
||||
// disallow specific globals
|
||||
'no-restricted-globals': 0,
|
||||
|
||||
// disallow specific imports
|
||||
// http://eslint.org/docs/rules/no-restricted-imports
|
||||
'no-restricted-imports': 0,
|
||||
|
||||
// disallow to use this/super before super() calling in constructors.
|
||||
'no-this-before-super': 0,
|
||||
// require let or const instead of var
|
||||
'no-var': 2,
|
||||
// http://eslint.org/docs/rules/no-this-before-super
|
||||
'no-this-before-super': 2,
|
||||
|
||||
// disallow useless computed property keys
|
||||
// http://eslint.org/docs/rules/no-useless-computed-key
|
||||
'no-useless-computed-key': 2,
|
||||
|
||||
// disallow unnecessary constructor
|
||||
// http://eslint.org/docs/rules/no-useless-constructor
|
||||
'no-useless-constructor': 2,
|
||||
|
||||
// disallow renaming import, export, and destructured assignments to the same name
|
||||
// http://eslint.org/docs/rules/no-useless-rename
|
||||
'no-useless-rename': [2, {
|
||||
ignoreDestructuring: false,
|
||||
ignoreImport: false,
|
||||
ignoreExport: false,
|
||||
}],
|
||||
|
||||
// require let or const instead of var
|
||||
'no-var': 2,
|
||||
|
||||
// require method and property shorthand syntax for object literals
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/object-shorthand.md
|
||||
'object-shorthand': [2, 'always'],
|
||||
// http://eslint.org/docs/rules/object-shorthand
|
||||
'object-shorthand': [2, 'always', {
|
||||
ignoreConstructors: false,
|
||||
avoidQuotes: true,
|
||||
}],
|
||||
|
||||
// suggest using arrow functions as callbacks
|
||||
'prefer-arrow-callback': 2,
|
||||
'prefer-arrow-callback': [2, {
|
||||
allowNamedFunctions: false,
|
||||
allowUnboundThis: true,
|
||||
}],
|
||||
|
||||
// suggest using of const declaration for variables that are never modified after declared
|
||||
'prefer-const': 2,
|
||||
// suggest using the spread operator instead of .apply()
|
||||
'prefer-spread': 0,
|
||||
'prefer-const': [2, {
|
||||
destructuring: 'any',
|
||||
ignoreReadBeforeAssign: true,
|
||||
}],
|
||||
|
||||
// suggest using Reflect methods where applicable
|
||||
// http://eslint.org/docs/rules/prefer-reflect
|
||||
// TODO: enable
|
||||
'prefer-reflect': 0,
|
||||
|
||||
// use rest parameters instead of arguments
|
||||
// http://eslint.org/docs/rules/prefer-rest-params
|
||||
'prefer-rest-params': 2,
|
||||
|
||||
// suggest using the spread operator instead of .apply()
|
||||
// http://eslint.org/docs/rules/prefer-spread
|
||||
'prefer-spread': 2,
|
||||
|
||||
// suggest using template literals instead of string concatenation
|
||||
// http://eslint.org/docs/rules/prefer-template
|
||||
'prefer-template': 2,
|
||||
|
||||
// disallow generator functions that do not have yield
|
||||
'require-yield': 0,
|
||||
// http://eslint.org/docs/rules/require-yield
|
||||
'require-yield': 2,
|
||||
|
||||
// enforce spacing between object rest-spread
|
||||
// http://eslint.org/docs/rules/rest-spread-spacing
|
||||
'rest-spread-spacing': [2, 'never'],
|
||||
|
||||
// import sorting
|
||||
// http://eslint.org/docs/rules/sort-imports
|
||||
'sort-imports': 0,
|
||||
'sort-imports': [0, {
|
||||
ignoreCase: false,
|
||||
ignoreMemberSort: false,
|
||||
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
|
||||
}],
|
||||
|
||||
// enforce usage of spacing in template strings
|
||||
// http://eslint.org/docs/rules/template-curly-spacing
|
||||
'template-curly-spacing': 2,
|
||||
|
||||
// enforce spacing around the * in yield* expressions
|
||||
// http://eslint.org/docs/rules/yield-star-spacing
|
||||
'yield-star-spacing': [2, 'after']
|
||||
132
packages/eslint-config-airbnb-base/rules/imports.js
Normal file
132
packages/eslint-config-airbnb-base/rules/imports.js
Normal file
@@ -0,0 +1,132 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
es6: true
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 6,
|
||||
sourceType: 'module'
|
||||
},
|
||||
plugins: [
|
||||
'import'
|
||||
],
|
||||
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
node: {
|
||||
extensions: ['.js', '.json']
|
||||
}
|
||||
},
|
||||
'import/extensions': [
|
||||
'node_modules',
|
||||
],
|
||||
'import/core-modules': [
|
||||
],
|
||||
'import/ignore': [
|
||||
'node_modules',
|
||||
'\\.(coffee|scss|css|less|hbs|svg|json)$',
|
||||
],
|
||||
},
|
||||
|
||||
rules: {
|
||||
// Static analysis:
|
||||
|
||||
// ensure imports point to files/modules that can be resolved
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
|
||||
'import/no-unresolved': [2, { commonjs: true }],
|
||||
|
||||
// ensure named imports coupled with named exports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
|
||||
'import/named': 0,
|
||||
|
||||
// ensure default import coupled with default export
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
|
||||
'import/default': 0,
|
||||
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/namespace.md
|
||||
'import/namespace': 0,
|
||||
|
||||
// Helpful warnings:
|
||||
|
||||
// disallow invalid exports, e.g. multiple defaults
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
|
||||
'import/export': 2,
|
||||
|
||||
// do not allow a default import name to match a named export
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
|
||||
'import/no-named-as-default': 2,
|
||||
|
||||
// warn on accessing default export property names that are also named exports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
|
||||
'import/no-named-as-default-member': 2,
|
||||
|
||||
// disallow use of jsdoc-marked-deprecated imports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
|
||||
'import/no-deprecated': 0,
|
||||
|
||||
// Forbid the use of extraneous packages
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
|
||||
'import/no-extraneous-dependencies': [2, {
|
||||
devDependencies: false,
|
||||
optionalDependencies: false,
|
||||
}],
|
||||
|
||||
// Forbid mutable exports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
|
||||
'import/no-mutable-exports': 2,
|
||||
|
||||
// Module systems:
|
||||
|
||||
// disallow require()
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
|
||||
'import/no-commonjs': 0,
|
||||
|
||||
// disallow AMD require/define
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-amd.md
|
||||
'import/no-amd': 2,
|
||||
|
||||
// No Node.js builtin modules
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
|
||||
// TODO: enable?
|
||||
'import/no-nodejs-modules': 0,
|
||||
|
||||
// Style guide:
|
||||
|
||||
// disallow non-import statements appearing before import statements
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
|
||||
'import/imports-first': [2, 'absolute-first'],
|
||||
|
||||
// disallow duplicate imports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
|
||||
'import/no-duplicates': 2,
|
||||
|
||||
// disallow namespace imports
|
||||
// TODO: enable?
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
|
||||
'import/no-namespace': 0,
|
||||
|
||||
// Ensure consistent use of file extension within the import path
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
|
||||
// TODO: enable when https://github.com/benmosher/eslint-plugin-import/issues/390 is resolved
|
||||
'import/extensions': [0, 'never'],
|
||||
|
||||
// Enforce a convention in module import order
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
|
||||
// TODO: enable?
|
||||
'import/order': [0, {
|
||||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
||||
'newlines-between': 'never',
|
||||
}],
|
||||
|
||||
// Require a newline after the last import/require in a group
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
|
||||
'import/newline-after-import': 2,
|
||||
|
||||
// Require modules with a single export to use a default export
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
|
||||
'import/prefer-default-export': 2,
|
||||
|
||||
// Restrict which files can be imported in a given folder
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
|
||||
'import/no-restricted-paths': 0,
|
||||
},
|
||||
};
|
||||
@@ -1,23 +1,39 @@
|
||||
module.exports = {
|
||||
'env': {
|
||||
'node': true
|
||||
env: {
|
||||
node: true
|
||||
},
|
||||
'rules': {
|
||||
|
||||
rules: {
|
||||
// enforce return after a callback
|
||||
'callback-return': 0,
|
||||
|
||||
// require all requires be top-level
|
||||
// http://eslint.org/docs/rules/global-require
|
||||
'global-require': 2,
|
||||
|
||||
// enforces error handling in callbacks (node environment)
|
||||
'handle-callback-err': 0,
|
||||
|
||||
// disallow mixing regular variable and require declarations
|
||||
'no-mixed-requires': [0, false],
|
||||
|
||||
// disallow use of new operator with the require function
|
||||
'no-new-require': 0,
|
||||
'no-new-require': 2,
|
||||
|
||||
// disallow string concatenation with __dirname and __filename
|
||||
'no-path-concat': 0,
|
||||
// http://eslint.org/docs/rules/no-path-concat
|
||||
'no-path-concat': 2,
|
||||
|
||||
// disallow use of process.env
|
||||
'no-process-env': 0,
|
||||
|
||||
// disallow process.exit()
|
||||
'no-process-exit': 0,
|
||||
|
||||
// restrict usage of specified node modules
|
||||
'no-restricted-modules': 0,
|
||||
|
||||
// disallow use of synchronous methods (off by default)
|
||||
'no-sync': 0
|
||||
'no-sync': 0,
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
rules: {
|
||||
// babel inserts `'use strict';` for us
|
||||
'strict': [2, 'never']
|
||||
strict: [2, 'never']
|
||||
}
|
||||
};
|
||||
305
packages/eslint-config-airbnb-base/rules/style.js
Normal file
305
packages/eslint-config-airbnb-base/rules/style.js
Normal file
@@ -0,0 +1,305 @@
|
||||
module.exports = {
|
||||
rules: {
|
||||
// enforce spacing inside array brackets
|
||||
'array-bracket-spacing': [2, 'never'],
|
||||
|
||||
// enforce spacing inside single-line blocks
|
||||
// http://eslint.org/docs/rules/block-spacing
|
||||
'block-spacing': [2, 'always'],
|
||||
|
||||
// enforce one true brace style
|
||||
'brace-style': [2, '1tbs', { allowSingleLine: true }],
|
||||
|
||||
// require camel case names
|
||||
camelcase: [2, { properties: 'never' }],
|
||||
|
||||
// enforce spacing before and after comma
|
||||
'comma-spacing': [2, { before: false, after: true }],
|
||||
|
||||
// enforce one true comma style
|
||||
'comma-style': [2, 'last'],
|
||||
|
||||
// disallow padding inside computed properties
|
||||
'computed-property-spacing': [2, 'never'],
|
||||
|
||||
// enforces consistent naming when capturing the current execution context
|
||||
'consistent-this': 0,
|
||||
|
||||
// enforce newline at the end of file, with no multiple empty lines
|
||||
'eol-last': 2,
|
||||
|
||||
// require function expressions to have a name
|
||||
'func-names': 1,
|
||||
|
||||
// enforces use of function declarations or expressions
|
||||
'func-style': 0,
|
||||
|
||||
// Blacklist certain identifiers to prevent them being used
|
||||
// http://eslint.org/docs/rules/id-blacklist
|
||||
'id-blacklist': 0,
|
||||
|
||||
// this option enforces minimum and maximum identifier lengths
|
||||
// (variable names, property names etc.)
|
||||
'id-length': 0,
|
||||
|
||||
// require identifiers to match the provided regular expression
|
||||
'id-match': 0,
|
||||
|
||||
// this option sets a specific tab width for your code
|
||||
// http://eslint.org/docs/rules/indent
|
||||
indent: [2, 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
|
||||
|
||||
// specify whether double or single quotes should be used in JSX attributes
|
||||
// http://eslint.org/docs/rules/jsx-quotes
|
||||
'jsx-quotes': [0, 'prefer-double'],
|
||||
|
||||
// enforces spacing between keys and values in object literal properties
|
||||
'key-spacing': [2, { beforeColon: false, afterColon: true }],
|
||||
|
||||
// require a space before & after certain keywords
|
||||
'keyword-spacing': [2, {
|
||||
before: true,
|
||||
after: true,
|
||||
overrides: {
|
||||
return: { after: true },
|
||||
throw: { after: true },
|
||||
case: { after: true }
|
||||
}
|
||||
}],
|
||||
|
||||
// disallow mixed 'LF' and 'CRLF' as linebreaks
|
||||
// http://eslint.org/docs/rules/linebreak-style
|
||||
'linebreak-style': [2, 'unix'],
|
||||
|
||||
// enforces empty lines around comments
|
||||
'lines-around-comment': 0,
|
||||
|
||||
// specify the maximum depth that blocks can be nested
|
||||
'max-depth': [0, 4],
|
||||
|
||||
// specify the maximum length of a line in your program
|
||||
// http://eslint.org/docs/rules/max-len
|
||||
'max-len': [2, 100, 2, {
|
||||
ignoreUrls: true,
|
||||
ignoreComments: false
|
||||
}],
|
||||
|
||||
// specify the max number of lines in a file
|
||||
// http://eslint.org/docs/rules/max-lines
|
||||
'max-lines': [0, {
|
||||
max: 300,
|
||||
skipBlankLines: true,
|
||||
skipComments: true
|
||||
}],
|
||||
|
||||
// specify the maximum depth callbacks can be nested
|
||||
'max-nested-callbacks': 0,
|
||||
|
||||
// limits the number of parameters that can be used in the function declaration.
|
||||
'max-params': [0, 3],
|
||||
|
||||
// specify the maximum number of statement allowed in a function
|
||||
'max-statements': [0, 10],
|
||||
|
||||
// restrict the number of statements per line
|
||||
// http://eslint.org/docs/rules/max-statements-per-line
|
||||
'max-statements-per-line': [0, { max: 1 }],
|
||||
|
||||
// require multiline ternary
|
||||
// http://eslint.org/docs/rules/multiline-ternary
|
||||
'multiline-ternary': 0,
|
||||
|
||||
// require a capital letter for constructors
|
||||
'new-cap': [2, { newIsCap: true }],
|
||||
|
||||
// disallow the omission of parentheses when invoking a constructor with no arguments
|
||||
// http://eslint.org/docs/rules/new-parens
|
||||
'new-parens': 2,
|
||||
|
||||
// allow/disallow an empty newline after var statement
|
||||
'newline-after-var': 0,
|
||||
|
||||
// http://eslint.org/docs/rules/newline-before-return
|
||||
'newline-before-return': 0,
|
||||
|
||||
// enforces new line after each method call in the chain to make it
|
||||
// more readable and easy to maintain
|
||||
// http://eslint.org/docs/rules/newline-per-chained-call
|
||||
'newline-per-chained-call': [2, { ignoreChainWithDepth: 4 }],
|
||||
|
||||
// disallow use of the Array constructor
|
||||
'no-array-constructor': 2,
|
||||
|
||||
// disallow use of bitwise operators
|
||||
// http://eslint.org/docs/rules/no-bitwise
|
||||
// TODO: enable
|
||||
'no-bitwise': 0,
|
||||
|
||||
// disallow use of the continue statement
|
||||
// http://eslint.org/docs/rules/no-continue
|
||||
'no-continue': 2,
|
||||
|
||||
// disallow comments inline after code
|
||||
'no-inline-comments': 0,
|
||||
|
||||
// disallow if as the only statement in an else block
|
||||
// http://eslint.org/docs/rules/no-lonely-if
|
||||
'no-lonely-if': 2,
|
||||
|
||||
// disallow un-paren'd mixes of different operators
|
||||
// http://eslint.org/docs/rules/no-mixed-operators
|
||||
'no-mixed-operators': [2, {
|
||||
groups: [
|
||||
['+', '-', '*', '/', '%', '**'],
|
||||
['&', '|', '^', '~', '<<', '>>', '>>>'],
|
||||
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
||||
['&&', '||'],
|
||||
['in', 'instanceof']
|
||||
],
|
||||
allowSamePrecedence: false
|
||||
}],
|
||||
|
||||
// disallow mixed spaces and tabs for indentation
|
||||
'no-mixed-spaces-and-tabs': 2,
|
||||
|
||||
// disallow multiple empty lines and only one newline at the end
|
||||
'no-multiple-empty-lines': [2, { max: 2, maxEOF: 1 }],
|
||||
|
||||
// disallow negated conditions
|
||||
// http://eslint.org/docs/rules/no-negated-condition
|
||||
'no-negated-condition': 0,
|
||||
|
||||
// disallow nested ternary expressions
|
||||
'no-nested-ternary': 2,
|
||||
|
||||
// disallow use of the Object constructor
|
||||
'no-new-object': 2,
|
||||
|
||||
// disallow use of unary operators, ++ and --
|
||||
'no-plusplus': 0,
|
||||
|
||||
// disallow certain syntax forms
|
||||
// http://eslint.org/docs/rules/no-restricted-syntax
|
||||
'no-restricted-syntax': [
|
||||
2,
|
||||
'DebuggerStatement',
|
||||
'ForInStatement',
|
||||
'LabeledStatement',
|
||||
'WithStatement',
|
||||
],
|
||||
|
||||
// disallow space between function identifier and application
|
||||
'no-spaced-func': 2,
|
||||
|
||||
// disallow tab characters entirely
|
||||
// TODO: enable
|
||||
'no-tabs': 0,
|
||||
|
||||
// disallow the use of ternary operators
|
||||
'no-ternary': 0,
|
||||
|
||||
// disallow trailing whitespace at the end of lines
|
||||
'no-trailing-spaces': 2,
|
||||
|
||||
// disallow dangling underscores in identifiers
|
||||
'no-underscore-dangle': [2, { allowAfterThis: false }],
|
||||
|
||||
// disallow the use of Boolean literals in conditional expressions
|
||||
// also, prefer `a || b` over `a ? a : b`
|
||||
// http://eslint.org/docs/rules/no-unneeded-ternary
|
||||
'no-unneeded-ternary': [2, { defaultAssignment: false }],
|
||||
|
||||
// disallow whitespace before properties
|
||||
// http://eslint.org/docs/rules/no-whitespace-before-property
|
||||
'no-whitespace-before-property': 2,
|
||||
|
||||
// require padding inside curly braces
|
||||
'object-curly-spacing': [2, 'always'],
|
||||
|
||||
// enforce line breaks between braces
|
||||
// http://eslint.org/docs/rules/object-curly-newline
|
||||
// TODO: enable once https://github.com/eslint/eslint/issues/6488 is resolved
|
||||
'object-curly-newline': [0, {
|
||||
ObjectExpression: { minProperties: 0, multiline: true },
|
||||
ObjectPattern: { minProperties: 0, multiline: true }
|
||||
}],
|
||||
|
||||
// enforce "same line" or "multiple line" on object properties.
|
||||
// http://eslint.org/docs/rules/object-property-newline
|
||||
'object-property-newline': [2, {
|
||||
allowMultiplePropertiesPerLine: true,
|
||||
}],
|
||||
|
||||
// allow just one var statement per function
|
||||
'one-var': [2, 'never'],
|
||||
|
||||
// require a newline around variable declaration
|
||||
// http://eslint.org/docs/rules/one-var-declaration-per-line
|
||||
'one-var-declaration-per-line': [2, 'always'],
|
||||
|
||||
// require assignment operator shorthand where possible or prohibit it entirely
|
||||
// http://eslint.org/docs/rules/operator-assignment
|
||||
'operator-assignment': [2, 'always'],
|
||||
|
||||
// enforce operators to be placed before or after line breaks
|
||||
'operator-linebreak': 0,
|
||||
|
||||
// enforce padding within blocks
|
||||
'padded-blocks': [2, 'never'],
|
||||
|
||||
// require quotes around object literal property names
|
||||
// http://eslint.org/docs/rules/quote-props.html
|
||||
'quote-props': [2, 'as-needed', { keywords: false, unnecessary: true, numbers: false }],
|
||||
|
||||
// specify whether double or single quotes should be used
|
||||
quotes: [2, 'single', { avoidEscape: true }],
|
||||
|
||||
// do not require jsdoc
|
||||
// http://eslint.org/docs/rules/require-jsdoc
|
||||
'require-jsdoc': 0,
|
||||
|
||||
// require or disallow use of semicolons instead of ASI
|
||||
semi: [2, 'always'],
|
||||
|
||||
// enforce spacing before and after semicolons
|
||||
'semi-spacing': [2, { before: false, after: true }],
|
||||
|
||||
// sort variables within the same declaration block
|
||||
'sort-vars': 0,
|
||||
|
||||
// require or disallow space before blocks
|
||||
'space-before-blocks': 2,
|
||||
|
||||
// require or disallow space before function opening parenthesis
|
||||
// http://eslint.org/docs/rules/space-before-function-paren
|
||||
'space-before-function-paren': [2, { anonymous: 'always', named: 'never' }],
|
||||
|
||||
// require or disallow spaces inside parentheses
|
||||
'space-in-parens': [2, 'never'],
|
||||
|
||||
// require spaces around operators
|
||||
'space-infix-ops': 2,
|
||||
|
||||
// Require or disallow spaces before/after unary operators
|
||||
// http://eslint.org/docs/rules/space-unary-ops
|
||||
'space-unary-ops': [2, {
|
||||
words: true,
|
||||
nonwords: false,
|
||||
overrides: {
|
||||
},
|
||||
}],
|
||||
|
||||
// require or disallow a space immediately following the // or /* in a comment
|
||||
'spaced-comment': [2, 'always', {
|
||||
exceptions: ['-', '+'],
|
||||
markers: ['=', '!'] // space here to support sprockets directives
|
||||
}],
|
||||
|
||||
// require or disallow the Unicode Byte Order Mark
|
||||
// http://eslint.org/docs/rules/unicode-bom
|
||||
'unicode-bom': [2, 'never'],
|
||||
|
||||
// require regex literals to be wrapped in parentheses
|
||||
'wrap-regex': 0
|
||||
}
|
||||
};
|
||||
@@ -1,31 +1,40 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
rules: {
|
||||
// enforce or disallow variable initializations at definition
|
||||
'init-declarations': 0,
|
||||
|
||||
// disallow the catch clause parameter name being the same as a variable in the outer scope
|
||||
'no-catch-shadow': 0,
|
||||
|
||||
// disallow deletion of variables
|
||||
'no-delete-var': 2,
|
||||
// disallow var and named functions in global scope
|
||||
// http://eslint.org/docs/rules/no-implicit-globals
|
||||
'no-implicit-globals': 0,
|
||||
|
||||
// disallow labels that share a name with a variable
|
||||
'no-label-var': 0,
|
||||
// disallow self assignment
|
||||
// http://eslint.org/docs/rules/no-self-assign
|
||||
'no-self-assign': 2,
|
||||
// disallow shadowing of names such as arguments
|
||||
'no-shadow-restricted-names': 2,
|
||||
// http://eslint.org/docs/rules/no-label-var
|
||||
'no-label-var': 2,
|
||||
|
||||
// disallow specific globals
|
||||
'no-restricted-globals': 0,
|
||||
|
||||
// disallow declaration of variables already declared in the outer scope
|
||||
'no-shadow': 2,
|
||||
// disallow use of undefined when initializing variables
|
||||
'no-undef-init': 0,
|
||||
|
||||
// disallow shadowing of names such as arguments
|
||||
'no-shadow-restricted-names': 2,
|
||||
|
||||
// disallow use of undeclared variables unless mentioned in a /*global */ block
|
||||
'no-undef': 2,
|
||||
|
||||
// disallow use of undefined when initializing variables
|
||||
'no-undef-init': 2,
|
||||
|
||||
// disallow use of undefined variable
|
||||
// TODO: enable?
|
||||
'no-undefined': 0,
|
||||
|
||||
// disallow declaration of variables that are not used in the code
|
||||
'no-unused-vars': [2, { 'vars': 'local', 'args': 'after-used' }],
|
||||
'no-unused-vars': [2, { vars: 'local', args: 'after-used' }],
|
||||
|
||||
// disallow use of variables before they are defined
|
||||
'no-use-before-define': 2
|
||||
}
|
||||
12
packages/eslint-config-airbnb-base/test/.eslintrc
Normal file
12
packages/eslint-config-airbnb-base/test/.eslintrc
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"rules": {
|
||||
// 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"]}],
|
||||
"import/no-extraneous-dependencies": [2, {
|
||||
"devDependencies": true
|
||||
}],
|
||||
}
|
||||
}
|
||||
29
packages/eslint-config-airbnb-base/test/test-base.js
Normal file
29
packages/eslint-config-airbnb-base/test/test-base.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import test from 'tape';
|
||||
|
||||
import index from '../';
|
||||
|
||||
const files = { index };
|
||||
|
||||
fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
|
||||
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
|
||||
});
|
||||
|
||||
Object.keys(files).forEach(name => {
|
||||
const config = files[name];
|
||||
|
||||
test(`${name}: does not reference react`, t => {
|
||||
t.plan(2);
|
||||
|
||||
// scan plugins for react and fail if it is found
|
||||
const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') &&
|
||||
config.plugins.indexOf('react') !== -1;
|
||||
t.notOk(hasReactPlugin, 'there is no react plugin');
|
||||
|
||||
// scan rules for react/ and fail if any exist
|
||||
const reactRuleIds = Object.keys(config.rules)
|
||||
.filter(ruleId => ruleId.indexOf('react/') === 0);
|
||||
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
|
||||
});
|
||||
});
|
||||
3
packages/eslint-config-airbnb/.babelrc
Normal file
3
packages/eslint-config-airbnb/.babelrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["airbnb"]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "airbnb",
|
||||
"extends": "./index.js",
|
||||
"rules": {
|
||||
// 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.
|
||||
|
||||
@@ -1,3 +1,46 @@
|
||||
9.0.1 / 2016-05-08
|
||||
==================
|
||||
- [patch] update `eslint-config-airbnb-base` to v3.0.1
|
||||
|
||||
9.0.0 / 2016-05-07
|
||||
==================
|
||||
- [breaking] update `eslint-config-airbnb-base` to v3
|
||||
- [deps] update `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`
|
||||
|
||||
8.0.0 / 2016-04-21
|
||||
==================
|
||||
- [breaking] Migrate non-React rules to a separate linter config (`eslint-config-airbnb-base`)
|
||||
- [breaking] disallow empty methods
|
||||
- [breaking] disallow empty restructuring patterns
|
||||
- [breaking] enable `no-restricted-syntax` rule
|
||||
- [breaking] enable `global-require` rule
|
||||
- [breaking] [react] enable `react/jsx-curly-spacing` rule ([#693](https://github.com/airbnb/javascript/issues/693))
|
||||
- [semver-minor] [react] Add `react/jsx-first-prop-new-line` rule
|
||||
- [semver-minor] [react] enable `jsx-equals-spacing` rule
|
||||
- [semver-minor] [react] enable `jsx-indent` rule
|
||||
- [semver-minor] enforce spacing inside single-line blocks
|
||||
- [semver-minor] enforce `no-underscore-dangle`
|
||||
- [semver-minor] Enable import/no-unresolved and import/export rules ([#825](https://github.com/airbnb/javascript/issues/825))
|
||||
- [semver-patch] Enable `no-useless-concat` rule which `prefer-template` already covers
|
||||
- [semver-patch] Allow `== null` ([#542](https://github.com/airbnb/javascript/issues/542))
|
||||
- [dev deps / peer deps] update `eslint`, `eslint-plugin-react`, `eslint-plugin-import`
|
||||
- [dev deps / peer deps] update `eslint-plugin-jsx-a11y` and rename rules ([#838](https://github.com/airbnb/javascript/issues/838))
|
||||
- [refactor] [react] separate a11y rules to their own file
|
||||
- [refactor] Add missing disabled rules.
|
||||
- [tests] Add `eslint-find-rules` to prevent missing rules
|
||||
|
||||
7.0.0 / 2016-04-11
|
||||
==================
|
||||
- [react] [breaking] Add accessibility rules to the React style guide + `eslint-plugin-a11y`
|
||||
- [breaking] enable `react/require-render-return`
|
||||
- [breaking] Add `no-dupe-class-members` rule + section ([#785](https://github.com/airbnb/javascript/issues/785))
|
||||
- [breaking] error on debugger statements
|
||||
- [breaking] add `no-useless-escape` rule
|
||||
- [breaking] add `no-duplicate-imports` rule
|
||||
- [semver-minor] enable `jsx-pascal-case` rule
|
||||
- [deps] update `eslint`, `react`
|
||||
- [dev deps] update `eslint`, `eslint-plugin-react`
|
||||
|
||||
6.2.0 / 2016-03-22
|
||||
==================
|
||||
- [new] Allow arrow functions in JSX props
|
||||
|
||||
@@ -10,25 +10,30 @@ We export three ESLint configurations for your usage.
|
||||
|
||||
### eslint-config-airbnb
|
||||
|
||||
Our default export contains all of our ESLint rules, including EcmaScript 6+
|
||||
and React. It requires `eslint` and `eslint-plugin-react`.
|
||||
Our default export contains all of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, and `eslint-plugin-jsx-a11y`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-react eslint`
|
||||
2. add `"extends": "airbnb"` to your .eslintrc
|
||||
1. Ensure packages are installed with correct version numbers by running:
|
||||
```sh
|
||||
(
|
||||
export PKG=eslint-config-airbnb;
|
||||
npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG"
|
||||
)
|
||||
```
|
||||
|
||||
Which produces and runs a command like:
|
||||
|
||||
```sh
|
||||
npm install --save-dev eslint-config-airbnb eslint@^2.9.0 eslint-plugin-jsx-a11y@^1.2.0 eslint-plugin-import@^1.7.0 eslint-plugin-react@^5.0.1
|
||||
```
|
||||
|
||||
2. Add `"extends": "airbnb"` to your .eslintrc
|
||||
### eslint-config-airbnb/base
|
||||
|
||||
Lints ES6+ but does not lint React. Requires `eslint`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint`
|
||||
2. add `"extends": "airbnb/base"` to your .eslintrc
|
||||
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
|
||||
### eslint-config-airbnb/legacy
|
||||
|
||||
Lints ES5 and below. Only requires `eslint`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint`
|
||||
2. add `"extends": "airbnb/legacy"` to your .eslintrc
|
||||
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
|
||||
See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and
|
||||
the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files)
|
||||
@@ -36,9 +41,7 @@ for more information.
|
||||
|
||||
## Improving this config
|
||||
|
||||
Consider adding test cases if you're making complicated rules changes, like
|
||||
anything involving regexes. Perhaps in a distant future, we could use literate
|
||||
programming to structure our README as test cases for our .eslintrc?
|
||||
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
|
||||
|
||||
You can run tests with `npm test`.
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint-config-airbnb/legacy',
|
||||
'eslint-config-airbnb/rules/es6',
|
||||
].map(require.resolve),
|
||||
rules: {}
|
||||
extends: ['eslint-config-airbnb-base'].map(require.resolve),
|
||||
rules: {},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint-config-airbnb/base',
|
||||
'eslint-config-airbnb/rules/strict',
|
||||
'eslint-config-airbnb/rules/react',
|
||||
'eslint-config-airbnb-base',
|
||||
'eslint-config-airbnb-base/rules/strict',
|
||||
'./rules/react',
|
||||
'./rules/react-a11y',
|
||||
].map(require.resolve),
|
||||
rules: {}
|
||||
};
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint-config-airbnb/rules/best-practices',
|
||||
'eslint-config-airbnb/rules/errors',
|
||||
'eslint-config-airbnb/rules/legacy',
|
||||
'eslint-config-airbnb/rules/node',
|
||||
'eslint-config-airbnb/rules/style',
|
||||
'eslint-config-airbnb/rules/variables'
|
||||
].map(require.resolve),
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
amd: false,
|
||||
mocha: false,
|
||||
jasmine: false
|
||||
},
|
||||
ecmaFeatures: {},
|
||||
globals: {},
|
||||
rules: {}
|
||||
extends: ['eslint-config-airbnb-base/legacy'].map(require.resolve),
|
||||
rules: {},
|
||||
};
|
||||
|
||||
1
packages/eslint-config-airbnb/node_modules/eslint-config-airbnb
generated
vendored
1
packages/eslint-config-airbnb/node_modules/eslint-config-airbnb
generated
vendored
@@ -1 +0,0 @@
|
||||
..
|
||||
@@ -1,12 +1,15 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb",
|
||||
"version": "6.2.0",
|
||||
"version": "9.0.1",
|
||||
"description": "Airbnb's ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"test": "parallelshell 'npm run lint' 'npm run tests-only'"
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test)",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"travis": "cd ../eslint-config-airbnb-base && npm install && npm link && cd - && npm link eslint-config-airbnb-base && npm run --silent test ; npm unlink eslint-config-airbnb-base >/dev/null &"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -41,16 +44,28 @@
|
||||
"url": "https://github.com/airbnb/javascript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"dependencies": {
|
||||
"eslint-config-airbnb-base": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-tape-runner": "^1.3.1",
|
||||
"eslint": "^2.4.0",
|
||||
"eslint-plugin-react": "^4.2.1",
|
||||
"react": "^0.14.7",
|
||||
"tape": "^4.5.1",
|
||||
"parallelshell": "^2.0.0"
|
||||
"babel-preset-airbnb": "^2.0.0",
|
||||
"babel-tape-runner": "^2.0.1",
|
||||
"eslint": "^3.2.2",
|
||||
"eslint-find-rules": "^1.11.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"eslint-plugin-jsx-a11y": "^2.0.1",
|
||||
"eslint-plugin-react": "^6.0.0",
|
||||
"in-publish": "^2.0.0",
|
||||
"react": ">= 0.13.0",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^2.4.0",
|
||||
"eslint-plugin-react": "^4.2.3"
|
||||
"eslint": "^3.2.2",
|
||||
"eslint-plugin-jsx-a11y": "^2.0.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"eslint-plugin-react": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"quote-props": 0
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
// disallow trailing commas in object literals
|
||||
'comma-dangle': [2, 'never'],
|
||||
// specify the maximum depth that blocks can be nested
|
||||
'max-depth': [0, 4],
|
||||
// limits the number of parameters that can be used in the function declaration.
|
||||
'max-params': [0, 3],
|
||||
// specify the maximum number of statement allowed in a function
|
||||
'max-statements': [0, 10],
|
||||
// disallow use of bitwise operators
|
||||
'no-bitwise': 0,
|
||||
// disallow use of unary operators, ++ and --
|
||||
'no-plusplus': 0
|
||||
}
|
||||
};
|
||||
100
packages/eslint-config-airbnb/rules/react-a11y.js
vendored
Normal file
100
packages/eslint-config-airbnb/rules/react-a11y.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
module.exports = {
|
||||
plugins: [
|
||||
'jsx-a11y',
|
||||
'react'
|
||||
],
|
||||
ecmaFeatures: {
|
||||
jsx: true
|
||||
},
|
||||
rules: {
|
||||
// Require ARIA roles to be valid and non-abstract
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md
|
||||
'jsx-a11y/aria-role': 2,
|
||||
|
||||
// Enforce all aria-* props are valid.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-props.md
|
||||
'jsx-a11y/aria-props': 2,
|
||||
|
||||
// Enforce ARIA state and property values are valid.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-proptypes.md
|
||||
'jsx-a11y/aria-proptypes': 2,
|
||||
|
||||
// Enforce that elements that do not support ARIA roles, states, and
|
||||
// properties do not have those attributes.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-unsupported-elements.md
|
||||
'jsx-a11y/aria-unsupported-elements': 2,
|
||||
|
||||
// disallow href "#"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/href-no-hash.md
|
||||
'jsx-a11y/href-no-hash': [2, ['a']],
|
||||
|
||||
// Require <img> to have a non-empty `alt` prop, or role="presentation"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-has-alt.md
|
||||
'jsx-a11y/img-has-alt': 2,
|
||||
|
||||
// Prevent img alt text from containing redundant words like "image", "picture", or "photo"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md
|
||||
'jsx-a11y/img-redundant-alt': 2,
|
||||
|
||||
// require that JSX labels use "htmlFor"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
|
||||
'jsx-a11y/label-has-for': [2, ['label']],
|
||||
|
||||
// require that mouseover/out come with focus/blur, for keyboard-only users
|
||||
// TODO: evaluate
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md
|
||||
'jsx-a11y/mouse-events-have-key-events': 0,
|
||||
|
||||
// Prevent use of `accessKey`
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md
|
||||
'jsx-a11y/no-access-key': 2,
|
||||
|
||||
// require onBlur instead of onChange
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md
|
||||
'jsx-a11y/no-onchange': 0,
|
||||
|
||||
// Enforce that elements with onClick handlers must be focusable.
|
||||
// TODO: evaluate
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-focus.md
|
||||
'jsx-a11y/onclick-has-focus': 0,
|
||||
|
||||
// require things with onClick to have an aria role
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/onclick-has-role.md
|
||||
'jsx-a11y/onclick-has-role': 0,
|
||||
|
||||
// Enforce that elements with ARIA roles must have all required attributes
|
||||
// for that role.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-has-required-aria-props.md
|
||||
'jsx-a11y/role-has-required-aria-props': 2,
|
||||
|
||||
// Enforce that elements with explicit or implicit roles defined contain
|
||||
// only aria-* properties supported by that role.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-supports-aria-props.md
|
||||
'jsx-a11y/role-supports-aria-props': 2,
|
||||
|
||||
// Enforce tabIndex value is not greater than zero.
|
||||
// TODO: evaluate
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md
|
||||
'jsx-a11y/tabindex-no-positive': 0,
|
||||
|
||||
// ensure <hX> tags have content and are not aria-hidden
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/heading-has-content.md
|
||||
'jsx-a11y/heading-has-content': [2, ['']],
|
||||
|
||||
// require HTML elements to have a "lang" prop
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/html-has-lang.md
|
||||
'jsx-a11y/html-has-lang': 2,
|
||||
|
||||
// require HTML element's lang prop to be valid
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/lang.md
|
||||
'jsx-a11y/lang': 2,
|
||||
|
||||
// prevent marquee elements
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-marquee.md
|
||||
'jsx-a11y/no-marquee': 2,
|
||||
|
||||
// only allow <th> to have the "scope" attr
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/scope.md
|
||||
'jsx-a11y/scope': 2,
|
||||
},
|
||||
};
|
||||
173
packages/eslint-config-airbnb/rules/react.js
vendored
173
packages/eslint-config-airbnb/rules/react.js
vendored
@@ -1,135 +1,193 @@
|
||||
module.exports = {
|
||||
'plugins': [
|
||||
plugins: [
|
||||
'react'
|
||||
],
|
||||
'ecmaFeatures': {
|
||||
'jsx': true
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
ecmaFeatures: {
|
||||
jsx: true
|
||||
},
|
||||
|
||||
// View link below for react rules documentation
|
||||
// https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
|
||||
'rules': {
|
||||
rules: {
|
||||
// Specify whether double or single quotes should be used in JSX attributes
|
||||
// http://eslint.org/docs/rules/jsx-quotes
|
||||
'jsx-quotes': [2, 'prefer-double'],
|
||||
|
||||
// Prevent missing displayName in a React component definition
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
|
||||
'react/display-name': [0, { 'ignoreTranspilerName': false }],
|
||||
'react/display-name': [0, { ignoreTranspilerName: false }],
|
||||
|
||||
// Forbid certain propTypes (any, array, object)
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
|
||||
'react/forbid-prop-types': [0, { 'forbid': ['any', 'array', 'object'] }],
|
||||
'react/forbid-prop-types': [0, { forbid: ['any', 'array', 'object'] }],
|
||||
|
||||
// Enforce boolean attributes notation in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
|
||||
'react/jsx-boolean-value': [2, 'never'],
|
||||
|
||||
// Validate closing bracket location in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
|
||||
'react/jsx-closing-bracket-location': [2, 'line-aligned'],
|
||||
|
||||
// Enforce or disallow spaces inside of curly braces in JSX attributes
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
|
||||
'react/jsx-curly-spacing': [0, 'never', { 'allowMultiline': true }],
|
||||
'react/jsx-curly-spacing': [2, 'never', { allowMultiline: true }],
|
||||
|
||||
// Enforce event handler naming conventions in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
|
||||
'react/jsx-handler-names': [0, {
|
||||
'eventHandlerPrefix': 'handle',
|
||||
'eventHandlerPropPrefix': 'on',
|
||||
eventHandlerPrefix: 'handle',
|
||||
eventHandlerPropPrefix: 'on',
|
||||
}],
|
||||
|
||||
// Validate props indentation in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
|
||||
'react/jsx-indent-props': [2, 2],
|
||||
|
||||
// Validate JSX has key prop when in array or iterator
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
|
||||
'react/jsx-key': 0,
|
||||
|
||||
// Limit maximum of props on a single line in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
|
||||
'react/jsx-max-props-per-line': [0, { 'maximum': 1 }],
|
||||
// Prevent usage of .bind() and arrow functions in JSX props
|
||||
'react/jsx-max-props-per-line': [0, { maximum: 1 }],
|
||||
|
||||
// Prevent usage of .bind() in JSX props
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
|
||||
'react/jsx-no-bind': [2, {
|
||||
'ignoreRefs': true,
|
||||
'allowArrowFunctions': true,
|
||||
'allowBind': false,
|
||||
ignoreRefs: true,
|
||||
allowArrowFunctions: true,
|
||||
allowBind: false,
|
||||
}],
|
||||
|
||||
// Prevent duplicate props in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
|
||||
'react/jsx-no-duplicate-props': [0, { 'ignoreCase': false }],
|
||||
'react/jsx-no-duplicate-props': [0, { ignoreCase: false }],
|
||||
|
||||
// Prevent usage of unwrapped JSX strings
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
|
||||
'react/jsx-no-literals': 0,
|
||||
|
||||
// Disallow undeclared variables in JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
|
||||
'react/jsx-no-undef': 2,
|
||||
|
||||
// Enforce PascalCase for user-defined JSX components
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
|
||||
'react/jsx-pascal-case': 0,
|
||||
'react/jsx-pascal-case': [2, {
|
||||
allowAllCaps: true,
|
||||
ignore: [],
|
||||
}],
|
||||
|
||||
// Enforce propTypes declarations alphabetical sorting
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
|
||||
'react/sort-prop-types': [0, {
|
||||
'ignoreCase': false,
|
||||
'callbacksLast': false,
|
||||
ignoreCase: false,
|
||||
callbacksLast: false,
|
||||
requiredFirst: false,
|
||||
}],
|
||||
|
||||
// Deprecated in favor of react/jsx-sort-props
|
||||
'react/jsx-sort-prop-types': 0,
|
||||
|
||||
// Enforce props alphabetical sorting
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
|
||||
'react/jsx-sort-props': [0, {
|
||||
'ignoreCase': false,
|
||||
'callbacksLast': false,
|
||||
ignoreCase: false,
|
||||
callbacksLast: false,
|
||||
shorthandFirst: false,
|
||||
shorthandLast: false,
|
||||
}],
|
||||
|
||||
// Prevent React to be incorrectly marked as unused
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
|
||||
'react/jsx-uses-react': [2, { 'pragma': 'React' }],
|
||||
'react/jsx-uses-react': [2],
|
||||
|
||||
// Prevent variables used in JSX to be incorrectly marked as unused
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
|
||||
'react/jsx-uses-vars': 2,
|
||||
|
||||
// Prevent usage of dangerous JSX properties
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
|
||||
'react/no-danger': 0,
|
||||
|
||||
// Prevent usage of deprecated methods
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
|
||||
'react/no-deprecated': [1, { 'react': '0.14.0' }],
|
||||
'react/no-deprecated': [2],
|
||||
|
||||
// Prevent usage of setState in componentDidMount
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
|
||||
'react/no-did-mount-set-state': [2, 'allow-in-func'],
|
||||
'react/no-did-mount-set-state': [2],
|
||||
|
||||
// Prevent usage of setState in componentDidUpdate
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
|
||||
'react/no-did-update-set-state': [2, 'allow-in-func'],
|
||||
'react/no-did-update-set-state': [2],
|
||||
|
||||
// Prevent direct mutation of this.state
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
|
||||
'react/no-direct-mutation-state': 0,
|
||||
|
||||
// Prevent usage of isMounted
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
|
||||
'react/no-is-mounted': 2,
|
||||
|
||||
// Prevent multiple component definition per file
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
|
||||
'react/no-multi-comp': [2, { 'ignoreStateless': true }],
|
||||
'react/no-multi-comp': [2, { ignoreStateless: true }],
|
||||
|
||||
// Prevent usage of setState
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
|
||||
'react/no-set-state': 0,
|
||||
|
||||
// Prevent using string references
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
|
||||
'react/no-string-refs': 0,
|
||||
'react/no-string-refs': 2,
|
||||
|
||||
// Prevent usage of unknown DOM property
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
|
||||
'react/no-unknown-property': 2,
|
||||
|
||||
// Require ES6 class declarations over React.createClass
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
|
||||
'react/prefer-es6-class': [2, 'always'],
|
||||
|
||||
// Require stateless functions when not using lifecycle methods, setState or ref
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
|
||||
'react/prefer-stateless-function': 2,
|
||||
|
||||
// Prevent missing props validation in a React component definition
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
|
||||
'react/prop-types': [2, { 'ignore': [], 'customValidators': [] }],
|
||||
'react/prop-types': [2, { ignore: [], customValidators: [] }],
|
||||
|
||||
// Prevent missing React when using JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
|
||||
'react/react-in-jsx-scope': 2,
|
||||
|
||||
// Restrict file extensions that may be required
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-extension.md
|
||||
'react/require-extension': [0, { 'extensions': ['.jsx'] }],
|
||||
'react/require-extension': [2, { extensions: ['.jsx', '.js'] }],
|
||||
|
||||
// Require render() methods to return something
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
|
||||
'react/require-render-return': 2,
|
||||
|
||||
// Prevent extra closing tags for components without children
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
|
||||
'react/self-closing-comp': 2,
|
||||
|
||||
// Enforce spaces before the closing bracket of self-closing JSX elements
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
|
||||
'react/jsx-space-before-closing': [2, 'always'],
|
||||
|
||||
// Enforce component methods order
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
|
||||
'react/sort-comp': [2, {
|
||||
'order': [
|
||||
order: [
|
||||
'static-methods',
|
||||
'lifecycle',
|
||||
'/^on.+$/',
|
||||
@@ -137,14 +195,65 @@ module.exports = {
|
||||
'everything-else',
|
||||
'/^render.+$/',
|
||||
'render'
|
||||
]
|
||||
],
|
||||
}],
|
||||
|
||||
// Prevent missing parentheses around multilines JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
|
||||
'react/wrap-multilines': [2, {
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
|
||||
'react/jsx-wrap-multilines': [2, {
|
||||
declaration: true,
|
||||
assignment: true,
|
||||
return: true
|
||||
}],
|
||||
'react/wrap-multilines': 0, // deprecated version
|
||||
|
||||
// Require that the first prop in a JSX element be on a new line when the element is multiline
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
|
||||
'react/jsx-first-prop-new-line': [2, 'multiline'],
|
||||
|
||||
// Enforce spacing around jsx equals signs
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
|
||||
'react/jsx-equals-spacing': [2, 'never'],
|
||||
|
||||
// Enforce JSX indentation
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
|
||||
'react/jsx-indent': [2, 2],
|
||||
|
||||
// Disallow target="_blank" on links
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
|
||||
'react/jsx-no-target-blank': 2,
|
||||
|
||||
// only .jsx files may have JSX
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
|
||||
'react/jsx-filename-extension': [2, { extensions: ['.jsx'] }],
|
||||
|
||||
// prevent accidental JS comments from being injected into JSX as text
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
|
||||
'react/jsx-no-comment-textnodes': 2,
|
||||
'react/no-comment-textnodes': 0, // deprecated version
|
||||
|
||||
// disallow using React.render/ReactDOM.render's return value
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
|
||||
'react/no-render-return-value': 2,
|
||||
|
||||
// require a shouldComponentUpdate method, or PureRenderMixin
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-optimization.md
|
||||
'react/require-optimization': [0, { allowDecorators: [] }],
|
||||
|
||||
// warn against using findDOMNode()
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md
|
||||
'react/no-find-dom-node': 2,
|
||||
},
|
||||
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
node: {
|
||||
extensions: ['.js', '.jsx', '.json']
|
||||
}
|
||||
},
|
||||
react: {
|
||||
pragma: 'React',
|
||||
version: '0.14'
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
module.exports = {
|
||||
'rules': {
|
||||
// enforce spacing inside array brackets
|
||||
'array-bracket-spacing': [2, 'never'],
|
||||
// enforce one true brace style
|
||||
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],
|
||||
// require camel case names
|
||||
'camelcase': [2, { 'properties': 'never' }],
|
||||
// enforce spacing before and after comma
|
||||
'comma-spacing': [2, { 'before': false, 'after': true }],
|
||||
// enforce one true comma style
|
||||
'comma-style': [2, 'last'],
|
||||
// disallow padding inside computed properties
|
||||
'computed-property-spacing': [2, 'never'],
|
||||
// enforces consistent naming when capturing the current execution context
|
||||
'consistent-this': 0,
|
||||
// enforce newline at the end of file, with no multiple empty lines
|
||||
'eol-last': 2,
|
||||
// require function expressions to have a name
|
||||
'func-names': 1,
|
||||
// enforces use of function declarations or expressions
|
||||
'func-style': 0,
|
||||
// this option enforces minimum and maximum identifier lengths
|
||||
// (variable names, property names etc.)
|
||||
'id-length': 0,
|
||||
// this option sets a specific tab width for your code
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/indent.md
|
||||
'indent': [2, 2, { 'SwitchCase': 1, 'VariableDeclarator': 1 }],
|
||||
// specify whether double or single quotes should be used in JSX attributes
|
||||
// http://eslint.org/docs/rules/jsx-quotes
|
||||
'jsx-quotes': [2, 'prefer-double'],
|
||||
// enforces spacing between keys and values in object literal properties
|
||||
'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }],
|
||||
// require a space before & after certain keywords
|
||||
'keyword-spacing': [2, {
|
||||
'before': true,
|
||||
'after': true,
|
||||
'overrides': {
|
||||
'return': { 'after': true },
|
||||
'throw': { 'after': true },
|
||||
'case': { 'after': true }
|
||||
}
|
||||
}],
|
||||
// enforces empty lines around comments
|
||||
'lines-around-comment': 0,
|
||||
// disallow mixed 'LF' and 'CRLF' as linebreaks
|
||||
'linebreak-style': 0,
|
||||
// specify the maximum length of a line in your program
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/max-len.md
|
||||
'max-len': [2, 100, 2, {
|
||||
'ignoreUrls': true,
|
||||
'ignoreComments': false
|
||||
}],
|
||||
// specify the maximum depth callbacks can be nested
|
||||
'max-nested-callbacks': 0,
|
||||
// require a capital letter for constructors
|
||||
'new-cap': [2, { 'newIsCap': true }],
|
||||
// disallow the omission of parentheses when invoking a constructor with no arguments
|
||||
'new-parens': 0,
|
||||
// allow/disallow an empty newline after var statement
|
||||
'newline-after-var': 0,
|
||||
// http://eslint.org/docs/rules/newline-before-return
|
||||
'newline-before-return': 0,
|
||||
// enforces new line after each method call in the chain to make it
|
||||
// more readable and easy to maintain
|
||||
// http://eslint.org/docs/rules/newline-per-chained-call
|
||||
'newline-per-chained-call': [0, { 'ignoreChainWithDepth': 3 }],
|
||||
// disallow use of the Array constructor
|
||||
'no-array-constructor': 2,
|
||||
// disallow use of the continue statement
|
||||
'no-continue': 0,
|
||||
// disallow comments inline after code
|
||||
'no-inline-comments': 0,
|
||||
// disallow if as the only statement in an else block
|
||||
'no-lonely-if': 0,
|
||||
// disallow mixed spaces and tabs for indentation
|
||||
'no-mixed-spaces-and-tabs': 2,
|
||||
// disallow multiple empty lines and only one newline at the end
|
||||
'no-multiple-empty-lines': [2, { 'max': 2, 'maxEOF': 1 }],
|
||||
// disallow nested ternary expressions
|
||||
'no-nested-ternary': 2,
|
||||
// disallow use of the Object constructor
|
||||
'no-new-object': 2,
|
||||
// disallow space between function identifier and application
|
||||
'no-spaced-func': 2,
|
||||
// disallow the use of ternary operators
|
||||
'no-ternary': 0,
|
||||
// disallow trailing whitespace at the end of lines
|
||||
'no-trailing-spaces': 2,
|
||||
// disallow dangling underscores in identifiers
|
||||
'no-underscore-dangle': 0,
|
||||
// disallow the use of Boolean literals in conditional expressions
|
||||
// also, prefer `a || b` over `a ? a : b`
|
||||
// http://eslint.org/docs/rules/no-unneeded-ternary
|
||||
'no-unneeded-ternary': [2, { 'defaultAssignment': false }],
|
||||
// disallow whitespace before properties
|
||||
// http://eslint.org/docs/rules/no-whitespace-before-property
|
||||
'no-whitespace-before-property': 2,
|
||||
// require padding inside curly braces
|
||||
'object-curly-spacing': [2, 'always'],
|
||||
// allow just one var statement per function
|
||||
'one-var': [2, 'never'],
|
||||
// require a newline around variable declaration
|
||||
// http://eslint.org/docs/rules/one-var-declaration-per-line
|
||||
'one-var-declaration-per-line': [2, 'always'],
|
||||
// require assignment operator shorthand where possible or prohibit it entirely
|
||||
'operator-assignment': 0,
|
||||
// enforce operators to be placed before or after line breaks
|
||||
'operator-linebreak': 0,
|
||||
// enforce padding within blocks
|
||||
'padded-blocks': [2, 'never'],
|
||||
// require quotes around object literal property names
|
||||
// http://eslint.org/docs/rules/quote-props.html
|
||||
'quote-props': [2, 'as-needed', { 'keywords': false, 'unnecessary': true, 'numbers': false }],
|
||||
// specify whether double or single quotes should be used
|
||||
'quotes': [2, 'single', 'avoid-escape'],
|
||||
// require identifiers to match the provided regular expression
|
||||
'id-match': 0,
|
||||
// enforce spacing before and after semicolons
|
||||
'semi-spacing': [2, { 'before': false, 'after': true }],
|
||||
// require or disallow use of semicolons instead of ASI
|
||||
'semi': [2, 'always'],
|
||||
// sort variables within the same declaration block
|
||||
'sort-vars': 0,
|
||||
// require or disallow space before blocks
|
||||
'space-before-blocks': 2,
|
||||
// require or disallow space before function opening parenthesis
|
||||
// https://github.com/eslint/eslint/blob/master/docs/rules/space-before-function-paren.md
|
||||
'space-before-function-paren': [2, { 'anonymous': 'always', 'named': 'never' }],
|
||||
// require or disallow spaces inside parentheses
|
||||
'space-in-parens': [2, 'never'],
|
||||
// require spaces around operators
|
||||
'space-infix-ops': 2,
|
||||
// Require or disallow spaces before/after unary operators
|
||||
'space-unary-ops': 0,
|
||||
// require or disallow a space immediately following the // or /* in a comment
|
||||
'spaced-comment': [2, 'always', {
|
||||
'exceptions': ['-', '+'],
|
||||
'markers': ['=', '!'] // space here to support sprockets directives
|
||||
}],
|
||||
// require regex literals to be wrapped in parentheses
|
||||
'wrap-regex': 0
|
||||
}
|
||||
};
|
||||
@@ -3,7 +3,11 @@
|
||||
// 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"]}]
|
||||
"id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}],
|
||||
|
||||
// tests can import things in devDependencies
|
||||
"import/no-extraneous-dependencies": [2, {"devDependencies": true}]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import test from 'tape';
|
||||
|
||||
const files = {
|
||||
base: require('../base')
|
||||
};
|
||||
const base = require('../base');
|
||||
|
||||
const files = { base };
|
||||
|
||||
fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
|
||||
if (name === 'react.js') {
|
||||
if (name === 'react.js' || name === 'react-a11y.js') {
|
||||
return;
|
||||
}
|
||||
|
||||
files[name] = require(`../rules/${name}`);
|
||||
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
|
||||
});
|
||||
|
||||
Object.keys(files).forEach(name => {
|
||||
@@ -20,7 +20,10 @@ Object.keys(files).forEach(name => {
|
||||
test(`${name}: does not reference react`, t => {
|
||||
t.plan(2);
|
||||
|
||||
t.notOk(config.plugins, 'plugins is unspecified');
|
||||
// scan plugins for react and fail if it is found
|
||||
const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') &&
|
||||
config.plugins.indexOf('react') !== -1;
|
||||
t.notOk(hasReactPlugin, 'there is no react plugin');
|
||||
|
||||
// scan rules for react/ and fail if any exist
|
||||
const reactRuleIds = Object.keys(config.rules)
|
||||
|
||||
@@ -2,13 +2,16 @@ import test from 'tape';
|
||||
import { CLIEngine } from 'eslint';
|
||||
import eslintrc from '../';
|
||||
import reactRules from '../rules/react';
|
||||
import reactA11yRules from '../rules/react-a11y';
|
||||
|
||||
const cli = new CLIEngine({
|
||||
useEslintrc: false,
|
||||
baseConfig: eslintrc,
|
||||
|
||||
// This rule fails when executing on text.
|
||||
rules: { indent: 0 },
|
||||
rules: {
|
||||
// It is okay to import devDependencies in tests.
|
||||
'import/no-extraneous-dependencies': [2, { devDependencies: true }],
|
||||
},
|
||||
});
|
||||
|
||||
function lint(text) {
|
||||
@@ -21,19 +24,22 @@ function lint(text) {
|
||||
function wrapComponent(body) {
|
||||
return `
|
||||
import React from 'react';
|
||||
|
||||
export default class MyComponent extends React.Component {
|
||||
/* eslint no-empty-function: 0 */
|
||||
${body}
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
test('validate react prop order', t => {
|
||||
t.test('make sure our eslintrc has React linting dependencies', t => {
|
||||
t.plan(1);
|
||||
t.equal(reactRules.plugins[0], 'react', 'uses eslint-plugin-react');
|
||||
test('validate react prop order', (t) => {
|
||||
t.test('make sure our eslintrc has React and JSX linting dependencies', (t) => {
|
||||
t.plan(2);
|
||||
t.deepEqual(reactRules.plugins, ['react']);
|
||||
t.deepEqual(reactA11yRules.plugins, ['jsx-a11y', 'react']);
|
||||
});
|
||||
|
||||
t.test('passes a good component', t => {
|
||||
t.test('passes a good component', (t) => {
|
||||
t.plan(3);
|
||||
const result = lint(wrapComponent(`
|
||||
componentWillMount() {}
|
||||
|
||||
187
react/README.md
187
react/README.md
@@ -12,6 +12,7 @@
|
||||
1. [Quotes](#quotes)
|
||||
1. [Spacing](#spacing)
|
||||
1. [Props](#props)
|
||||
1. [Refs](#refs)
|
||||
1. [Parentheses](#parentheses)
|
||||
1. [Tags](#tags)
|
||||
1. [Methods](#methods)
|
||||
@@ -29,7 +30,7 @@
|
||||
|
||||
- If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass` unless you have a very good reason to use mixins. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
const Listing = React.createClass({
|
||||
// ...
|
||||
@@ -49,8 +50,7 @@
|
||||
|
||||
And if you don't have state or refs, prefer normal functions (not arrow functions) over classes:
|
||||
|
||||
```javascript
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
class Listing extends React.Component {
|
||||
render() {
|
||||
@@ -58,7 +58,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// bad (since arrow functions do not have a "name" property)
|
||||
// bad (relying on function name inference is discouraged)
|
||||
const Listing = ({ hello }) => (
|
||||
<div>{hello}</div>
|
||||
);
|
||||
@@ -75,7 +75,7 @@
|
||||
- **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
|
||||
- **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
import reservationCard from './ReservationCard';
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
|
||||
- **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name:
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
import Footer from './Footer/Footer';
|
||||
|
||||
@@ -101,12 +101,37 @@
|
||||
// good
|
||||
import Footer from './Footer';
|
||||
```
|
||||
- **Higher-order Component Naming**: Use a composite of the higher-order component's name and the passed-in component's name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`.
|
||||
|
||||
> Why? A component's `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening.
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
export default function withFoo(WrappedComponent) {
|
||||
return function WithFoo(props) {
|
||||
return <WrappedComponent {...props} foo />;
|
||||
}
|
||||
}
|
||||
|
||||
// good
|
||||
export default function withFoo(WrappedComponent) {
|
||||
function WithFoo(props) {
|
||||
return <WrappedComponent {...props} foo />;
|
||||
}
|
||||
|
||||
const wrappedComponentName = WrappedComponent.displayName
|
||||
|| WrappedComponent.name
|
||||
|| 'Component';
|
||||
|
||||
WithFoo.displayName = `withFoo(${wrappedComponentName})`;
|
||||
return WithFoo;
|
||||
}
|
||||
```
|
||||
## Declaration
|
||||
|
||||
- Do not use `displayName` for naming components. Instead, name the component by reference.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
export default React.createClass({
|
||||
displayName: 'ReservationCard',
|
||||
@@ -122,7 +147,7 @@
|
||||
|
||||
- Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo superLongParam="bar"
|
||||
anotherSuperLongParam="baz" />
|
||||
@@ -149,10 +174,10 @@
|
||||
|
||||
- Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS. eslint: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes)
|
||||
|
||||
> Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type.
|
||||
> Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make contractions like `"don't"` easier to type.
|
||||
> Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo bar='bar' />
|
||||
|
||||
@@ -170,7 +195,7 @@
|
||||
|
||||
- Always include a single space in your self-closing tag.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo/>
|
||||
|
||||
@@ -185,11 +210,21 @@
|
||||
<Foo />
|
||||
```
|
||||
|
||||
- Do not pad JSX curly braces with spaces. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md)
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
<Foo bar={ baz } />
|
||||
|
||||
// good
|
||||
<Foo bar={baz} />
|
||||
```
|
||||
|
||||
## Props
|
||||
|
||||
- Always use camelCase for prop names.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo
|
||||
UserName="hello"
|
||||
@@ -205,7 +240,7 @@
|
||||
|
||||
- Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo
|
||||
hidden={true}
|
||||
@@ -217,11 +252,100 @@
|
||||
/>
|
||||
```
|
||||
|
||||
- Always include an `alt` prop on `<img>` tags. If the image is presentational, `alt` can be an empty string or the `<img>` must have `role="presentation"`. eslint: [`jsx-a11y/img-has-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-has-alt.md)
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
<img src="hello.jpg" />
|
||||
|
||||
// good
|
||||
<img src="hello.jpg" alt="Me waving hello" />
|
||||
|
||||
// good
|
||||
<img src="hello.jpg" alt="" />
|
||||
|
||||
// good
|
||||
<img src="hello.jpg" role="presentation" />
|
||||
```
|
||||
|
||||
- Do not use words like "image", "photo", or "picture" in `<img>` `alt` props. eslint: [`jsx-a11y/img-redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md)
|
||||
|
||||
> Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text.
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
<img src="hello.jpg" alt="Picture of me waving hello" />
|
||||
|
||||
// good
|
||||
<img src="hello.jpg" alt="Me waving hello" />
|
||||
```
|
||||
|
||||
- Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/roles#role_definitions). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md)
|
||||
|
||||
```jsx
|
||||
// bad - not an ARIA role
|
||||
<div role="datepicker" />
|
||||
|
||||
// bad - abstract ARIA role
|
||||
<div role="range" />
|
||||
|
||||
// good
|
||||
<div role="button" />
|
||||
```
|
||||
|
||||
- Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md)
|
||||
|
||||
> Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility.
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
<div accessKey="h" />
|
||||
|
||||
// good
|
||||
<div />
|
||||
```
|
||||
|
||||
- Avoid using an array index as `key` prop, prefer a unique ID. ([why?](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318))
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
{todos.map((todo, index) =>
|
||||
<Todo
|
||||
{...todo}
|
||||
key={index}
|
||||
/>
|
||||
)}
|
||||
|
||||
// good
|
||||
{todos.map(todo => (
|
||||
<Todo
|
||||
{...todo}
|
||||
key={todo.id}
|
||||
/>
|
||||
))}
|
||||
```
|
||||
|
||||
## Refs
|
||||
|
||||
- Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
<Foo
|
||||
ref="myRef"
|
||||
/>
|
||||
|
||||
// good
|
||||
<Foo
|
||||
ref={(ref) => this.myRef = ref}
|
||||
/>
|
||||
```
|
||||
|
||||
## Parentheses
|
||||
|
||||
- Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
render() {
|
||||
return <MyComponent className="long body" foo="bar">
|
||||
@@ -249,7 +373,7 @@
|
||||
|
||||
- Always self-close tags that have no children. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo className="stuff"></Foo>
|
||||
|
||||
@@ -259,7 +383,7 @@
|
||||
|
||||
- If your component has multi-line properties, close its tag on a new line. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
<Foo
|
||||
bar="bar"
|
||||
@@ -276,7 +400,7 @@
|
||||
|
||||
- Use arrow functions to close over local variables.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
function ItemList(props) {
|
||||
return (
|
||||
<ul>
|
||||
@@ -295,7 +419,7 @@
|
||||
|
||||
> Why? A bind call in the render path creates a brand new function on every single render.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
class extends React.Component {
|
||||
onClickDiv() {
|
||||
@@ -327,7 +451,7 @@
|
||||
|
||||
- Do not use underscore prefix for internal methods of a React component.
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
// bad
|
||||
React.createClass({
|
||||
_onClickSubmit() {
|
||||
@@ -347,6 +471,20 @@
|
||||
}
|
||||
```
|
||||
|
||||
- Be sure to return a value in your `render` methods. eslint: [`require-render-return`](https://github.com/yannickcr/eslint-plugin-react/pull/502)
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
render() {
|
||||
(<div />);
|
||||
}
|
||||
|
||||
// good
|
||||
render() {
|
||||
return (<div />);
|
||||
}
|
||||
```
|
||||
|
||||
## Ordering
|
||||
|
||||
- Ordering for `class extends React.Component`:
|
||||
@@ -368,7 +506,7 @@
|
||||
|
||||
- How to define `propTypes`, `defaultProps`, `contextTypes`, etc...
|
||||
|
||||
```javascript
|
||||
```jsx
|
||||
import React, { PropTypes } from 'react';
|
||||
|
||||
const propTypes = {
|
||||
@@ -429,4 +567,13 @@
|
||||
|
||||
[anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html
|
||||
|
||||
## Translation
|
||||
|
||||
This JSX/React style guide is also available in other languages:
|
||||
|
||||
-  **Chinese (Simplified)**: [JasonBoy/javascript](https://github.com/JasonBoy/javascript/tree/master/react)
|
||||
-  **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
|
||||
-  **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
|
||||
-  **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
Reference in New Issue
Block a user