Compare commits

...

41 Commits

Author SHA1 Message Date
Jordan Harband
b4d8543f12 [eslint config] [react] [breaking] enable jsx-a11y rules:
- `jsx-a11y/heading-has-content`
 - `jsx-a11y/html-has-lang`
 - `jsx-a11y/lang`
 - `jsx-a11y/no-marquee`
 - `jsx-a11y/scope`
 - `jsx-a11y/href-no-hash`
 - `jsx-a11y/label-has-for`
2016-07-05 13:38:57 -07:00
Jordan Harband
a6da4bb5b2 [eslint config] [react] [breaking] enable aria rules:
- `jsx-a11y/aria-props`
 - `jsx-a11y/aria-proptypes`
 - `jsx-a11y/aria-unsupported-elements`
 - `jsx-a11y/role-has-required-aria-props`
 - `jsx-a11y/role-supports-aria-props`
2016-07-05 13:36:21 -07:00
Jordan Harband
6857f7af97 [eslint config] [react] [breaking] enable react rules:
- `react/jsx-filename-extension`
 - `react/jsx-no-comment-textnodes`
 - `react/jsx-no-target-blank`
 - `react/require-extension`
 - `react/no-render-return-value`
 - `react/no-find-dom-node`
 - `react/no-deprecated`
2016-07-05 13:20:39 -07:00
Jordan Harband
cb36ed90c3 [eslint config] [deps] [breaking] update eslint to v3, eslint-config-airbnb-base to v5, eslint-find-rules, eslint-plugin-import, eslint-plugin-jsx-a11y to v2, eslint-plugin-react to v6, tape.
- drop node < 4 support
2016-07-05 13:15:51 -07:00
Zane Mountcastle
75c961a43f Change 'Brazilian' to 'Portuguese' 2016-08-01 10:41:15 +08:00
Jordan Harband
a533e2dd35 [eslint config] [base] v5.0.1 2016-07-29 17:32:24 -07:00
Jordan Harband
4425d3c76b [eslint config] [base] [deps] update eslint to v3.2 2016-07-29 16:29:00 -07:00
Jordan Harband
49dfcc42de [eslint config] [*] improve prepublish script 2016-07-29 16:29:50 -07:00
Jordan Harband
b2ea03ef2c [eslint config] [base] [deps] update eslint-plugin-import 2016-07-29 08:14:10 -07:00
Joe Lencioni
4dbb2af7da Improve React HOC example
I decided that `WrappedComponent` is clearer than `Component` here, so I
made the switch. I also realized that `WrappedComponent.name` might
still be undefined, so I added a fallback value of "Component".
2016-07-27 09:54:00 -07:00
Joe Lencioni
1917968acb Add missing closing paren in HOC guideline
As pointed out by eagle-eyed @pepakriz.
2016-07-27 09:53:42 -07:00
James Glover
0165c13845 [eslint config] [*] [docs] Added subshell to usage commands and converted samples to the three backtick markdown syntax with language specifier for highlighting. 2016-07-27 20:18:11 +10:00
Joe Lencioni
4c8f78921f Add guideline for displayName in higher-order components
This guideline will help us keep our higher-order components consistent
and easy to understand.

Fixes #968.
2016-07-26 16:51:08 -07:00
Jordan Harband
eea5f0f5f5 [eslint config] [base] no-unused-expressions: flesh out options
Fixes #963.
2016-07-25 12:39:31 -07:00
Jordan Harband
1fb300c6c7 [eslint config] [base] v5.0.0 2016-07-24 09:55:44 -07:00
Jordan Harband
616233c8b2 [eslint config] [base] [breaking] enable no-unexpected-multiline rule 2016-07-24 09:51:50 -07:00
Jordan Harband
bbfb9600dc [eslint config] [*] [deps] update babel-tape-runner, add babel-preset-airbnb 2016-07-23 21:28:04 -07:00
Joe Lencioni
da3eb59b39 Merge pull request #961 from idugcoal/master
Change 'conjunctions' to 'contractions'
2016-07-23 12:55:46 -07:00
Doug Cole
892128366a change 'conjunctions' to 'contractions' 2016-07-23 11:53:45 -07:00
Jordan Harband
9d598c3563 [eslint config] [base] [breaking] enable more overlooked rules:
- `no-void`
 - `constructor-super`
 - `prefer-spread`
 - `no-new-require`
 - `no-undef-init`
2016-07-22 15:40:00 -07:00
Jordan Harband
4921e03a7b [eslint config] [base] [breaking] enable import/newline-after-import
Per https://github.com/benmosher/eslint-plugin-import/issues/386 / https://github.com/benmosher/eslint-plugin-import/issues/441
2016-07-14 21:27:37 -07:00
Jordan Harband
df8627d72f [eslint config] [*] [tests] fix prepublish scripts. 2016-07-19 13:57:42 -07:00
Jordan Harband
3594ee94ac [eslint config] [*] [docs] forgot “—save-dev” in 623dc44bb9 2016-07-19 10:33:29 -07:00
Jordan Harband
623dc44bb9 [eslint config] [*] [docs] update the peer dep install command to dynamically look up the right version numbers when installing peer deps.
Fixes #956.

This command would be simpler if https://github.com/npm/npm/issues/11213 is ever implemented.
2016-07-19 10:31:40 -07:00
Jordan Harband
ca9c322790 [eslint config] [base] [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`
2016-07-14 22:00:07 -07:00
Jordan Harband
762177eb3b [eslint config] [base] [deps] update eslint, eslint-find-rules, eslint-plugin-import 2016-07-18 14:27:26 -07:00
Jordan Harband
2504e0f85c [eslint config] [base] Fleshing out defaults. 2016-07-14 21:40:05 -07:00
Jordan Harband
385fc9effe Merge pull request #955 from ronal2do/master
Airbnb React/JSX Style Guide translation for PT-BR
2016-07-18 14:47:38 -07:00
Your NameRonaldo
723e12a87d Airbnb React/JSX Style Guide translation for PT-BR 2016-07-18 18:20:32 -03:00
Your NameRonaldo
97da7b65c6 Airbnb React/JSX Style Guide translation for PT-br 2016-07-18 18:17:59 -03:00
Kenny Tran
abcc0c681e Capitalize all comments in react.js 2016-07-15 11:14:22 -07:00
Jordan Harband
325f8ba72f [eslint config] [base] v4.0.2 2016-07-14 22:33:27 -07:00
Jordan Harband
6039804cc3 [eslint config] [base] [fix] repair accidental comma-dangle change. 2016-07-14 22:28:38 -07:00
Jordan Harband
af594687be [eslint config] [base] v4.0.1 2016-07-14 21:36:31 -07:00
Jordan Harband
5f02a6f98f [eslint config] [base] [deps] update eslint-plugin-import 2016-07-14 21:36:07 -07:00
Jordan Harband
b352ec6a4a [eslint config] [base] [fix] Prevent trailing commas in the legacy config.
Fixes #950.
2016-07-11 23:37:51 -07:00
Jordan Harband
a9bfee01cd [guide] Add link to eol-last rule.
Fixes #945.
2016-07-09 09:10:50 -07:00
Luke Libraro
3ad2404974 Added link to Mozilla documentation on Function.bind 2016-07-07 15:46:40 -05:00
Cédric Malard
7fb8b03714 Document for-in restricted usage
https://github.com/airbnb/javascript/issues/851#issuecomment-213834028
2016-07-06 17:00:42 +02:00
Joe Lencioni
7816731d4d Allow importing devDependencies in tests
This rule seems to be giving me errors for some places we have imported
devDependencies in our tests such as tape and eslint. This is actually
okay, so we just need to configure this rule to allow devDependencies
for tests.

While I was at it, I added some whitespace to improve readability and
reduce the likelihood of merge conflicts.
2016-07-05 10:11:18 -07:00
Jordan Harband
6db1af173c [eslint config] [*] [Tests] stop testing < node 4. 2016-07-05 13:07:41 -07:00
23 changed files with 293 additions and 98 deletions

View File

@@ -3,7 +3,6 @@ node_js:
- "6"
- "5"
- "4"
- "iojs"
env:
- 'TEST_DIR=packages/eslint-config-airbnb'
- 'TEST_DIR=packages/eslint-config-airbnb-base'
@@ -16,5 +15,3 @@ script:
sudo: false
matrix:
fast_finish: true
allow_failures:
- node_js: "iojs"

View File

@@ -1215,10 +1215,12 @@ Other Style Guides
## 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];
@@ -1920,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
@@ -2429,7 +2431,7 @@ Other Style Guides
```
<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

View File

@@ -0,0 +1,3 @@
{
"presets": ["airbnb"]
}

View File

@@ -1,3 +1,27 @@
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

View File

@@ -12,15 +12,41 @@ We export two ESLint configurations for your usage.
Our default export contains all of our ESLint rules, including ECMAScript 6+. It requires `eslint` and `eslint-plugin-import`.
1. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint`
2. add `"extends": "airbnb-base"` to your .eslintrc
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. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint`
2. add `"extends": "airbnb-base/legacy"` to your .eslintrc
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.

View File

@@ -1,6 +1,10 @@
module.exports = {
extends: [
'./legacy',
'./rules/best-practices',
'./rules/errors',
'./rules/node',
'./rules/style',
'./rules/variables',
'./rules/es6',
'./rules/imports',
].map(require.resolve),

View File

@@ -15,5 +15,7 @@ module.exports = {
},
ecmaFeatures: {},
globals: {},
rules: {}
rules: {
'comma-dangle': [2, 'never']
}
};

View File

@@ -1,12 +1,12 @@
{
"name": "eslint-config-airbnb-base",
"version": "4.0.0",
"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": "not-in-install && (eslint-find-rules --unused && npm test) || in-install",
"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"
@@ -45,16 +45,17 @@
},
"homepage": "https://github.com/airbnb/javascript",
"devDependencies": {
"babel-tape-runner": "^1.3.1",
"eslint": "^3.0.1",
"eslint-find-rules": "^1.11.0",
"eslint-plugin-import": "^1.10.2",
"tape": "^4.6.0",
"in-publish": "^2.0.0"
"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.0.1",
"eslint-plugin-import": "^1.10.2"
"eslint": "^3.2.0",
"eslint-plugin-import": "^1.12.0"
},
"engines": {
"node": ">= 4"

View File

@@ -26,7 +26,8 @@ module.exports = {
'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 !==
// http://eslint.org/docs/rules/eqeqeq
@@ -46,6 +47,7 @@ module.exports = {
'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
@@ -87,8 +89,14 @@ module.exports = {
// 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
@@ -181,7 +189,10 @@ module.exports = {
'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
@@ -199,7 +210,8 @@ module.exports = {
'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' }],

View File

@@ -37,7 +37,8 @@ module.exports = {
'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
// http://eslint.org/docs/rules/no-extra-parens
@@ -79,7 +80,8 @@ module.exports = {
'no-sparse-arrays': 2,
// Avoid code that looks like two expressions but is actually one
'no-unexpected-multiline': 0,
// 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,

View File

@@ -24,7 +24,7 @@ module.exports = {
'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
// http://eslint.org/docs/rules/generator-star-spacing
@@ -60,7 +60,8 @@ module.exports = {
'no-restricted-imports': 0,
// disallow to use this/super before super() calling in constructors.
'no-this-before-super': 0,
// 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
@@ -101,6 +102,8 @@ module.exports = {
}],
// suggest using Reflect methods where applicable
// http://eslint.org/docs/rules/prefer-reflect
// TODO: enable
'prefer-reflect': 0,
// use rest parameters instead of arguments
@@ -108,14 +111,16 @@ module.exports = {
'prefer-rest-params': 2,
// suggest using the spread operator instead of .apply()
'prefer-spread': 0,
// 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
@@ -123,7 +128,11 @@ module.exports = {
// 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

View File

@@ -86,6 +86,7 @@ module.exports = {
// 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:
@@ -118,8 +119,7 @@ module.exports = {
// 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
// TODO: enable when https://github.com/benmosher/eslint-plugin-import/issues/386 is resolved
'import/newline-after-import': 0,
'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

View File

@@ -18,10 +18,11 @@ module.exports = {
'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,
@@ -33,6 +34,6 @@ module.exports = {
'no-restricted-modules': 0,
// disallow use of synchronous methods (off by default)
'no-sync': 0
'no-sync': 0,
}
};

View File

@@ -51,7 +51,7 @@ module.exports = {
// specify whether double or single quotes should be used in JSX attributes
// http://eslint.org/docs/rules/jsx-quotes
'jsx-quotes': 0,
'jsx-quotes': [0, 'prefer-double'],
// enforces spacing between keys and values in object literal properties
'key-spacing': [2, { beforeColon: false, afterColon: true }],
@@ -68,7 +68,8 @@ module.exports = {
}],
// disallow mixed 'LF' and 'CRLF' as linebreaks
'linebreak-style': 0,
// http://eslint.org/docs/rules/linebreak-style
'linebreak-style': [2, 'unix'],
// enforces empty lines around comments
'lines-around-comment': 0,
@@ -104,11 +105,16 @@ module.exports = {
// 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
'new-parens': 0,
// http://eslint.org/docs/rules/new-parens
'new-parens': 2,
// allow/disallow an empty newline after var statement
'newline-after-var': 0,
@@ -125,16 +131,20 @@ module.exports = {
'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
'no-continue': 0,
// 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
'no-lonely-if': 0,
// 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
@@ -181,6 +191,10 @@ module.exports = {
// 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,
@@ -224,7 +238,8 @@ module.exports = {
'one-var-declaration-per-line': [2, 'always'],
// require assignment operator shorthand where possible or prohibit it entirely
'operator-assignment': 0,
// http://eslint.org/docs/rules/operator-assignment
'operator-assignment': [2, 'always'],
// enforce operators to be placed before or after line breaks
'operator-linebreak': 0,
@@ -266,7 +281,13 @@ module.exports = {
'space-infix-ops': 2,
// Require or disallow spaces before/after unary operators
'space-unary-ops': 0,
// 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', {

View File

@@ -10,7 +10,8 @@ module.exports = {
'no-delete-var': 2,
// disallow labels that share a name with a variable
'no-label-var': 0,
// http://eslint.org/docs/rules/no-label-var
'no-label-var': 2,
// disallow specific globals
'no-restricted-globals': 0,
@@ -25,9 +26,10 @@ module.exports = {
'no-undef': 2,
// disallow use of undefined when initializing variables
'no-undef-init': 0,
'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

View File

@@ -0,0 +1,3 @@
{
"presets": ["airbnb"]
}

View File

@@ -12,9 +12,21 @@ We export three ESLint configurations for your usage.
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-import eslint-plugin-react eslint-plugin-jsx-a11y 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
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).

View File

@@ -6,10 +6,10 @@
"scripts": {
"lint": "eslint .",
"tests-only": "babel-tape-runner ./test/test-*.js",
"prepublish": "not-in-install && (eslint-find-rules --unused && npm test) || in-install",
"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 link && cd - && npm link eslint-config-airbnb-base && npm run --silent test ; npm unlink eslint-config-airbnb-base >/dev/null &"
"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",
@@ -45,23 +45,27 @@
},
"homepage": "https://github.com/airbnb/javascript",
"dependencies": {
"eslint-config-airbnb-base": "^3.0.1"
"eslint-config-airbnb-base": "^5.0.1"
},
"devDependencies": {
"babel-tape-runner": "^1.3.1",
"eslint": "^2.10.2",
"eslint-find-rules": "^1.9.2",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-jsx-a11y": "^1.2.2",
"eslint-plugin-react": "^5.1.1",
"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.5.1",
"in-publish": "^2.0.0"
"tape": "^4.6.0"
},
"peerDependencies": {
"eslint": "^2.10.2",
"eslint-plugin-jsx-a11y": "^1.2.2",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-react": "^5.1.1"
"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"
}
}

View File

@@ -12,25 +12,21 @@ module.exports = {
'jsx-a11y/aria-role': 2,
// Enforce all aria-* props are valid.
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-props.md
'jsx-a11y/aria-props': 0,
'jsx-a11y/aria-props': 2,
// Enforce ARIA state and property values are valid.
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-proptypes.md
'jsx-a11y/aria-proptypes': 0,
'jsx-a11y/aria-proptypes': 2,
// Enforce that elements that do not support ARIA roles, states, and
// properties do not have those attributes.
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-unsupported-elements.md
'jsx-a11y/aria-unsupported-elements': 0,
'jsx-a11y/aria-unsupported-elements': 2,
// disallow href "#"
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/href-no-hash.md
'jsx-a11y/href-no-hash': 0,
'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
@@ -41,12 +37,11 @@ module.exports = {
'jsx-a11y/img-redundant-alt': 2,
// require that JSX labels use "htmlFor"
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
'jsx-a11y/label-has-for': 0,
'jsx-a11y/label-has-for': [2, ['label']],
// require that mouseover/out come with focus/blur, for keyboard-only users
// TODO: enable?
// 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,
@@ -69,19 +64,37 @@ module.exports = {
// Enforce that elements with ARIA roles must have all required attributes
// for that role.
// TODO: enable
// 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': 0,
'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.
// TODO: enable
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/role-supports-aria-props.md
'jsx-a11y/role-supports-aria-props': 0,
'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,
},
};

View File

@@ -14,7 +14,7 @@ module.exports = {
// View link below for react rules documentation
// https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
rules: {
// specify whether double or single quotes should be used in JSX attributes
// Specify whether double or single quotes should be used in JSX attributes
// http://eslint.org/docs/rules/jsx-quotes
'jsx-quotes': [2, 'prefer-double'],
@@ -89,9 +89,10 @@ module.exports = {
'react/sort-prop-types': [0, {
ignoreCase: false,
callbacksLast: false,
requiredFirst: false,
}],
// deprecated in favor of react/jsx-sort-props
// Deprecated in favor of react/jsx-sort-props
'react/jsx-sort-prop-types': 0,
// Enforce props alphabetical sorting
@@ -99,11 +100,13 @@ module.exports = {
'react/jsx-sort-props': [0, {
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
@@ -115,15 +118,15 @@ module.exports = {
// 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
@@ -167,7 +170,7 @@ module.exports = {
// 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
@@ -196,29 +199,50 @@ module.exports = {
}],
// 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
// 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
// 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
// Disallow target="_blank" on links
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
// TODO: enable
'react/jsx-no-target-blank': 0
'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: {

View File

@@ -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}]
}
}

View File

@@ -8,8 +8,10 @@ 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) {
@@ -22,6 +24,7 @@ function lint(text) {
function wrapComponent(body) {
return `
import React from 'react';
export default class MyComponent extends React.Component {
/* eslint no-empty-function: 0 */
${body}

View File

@@ -101,7 +101,32 @@
// 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.
@@ -149,7 +174,7 @@
- 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.
```jsx
@@ -549,5 +574,6 @@
- ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [JasonBoy/javascript](https://github.com/JasonBoy/javascript/tree/master/react)
- ![pl](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png) **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
- ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
- ![Br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
**[⬆ back to top](#table-of-contents)**