mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 13:28:05 -05:00
Compare commits
109 Commits
eslint-con
...
actions
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34b5bc39f1 | ||
|
|
d4e39c9b10 | ||
|
|
baaa5e8d26 | ||
|
|
274c8d5701 | ||
|
|
38bc026fe4 | ||
|
|
445322db64 | ||
|
|
152bd5e85a | ||
|
|
afc2cc3432 | ||
|
|
371537f393 | ||
|
|
c05ffb2417 | ||
|
|
97a3238020 | ||
|
|
e0bb393519 | ||
|
|
c4000b932a | ||
|
|
31c6f21878 | ||
|
|
91cab81f69 | ||
|
|
d8cb404da7 | ||
|
|
52e710c14e | ||
|
|
1bc8cabd44 | ||
|
|
37ebbba44c | ||
|
|
930a6f2e4c | ||
|
|
366bfa6638 | ||
|
|
f3d3a075cd | ||
|
|
eac8cc605b | ||
|
|
be6966b251 | ||
|
|
4fc997b97e | ||
|
|
96f11d8c81 | ||
|
|
c12a08c479 | ||
|
|
10a6d02c66 | ||
|
|
ef6c478a2b | ||
|
|
6734b78911 | ||
|
|
fdc812a0a5 | ||
|
|
8aec65a4d3 | ||
|
|
ea5b991a4f | ||
|
|
2a6bec1132 | ||
|
|
82dbec3c99 | ||
|
|
122788230a | ||
|
|
4ee7326393 | ||
|
|
7fbed3b55c | ||
|
|
30927d2503 | ||
|
|
f5c14cae2f | ||
|
|
428c9ddb7e | ||
|
|
af8bdf17dd | ||
|
|
d5d406a849 | ||
|
|
35914b1402 | ||
|
|
1fb4592122 | ||
|
|
5641278fa1 | ||
|
|
dc3af3a90e | ||
|
|
1eadb93e37 | ||
|
|
0cf78acab0 | ||
|
|
730b749274 | ||
|
|
4d837646b7 | ||
|
|
1b540ba14e | ||
|
|
711aeb650d | ||
|
|
9c181108a7 | ||
|
|
ea5ec0c524 | ||
|
|
db8b6ceb33 | ||
|
|
b9ff0aee71 | ||
|
|
fb3214c9d6 | ||
|
|
66cd156a48 | ||
|
|
63098cbb6c | ||
|
|
1f786e154f | ||
|
|
5620bd5620 | ||
|
|
f0df3a8680 | ||
|
|
37d48dbf60 | ||
|
|
e5de51e55f | ||
|
|
eee79a5455 | ||
|
|
b7015dd0b3 | ||
|
|
36f23d7886 | ||
|
|
e149b05366 | ||
|
|
f0492d59bd | ||
|
|
25b64d7f46 | ||
|
|
8996aa7c53 | ||
|
|
05c3bb0018 | ||
|
|
d3c7b84d9e | ||
|
|
b30b0e4d91 | ||
|
|
2c5c88d048 | ||
|
|
ee2f22a10c | ||
|
|
aa43bb2398 | ||
|
|
82170f9127 | ||
|
|
5ebfe3e5b8 | ||
|
|
337f60706f | ||
|
|
6006d6d2df | ||
|
|
a24dc34a4a | ||
|
|
1dc71d3839 | ||
|
|
973384be1b | ||
|
|
3dcc591123 | ||
|
|
c5bee75b1b | ||
|
|
5124de23da | ||
|
|
54955410ee | ||
|
|
197b50c076 | ||
|
|
f550ded6da | ||
|
|
562e3519b8 | ||
|
|
78457af2c5 | ||
|
|
5b462a04cd | ||
|
|
22adc06f56 | ||
|
|
fe2e451ba7 | ||
|
|
b587006077 | ||
|
|
8aee3e1600 | ||
|
|
cad3db3169 | ||
|
|
7aa0fa14d6 | ||
|
|
d34f807459 | ||
|
|
c48a060aff | ||
|
|
06b3ab11d9 | ||
|
|
c0ee2c4924 | ||
|
|
e4f3dd4eff | ||
|
|
0375265cbd | ||
|
|
d3628e2600 | ||
|
|
f075a0db50 | ||
|
|
d529ccaea3 |
26
.github/workflows/node-pretest.yml
vendored
Normal file
26
.github/workflows/node-pretest.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: 'Tests: pretest/posttest'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
pretest:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
package:
|
||||
- '..'
|
||||
- eslint-config-airbnb
|
||||
- eslint-config-airbnb-base
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: "packages/${{ matrix.package }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install lts/* && npm install'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm run pretest
|
||||
163
.github/workflows/node.yml
vendored
Normal file
163
.github/workflows/node.yml
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
name: 'Tests: node.js'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
latest: ${{ steps.set-matrix.outputs.requireds }}
|
||||
steps:
|
||||
- uses: ljharb/actions/node/matrix@main
|
||||
id: set-matrix
|
||||
with:
|
||||
versionsAsRoot: true
|
||||
type: 'majors'
|
||||
preset: '^12 || ^14 || ^16 || >= 17'
|
||||
|
||||
base:
|
||||
needs: [matrix]
|
||||
name: 'base config'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
||||
eslint:
|
||||
- 8
|
||||
- 7
|
||||
package:
|
||||
- eslint-config-airbnb-base
|
||||
exclude:
|
||||
- node-version: 10
|
||||
eslint: 8
|
||||
package: eslint-config-airbnb-base
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: "packages/${{ matrix.package }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||
with:
|
||||
before_install: cd "packages/${{ matrix.package }}"
|
||||
node-version: ${{ matrix.node-version }}
|
||||
after_install: |
|
||||
npm install --no-save "eslint@${{ matrix.eslint }}"
|
||||
- run: node -pe "require('eslint/package.json').version"
|
||||
name: 'eslint version'
|
||||
- run: npm run travis
|
||||
- uses: codecov/codecov-action@v2
|
||||
|
||||
react:
|
||||
needs: [matrix]
|
||||
name: 'react config'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
||||
eslint:
|
||||
- 8
|
||||
- 7
|
||||
package:
|
||||
- eslint-config-airbnb
|
||||
react-hooks:
|
||||
- 4
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: "packages/${{ matrix.package }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||
with:
|
||||
before_install: cd "packages/${{ matrix.package }}"
|
||||
node-version: ${{ matrix.node-version }}
|
||||
after_install: |
|
||||
npm install --no-save "eslint@${{ matrix.eslint }}"
|
||||
- run: node -pe "require('eslint/package.json').version"
|
||||
name: 'eslint version'
|
||||
- run: npm install --no-save "eslint-plugin-react-hooks@${{ matrix.react-hooks }}"
|
||||
if: ${{ matrix.react-hooks > 0}}
|
||||
- run: npm run travis
|
||||
- uses: codecov/codecov-action@v2
|
||||
|
||||
prepublish-base:
|
||||
name: 'prepublish tests (base config)'
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
eslint:
|
||||
- 8
|
||||
- 7
|
||||
package:
|
||||
- eslint-config-airbnb-base
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: "packages/${{ matrix.package }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install lts/* && npm install'
|
||||
with:
|
||||
before_install: cd "packages/${{ matrix.package }}"
|
||||
node-version: lts/*
|
||||
after_install: |
|
||||
npm install --no-save "eslint@${{ matrix.eslint }}"
|
||||
- run: node -pe "require('eslint/package.json').version"
|
||||
name: 'eslint version'
|
||||
- run: npm run pretravis
|
||||
- run: npm run prepublishOnly
|
||||
- run: npm run posttravis
|
||||
|
||||
prepublish-react:
|
||||
name: 'prepublish tests (react config)'
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
eslint:
|
||||
- 8
|
||||
- 7
|
||||
package:
|
||||
- eslint-config-airbnb
|
||||
react-hooks:
|
||||
- 4
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: "packages/${{ matrix.package }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install lts/* && npm install'
|
||||
with:
|
||||
before_install: cd "packages/${{ matrix.package }}"
|
||||
node-version: lts/*
|
||||
after_install: |
|
||||
npm install --no-save "eslint@${{ matrix.eslint }}"
|
||||
- run: npm install --no-save "eslint-plugin-react-hooks@${{ matrix.react-hooks }}"
|
||||
if: ${{ matrix.react-hooks > 0}}
|
||||
- run: node -pe "require('eslint/package.json').version"
|
||||
name: 'eslint version'
|
||||
- run: npm run pretravis
|
||||
- run: npm run prepublishOnly
|
||||
- run: npm run posttravis
|
||||
|
||||
node:
|
||||
name: 'node 10+'
|
||||
needs: [base, prepublish-base, react, prepublish-react]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: 'echo tests completed'
|
||||
15
.github/workflows/rebase.yml
vendored
Normal file
15
.github/workflows/rebase.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: Automatic Rebase
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
jobs:
|
||||
_:
|
||||
name: "Automatic Rebase"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/rebase@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
12
.github/workflows/require-allow-edits.yml
vendored
Normal file
12
.github/workflows/require-allow-edits.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
name: Require “Allow Edits”
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
jobs:
|
||||
_:
|
||||
name: "Require “Allow Edits”"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: ljharb/require-allow-edits@main
|
||||
67
.travis.yml
67
.travis.yml
@@ -1,67 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "12"
|
||||
- "11"
|
||||
- "10"
|
||||
- "9"
|
||||
- "8"
|
||||
before_install:
|
||||
- 'nvm install-latest-npm'
|
||||
install:
|
||||
- 'if [ -n "${PACKAGE-}" ]; then cd "packages/${PACKAGE}"; fi'
|
||||
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
|
||||
- 'if [ -n "${ESLINT}" ]; then npm install --no-save "eslint@${ESLINT}"; fi'
|
||||
- 'if [ -n "${REACT_HOOKS}" ]; then npm install --no-save "eslint-plugin-react-hooks@${REACT_HOOKS}"; fi'
|
||||
script:
|
||||
- 'if [ -n "${PREPUBLISH-}" ]; then npm run pretravis && npm run prepublish && npm run posttravis; elif [ -n "${LINT-}" ]; then npm run lint; else npm run travis; fi'
|
||||
sudo: false
|
||||
env:
|
||||
matrix:
|
||||
- 'TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb-base'
|
||||
- 'TEST=true ESLINT=6 PACKAGE=eslint-config-airbnb'
|
||||
- 'TEST=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb'
|
||||
- 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base'
|
||||
- 'TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb'
|
||||
- 'TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb'
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=6 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "lts/*"
|
||||
env: PREPUBLISH=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "lts/*"
|
||||
env: LINT=true
|
||||
- node_js: "lts/*"
|
||||
env: LINT=true PACKAGE=eslint-config-airbnb
|
||||
- node_js: "lts/*"
|
||||
env: LINT=true PACKAGE=eslint-config-airbnb-base
|
||||
- node_js: "7"
|
||||
env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
|
||||
- node_js: "7"
|
||||
env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "7"
|
||||
env: TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "6"
|
||||
env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
|
||||
- node_js: "6"
|
||||
env: TEST=true ESLINT=5 PACKAGE=eslint-config-airbnb
|
||||
- node_js: "6"
|
||||
env: TEST=true ESLINT=5 REACT_HOOKS=1.7 PACKAGE=eslint-config-airbnb
|
||||
exclude:
|
||||
allow_failures:
|
||||
- node_js: "11"
|
||||
- node_js: "9"
|
||||
- node_js: "7"
|
||||
- env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb-base
|
||||
- env: PREPUBLISH=true ESLINT=6 PACKAGE=eslint-config-airbnb
|
||||
- env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb-base
|
||||
- env: PREPUBLISH=true ESLINT=5 PACKAGE=eslint-config-airbnb
|
||||
82
README.md
82
README.md
@@ -139,18 +139,22 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="references--block-scope"></a><a name="2.3"></a>
|
||||
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped.
|
||||
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped, whereas `var` is function-scoped.
|
||||
|
||||
```javascript
|
||||
// const and let only exist in the blocks they are defined in.
|
||||
{
|
||||
let a = 1;
|
||||
const b = 1;
|
||||
var c = 1;
|
||||
}
|
||||
console.log(a); // ReferenceError
|
||||
console.log(b); // ReferenceError
|
||||
console.log(c); // Prints 1
|
||||
```
|
||||
|
||||
In the above code, you can see that referencing `a` and `b` will produce a ReferenceError, while `c` contains the number. This is because `a` and `b` are block scoped, while `c` is scoped to the containing function.
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Objects
|
||||
@@ -306,7 +310,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="objects--rest-spread"></a>
|
||||
- [3.8](#objects--rest-spread) Prefer the object spread operator over [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.
|
||||
- [3.8](#objects--rest-spread) Prefer the object spread syntax over [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to shallow-copy objects. Use the object rest parameter syntax to get a new object with certain properties omitted. eslint: [`prefer-object-spread`](https://eslint.org/docs/rules/prefer-object-spread)
|
||||
|
||||
```javascript
|
||||
// very bad
|
||||
@@ -497,7 +501,7 @@ Other Style Guides
|
||||
<a name="destructuring--object"></a><a name="5.1"></a>
|
||||
- [5.1](#destructuring--object) Use object destructuring when accessing and using multiple properties of an object. eslint: [`prefer-destructuring`](https://eslint.org/docs/rules/prefer-destructuring)
|
||||
|
||||
> Why? Destructuring saves you from creating temporary references for those properties.
|
||||
> Why? Destructuring saves you from creating temporary references for those properties, and from repetitive access of the object. Repeating object access creates more repetitive code, requires more reading, and creates more opportunities for mistakes. Destructuring objects also provides a single site of definition of the object structure that is used in the block, rather than requiring reading the entire block to determine what is used.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -782,7 +786,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--defaults-last"></a><a name="7.9"></a>
|
||||
- [7.9](#functions--defaults-last) Always put default parameters last.
|
||||
- [7.9](#functions--defaults-last) Always put default parameters last. eslint: [`default-param-last`](https://eslint.org/docs/rules/default-param-last)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -871,7 +875,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--spread-vs-apply"></a><a name="7.14"></a>
|
||||
- [7.14](#functions--spread-vs-apply) Prefer the use of the spread operator `...` to call variadic functions. eslint: [`prefer-spread`](https://eslint.org/docs/rules/prefer-spread)
|
||||
- [7.14](#functions--spread-vs-apply) Prefer the use of the spread syntax `...` to call variadic functions. eslint: [`prefer-spread`](https://eslint.org/docs/rules/prefer-spread)
|
||||
|
||||
> Why? It’s cleaner, you don’t need to supply a context, and you can not easily compose `new` with `apply`.
|
||||
|
||||
@@ -1256,7 +1260,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="classes--methods-use-this"></a>
|
||||
- [9.7](#classes--methods-use-this) Class methods should use `this` or be made into a static method unless an external library or framework requires to use specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: [`class-methods-use-this`](https://eslint.org/docs/rules/class-methods-use-this)
|
||||
- [9.7](#classes--methods-use-this) Class methods should use `this` or be made into a static method unless an external library or framework requires using specific non-static methods. Being an instance method should indicate that it behaves differently based on properties of the receiver. eslint: [`class-methods-use-this`](https://eslint.org/docs/rules/class-methods-use-this)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1662,7 +1666,7 @@ Other Style Guides
|
||||
<a name="variables--const-let-group"></a><a name="13.3"></a>
|
||||
- [13.3](#variables--const-let-group) Group all your `const`s and then group all your `let`s.
|
||||
|
||||
> Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.
|
||||
> Why? This is helpful when later on you might need to assign a variable depending on one of the previously assigned variables.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1859,7 +1863,7 @@ Other Style Guides
|
||||
## Hoisting
|
||||
|
||||
<a name="hoisting--about"></a><a name="14.1"></a>
|
||||
- [14.1](#hoisting--about) `var` declarations get hoisted to the top of their closest enclosing function scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone). It’s important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).
|
||||
- [14.1](#hoisting--about) `var` declarations get hoisted to the top of their closest enclosing function scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz). It’s important to know why [typeof is no longer safe](https://web.archive.org/web/20200121061528/http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).
|
||||
|
||||
```javascript
|
||||
// we know this wouldn’t work (assuming there
|
||||
@@ -1951,7 +1955,7 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
|
||||
- For more information refer to [JavaScript Scoping & Hoisting](https://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](https://www.adequatelygood.com/).
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
@@ -2618,6 +2622,10 @@ Other Style Guides
|
||||
|
||||
// good
|
||||
const leds = stage.selectAll('.led').data(data);
|
||||
const svg = leds.enter().append('svg:svg');
|
||||
svg.classed('led', true).attr('width', (radius + margin) * 2);
|
||||
const g = svg.append('svg:g');
|
||||
g.attr('transform', `translate(${radius + margin},${radius + margin})`).call(tron.led);
|
||||
```
|
||||
|
||||
<a name="whitespace--after-blocks"></a><a name="18.7"></a>
|
||||
@@ -2914,11 +2922,11 @@ Other Style Guides
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
var obj = { "foo" : 42 };
|
||||
var obj2 = { "foo":42 };
|
||||
var obj = { foo : 42 };
|
||||
var obj2 = { foo:42 };
|
||||
|
||||
// good
|
||||
var obj = { "foo": 42 };
|
||||
var obj = { foo: 42 };
|
||||
```
|
||||
|
||||
<a name="whitespace--no-trailing-spaces"></a>
|
||||
@@ -3094,7 +3102,7 @@ Other Style Guides
|
||||
<a name="semicolons--required"></a><a name="20.1"></a>
|
||||
- [21.1](#semicolons--required) **Yup.** eslint: [`semi`](https://eslint.org/docs/rules/semi.html)
|
||||
|
||||
> Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called [Automatic Semicolon Insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) to determine whether or not it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues.
|
||||
> Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called [Automatic Semicolon Insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) to determine whether it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. These rules will become more complicated as new features become a part of JavaScript. Explicitly terminating your statements and configuring your linter to catch missing semicolons will help prevent you from encountering issues.
|
||||
|
||||
```javascript
|
||||
// bad - raises exception
|
||||
@@ -3166,6 +3174,8 @@ Other Style Guides
|
||||
<a name="coercion--numbers"></a><a name="21.3"></a>
|
||||
- [22.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](https://eslint.org/docs/rules/radix) [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
|
||||
|
||||
> Why? The `parseInt` function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading whitespace in string is ignored. If radix is `undefined` or `0`, it is assumed to be `10` except when the number begins with the character pairs `0x` or `0X`, in which case a radix of 16 is assumed. This differs from ECMAScript 3, which merely discouraged (but allowed) octal interpretation. Many implementations have not adopted this behavior as of 2013. And, because older browsers must be supported, always specify a radix.
|
||||
|
||||
```javascript
|
||||
const inputValue = '4';
|
||||
|
||||
@@ -3612,7 +3622,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="jquery--queries"></a><a name="25.3"></a>
|
||||
- [26.3](#jquery--queries) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
|
||||
- [26.3](#jquery--queries) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](https://jsperf.com/jquery-find-vs-context-sel/16)
|
||||
|
||||
<a name="jquery--find"></a><a name="25.4"></a>
|
||||
- [26.4](#jquery--find) Use `find` with scoped jQuery object queries.
|
||||
@@ -3752,19 +3762,19 @@ Other Style Guides
|
||||
**Learning ES6+**
|
||||
|
||||
- [Latest ECMA spec](https://tc39.github.io/ecma262/)
|
||||
- [ExploringJS](http://exploringjs.com/)
|
||||
- [ExploringJS](https://exploringjs.com/)
|
||||
- [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/)
|
||||
- [Comprehensive Overview of ES6 Features](http://es6-features.org/)
|
||||
|
||||
**Read This**
|
||||
|
||||
- [Standard ECMA-262](http://www.ecma-international.org/ecma-262/6.0/index.html)
|
||||
- [Standard ECMA-262](https://www.ecma-international.org/ecma-262/6.0/index.html)
|
||||
|
||||
**Tools**
|
||||
|
||||
- Code Style Linters
|
||||
- [ESlint](https://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc)
|
||||
- [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/.jshintrc)
|
||||
- [JSHint](https://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/.jshintrc)
|
||||
- Neutrino Preset - [@neutrinojs/airbnb](https://neutrinojs.org/packages/airbnb/)
|
||||
|
||||
**Other Style Guides**
|
||||
@@ -3780,13 +3790,13 @@ Other Style Guides
|
||||
- [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen
|
||||
- [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen
|
||||
- [Popular JavaScript Coding Conventions on GitHub](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun
|
||||
- [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman
|
||||
- [Multiple var statements in JavaScript, not superfluous](https://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman
|
||||
|
||||
**Further Reading**
|
||||
|
||||
- [Understanding JavaScript Closures](https://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
|
||||
- [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
|
||||
- [You Might Not Need jQuery](http://youmightnotneedjquery.com/) - Zack Bloom & Adam Schwartz
|
||||
- [Basic JavaScript for the impatient programmer](https://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
|
||||
- [You Might Not Need jQuery](https://youmightnotneedjquery.com/) - Zack Bloom & Adam Schwartz
|
||||
- [ES6 Features](https://github.com/lukehoban/es6features) - Luke Hoban
|
||||
- [Frontend Guidelines](https://github.com/bendc/frontend-guidelines) - Benjamin De Cock
|
||||
|
||||
@@ -3803,23 +3813,23 @@ Other Style Guides
|
||||
- [Secrets of the JavaScript Ninja](https://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
|
||||
- [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
|
||||
- [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
|
||||
- [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon
|
||||
- [JSBooks](https://jsbooks.revolunet.com/) - Julien Bouquillon
|
||||
- [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
|
||||
- [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman
|
||||
- [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke
|
||||
- [You Don’t Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
|
||||
- [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](https://amzn.com/0321812182) - David Herman
|
||||
- [Eloquent JavaScript](https://eloquentjavascript.net/) - Marijn Haverbeke
|
||||
- [You Don’t Know JS: ES6 & Beyond](https://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
|
||||
|
||||
**Blogs**
|
||||
|
||||
- [JavaScript Weekly](http://javascriptweekly.com/)
|
||||
- [JavaScript Weekly](https://javascriptweekly.com/)
|
||||
- [JavaScript, JavaScript...](https://javascriptweblog.wordpress.com/)
|
||||
- [Bocoup Weblog](https://bocoup.com/weblog)
|
||||
- [Adequately Good](http://www.adequatelygood.com/)
|
||||
- [Adequately Good](https://www.adequatelygood.com/)
|
||||
- [NCZOnline](https://www.nczonline.net/)
|
||||
- [Perfection Kills](http://perfectionkills.com/)
|
||||
- [Ben Alman](http://benalman.com/)
|
||||
- [Ben Alman](https://benalman.com/)
|
||||
- [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
|
||||
- [nettuts](http://code.tutsplus.com/?s=javascript)
|
||||
- [nettuts](https://code.tutsplus.com/?s=javascript)
|
||||
|
||||
**Podcasts**
|
||||
|
||||
@@ -3833,18 +3843,15 @@ 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.
|
||||
|
||||
- **123erfasst**: [123erfasst/javascript](https://github.com/123erfasst/javascript)
|
||||
- **3blades**: [3Blades](https://github.com/3blades)
|
||||
- **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)
|
||||
- **AloPeyk**: [AloPeyk](https://github.com/AloPeyk)
|
||||
- **AltSchool**: [AltSchool/javascript](https://github.com/AltSchool/javascript)
|
||||
- **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)
|
||||
- **Ascribe**: [ascribe/javascript](https://github.com/ascribe/javascript)
|
||||
- **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)
|
||||
- **Avant**: [avantcredit/javascript](https://github.com/avantcredit/javascript)
|
||||
- **Axept**: [axept/javascript](https://github.com/axept/javascript)
|
||||
- **BashPros**: [BashPros/javascript](https://github.com/BashPros/javascript)
|
||||
- **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
|
||||
- **Bisk**: [bisk](https://github.com/Bisk/)
|
||||
- **Bonhomme**: [bonhommeparis/javascript](https://github.com/bonhommeparis/javascript)
|
||||
@@ -3858,13 +3865,12 @@ Other Style Guides
|
||||
- **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)
|
||||
- **Drupal**: [www.drupal.org](https://www.drupal.org/project/drupal)
|
||||
- **Drupal**: [www.drupal.org](https://git.drupalcode.org/project/drupal/blob/8.6.x/core/.eslintrc.json)
|
||||
- **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)
|
||||
- **Gawker Media**: [gawkermedia](https://github.com/gawkermedia/)
|
||||
- **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
|
||||
@@ -3876,12 +3882,10 @@ Other Style Guides
|
||||
- **Happeo**: [happeo/javascript](https://github.com/happeo/javascript)
|
||||
- **Honey**: [honeyscience/javascript](https://github.com/honeyscience/javascript)
|
||||
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)
|
||||
- **Huballin**: [huballin](https://github.com/huballin/)
|
||||
- **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)
|
||||
- **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)
|
||||
- **InterCity Group**: [intercitygroup/javascript-style-guide](https://github.com/intercitygroup/javascript-style-guide)
|
||||
- **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)
|
||||
- **Kaplan Komputing**: [kaplankomputing/javascript](https://github.com/kaplankomputing/javascript)
|
||||
- **KickorStick**: [kickorstick](https://github.com/kickorstick/)
|
||||
@@ -3892,11 +3896,8 @@ Other Style Guides
|
||||
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
|
||||
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
|
||||
- **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)
|
||||
- **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
|
||||
- **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript)
|
||||
- **Muber**: [muber](https://github.com/muber/)
|
||||
- **National Geographic**: [natgeo](https://github.com/natgeo/)
|
||||
- **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)
|
||||
- **NullDev**: [NullDevCo/JavaScript-Styleguide](https://github.com/NullDevCo/JavaScript-Styleguide)
|
||||
- **Nulogy**: [nulogy/javascript](https://github.com/nulogy/javascript)
|
||||
- **Orange Hill Development**: [orangehill/javascript](https://github.com/orangehill/javascript)
|
||||
@@ -3905,13 +3906,10 @@ Other Style Guides
|
||||
- **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)
|
||||
- **Pier 1**: [Pier1/javascript](https://github.com/pier1/javascript)
|
||||
- **Qotto**: [Qotto/javascript-style-guide](https://github.com/Qotto/javascript-style-guide)
|
||||
- **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
|
||||
- **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)
|
||||
- **React**: [facebook.github.io/react/contributing/how-to-contribute.html#style-guide](https://facebook.github.io/react/contributing/how-to-contribute.html#style-guide)
|
||||
- **REI**: [reidev/js-style-guide](https://github.com/rei/code-style-guides/)
|
||||
- **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)
|
||||
- **Sainsbury’s Supermarkets**: [jsainsburyplc](https://github.com/jsainsburyplc)
|
||||
- **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
|
||||
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
|
||||
- **Sourcetoad**: [sourcetoad/javascript](https://github.com/sourcetoad/javascript)
|
||||
- **Springload**: [springload](https://github.com/springload/)
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
"no-multiple-space-closed-atx": true,
|
||||
|
||||
"comment": "MD022: Headers should be surrounded by blank lines.",
|
||||
"comment": "Some headers have preceeding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers",
|
||||
"comment": "Some headers have preceding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers",
|
||||
"blanks-around-headers": false,
|
||||
|
||||
"comment": "MD023: Headers must start at the beginning of the line.",
|
||||
@@ -111,7 +111,7 @@
|
||||
"blanks-around-fences": true,
|
||||
|
||||
"comment": "MD032: Lists should be surrounded by blank lines",
|
||||
"comment": "Some lists have preceeding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers",
|
||||
"comment": "Some lists have preceding HTML anchors. Unfortunate that we have to disable this, as it otherwise catches a real problem that trips up some Markdown renderers",
|
||||
"blanks-around-lists": false,
|
||||
|
||||
"comment": "MD033: Disallow inline HTML",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* @version 0.3.0
|
||||
* @see https://github.com/SublimeLinter/SublimeLinter
|
||||
* @see http://www.jshint.com/docs/
|
||||
* @see https://www.jshint.com/docs/
|
||||
*/
|
||||
{
|
||||
"jshint_options":
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"markdownlint": "^0.19.0",
|
||||
"markdownlint-cli": "^0.21.0"
|
||||
"markdownlint": "^0.20.4",
|
||||
"markdownlint-cli": "^0.23.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,7 @@
|
||||
// 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,
|
||||
|
||||
"max-len": 0,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,3 +1,40 @@
|
||||
15.0.0 / 2021-11-08
|
||||
==================
|
||||
- [breaking] drop eslint < 7, add eslint 8 (#2495)
|
||||
- [breaking] add `exports`
|
||||
- [patch] Improve `function-paren-newline` with `multiline-arguments` option (#2471)
|
||||
- [patch] update default value for complexity (#2420)
|
||||
- [patch] add disabled `no-unsafe-optional-chaining` rule
|
||||
- [patch] arthmetic -> arithmetic (#2341)
|
||||
- [patch] fix spelling of "than" (#2333)
|
||||
- [patch] add `no-nonoctal-decimal-escape` rule
|
||||
- [patch] `import/no-extraneous-dependencies`: Add .eslintrc.js to devDeps (#2329)
|
||||
- [guide] Spread operator => Spread syntax (#2423)
|
||||
- [guide] add references for eslint rules (#2419)
|
||||
- [Docs] HTTP => HTTPS (#2489)
|
||||
- [readme] some updates
|
||||
- [meta] use `prepublishOnly` script for npm 7+
|
||||
- [deps] update `eslint-plugin-import`, `eslint-plugin-react`, `object.entries`
|
||||
- [dev deps] update `@babel/runtime`, ``tape`
|
||||
|
||||
14.2.1 / 2020-11-06
|
||||
==================
|
||||
- [base] `no-restricted-globals`: add better messages (#2320)
|
||||
- [base] add new core eslint rules, set to off
|
||||
- [deps] update `confusing-browser-globals`, `object.assign`
|
||||
- [deps] update `eslint-plugin-import`, use valid `import/no-cycle` `maxDepth` option (#2250, #2249)
|
||||
- [dev deps] update `@babel/runtime`, `eslint-find-rules`, `eslint-plugin-import`
|
||||
|
||||
14.2.0 / 2020-06-10
|
||||
==================
|
||||
- [new] add `eslint` `v7`
|
||||
- [minor] Disallow multiple empty lines (#2238)
|
||||
- [minor] Fix typo in no-multiple-empty-lines rule (#2168)
|
||||
- [patch] Include 'context' exception for `no-param-reassign` (#2230)
|
||||
- [patch] Allow triple-slash (///) comments (#2197)
|
||||
- [patch] Disable `prefer-object-spread` for `airbnb-base/legacy` (#2198)
|
||||
- [deps] update `eslint-plugin-import`, `eslint-plugin-react`, `babel-preset-airbnb`, `eslint-find-rules`, `in-publish`, `tape`, `object.entries`
|
||||
|
||||
14.1.0 / 2020-03-12
|
||||
==================
|
||||
- [minor] add new disabled rules, update eslint
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# eslint-config-airbnb-base
|
||||
# eslint-config-airbnb-base <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[](http://badge.fury.io/js/eslint-config-airbnb-base)
|
||||
[][package-url]
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
This package provides Airbnb's base JS .eslintrc (without React plugins) as an extensible shared config.
|
||||
|
||||
@@ -79,7 +83,7 @@ Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
|
||||
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
|
||||
npm install --save-dev eslint-config-airbnb-base eslint@^#.#.# eslint-plugin-import@^#.#.#
|
||||
```
|
||||
|
||||
2. Add `"extends": "airbnb-base/legacy"` to your .eslintrc
|
||||
@@ -97,3 +101,12 @@ Consider adding test cases if you're making complicated rules changes, like anyt
|
||||
You can run tests with `npm test`.
|
||||
|
||||
You can make sure this module lints with itself using `npm run lint`.
|
||||
|
||||
[package-url]: https://npmjs.org/package/eslint-config-airbnb-base
|
||||
[npm-version-svg]: https://versionbadg.es/airbnb/javascript.svg
|
||||
[license-image]: https://img.shields.io/npm/l/eslint-config-airbnb-base.svg
|
||||
[license-url]: LICENSE.md
|
||||
[downloads-image]: https://img.shields.io/npm/dm/eslint-config-airbnb-base.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=eslint-config-airbnb-base
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/airbnb/javascript
|
||||
[actions-url]: https://github.com/airbnb/javascript/actions
|
||||
|
||||
@@ -28,6 +28,7 @@ module.exports = {
|
||||
message: 'Please use Object.defineProperty instead.',
|
||||
}],
|
||||
'no-var': 'off',
|
||||
'prefer-object-spread': 'off',
|
||||
strict: ['error', 'safe'],
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb-base",
|
||||
"version": "14.1.0",
|
||||
"version": "15.0.0",
|
||||
"description": "Airbnb's base JS ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./legacy": "./legacy.js",
|
||||
"./whitespace": "./whitespace.js",
|
||||
"./rules/best-practices": "./rules/best-practices.js",
|
||||
"./rules/es6": "./rules/es6.js",
|
||||
"./rules/node": "./rules/node.js",
|
||||
"./rules/style": "./rules/style.js",
|
||||
"./rules/errors": "./rules/errors.js",
|
||||
"./rules/imports": "./rules/imports.js",
|
||||
"./rules/strict": "./rules/strict.js",
|
||||
"./rules/variables": "./rules/variables.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"prelint": "eclint check * rules/* test/*",
|
||||
"lint": "eslint --report-unused-disable-directives .",
|
||||
"pretests-only": "node ./test/requires",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest",
|
||||
"prepublishOnly": "eslint-find-rules --unused && npm test && safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"pretravis": ":",
|
||||
@@ -53,27 +68,27 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "^7.8.7",
|
||||
"babel-preset-airbnb": "^4.4.0",
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"babel-preset-airbnb": "^4.5.0",
|
||||
"babel-tape-runner": "^3.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^5.16.0 || ^6.8.0",
|
||||
"eslint-find-rules": "^3.4.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"in-publish": "^2.0.0",
|
||||
"safe-publish-latest": "^1.1.4",
|
||||
"tape": "^5.0.0-next.4"
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-find-rules": "^4.0.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"in-publish": "^2.0.1",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^5.16.0 || ^6.8.0",
|
||||
"eslint-plugin-import": "^2.20.1"
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-plugin-import": "^2.25.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
"node": "^10.12.0 || >=12.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"confusing-browser-globals": "^1.0.9",
|
||||
"object.assign": "^4.1.0",
|
||||
"object.entries": "^1.1.1"
|
||||
"confusing-browser-globals": "^1.0.10",
|
||||
"object.assign": "^4.1.2",
|
||||
"object.entries": "^1.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
rules: {
|
||||
// enforces getter/setter pairs in objects
|
||||
// https://eslint.org/docs/rules/accessor-pairs
|
||||
'accessor-pairs': 'off',
|
||||
|
||||
// enforces return statements in callbacks of array's methods
|
||||
@@ -8,10 +9,12 @@ module.exports = {
|
||||
'array-callback-return': ['error', { allowImplicit: true }],
|
||||
|
||||
// treat var statements as if they were block scoped
|
||||
// https://eslint.org/docs/rules/block-scoped-var
|
||||
'block-scoped-var': 'error',
|
||||
|
||||
// specify the maximum cyclomatic complexity allowed in a program
|
||||
complexity: ['off', 11],
|
||||
// https://eslint.org/docs/rules/complexity
|
||||
complexity: ['off', 20],
|
||||
|
||||
// enforce that class methods use "this"
|
||||
// https://eslint.org/docs/rules/class-methods-use-this
|
||||
@@ -20,19 +23,26 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// require return statements to either always or never specify values
|
||||
// https://eslint.org/docs/rules/consistent-return
|
||||
'consistent-return': 'error',
|
||||
|
||||
// specify curly brace conventions for all control statements
|
||||
// https://eslint.org/docs/rules/curly
|
||||
curly: ['error', 'multi-line'], // multiline
|
||||
|
||||
// require default case in switch statements
|
||||
// https://eslint.org/docs/rules/default-case
|
||||
'default-case': ['error', { commentPattern: '^no default$' }],
|
||||
|
||||
// Enforce default clauses in switch statements to be last
|
||||
// https://eslint.org/docs/rules/default-case-last
|
||||
'default-case-last': 'error',
|
||||
|
||||
// https://eslint.org/docs/rules/default-param-last
|
||||
// TODO: enable, semver-minor, when eslint v6.4 is required (which is a major)
|
||||
'default-param-last': 'off',
|
||||
'default-param-last': 'error',
|
||||
|
||||
// encourages use of dot notation whenever possible
|
||||
// https://eslint.org/docs/rules/dot-notation
|
||||
'dot-notation': ['error', { allowKeywords: true }],
|
||||
|
||||
// enforces consistent newlines before or after dots
|
||||
@@ -45,10 +55,10 @@ module.exports = {
|
||||
|
||||
// Require grouped accessor pairs in object literals and classes
|
||||
// https://eslint.org/docs/rules/grouped-accessor-pairs
|
||||
// TODO: enable in next major, altho the guide forbids getters/setters anyways
|
||||
'grouped-accessor-pairs': 'off',
|
||||
'grouped-accessor-pairs': 'error',
|
||||
|
||||
// make sure for-in loops have an if statement
|
||||
// https://eslint.org/docs/rules/guard-for-in
|
||||
'guard-for-in': 'error',
|
||||
|
||||
// enforce a maximum number of classes per file
|
||||
@@ -56,19 +66,20 @@ module.exports = {
|
||||
'max-classes-per-file': ['error', 1],
|
||||
|
||||
// disallow the use of alert, confirm, and prompt
|
||||
// https://eslint.org/docs/rules/no-alert
|
||||
'no-alert': 'warn',
|
||||
|
||||
// disallow use of arguments.caller or arguments.callee
|
||||
// https://eslint.org/docs/rules/no-caller
|
||||
'no-caller': 'error',
|
||||
|
||||
// disallow lexical declarations in case/default clauses
|
||||
// https://eslint.org/docs/rules/no-case-declarations.html
|
||||
// https://eslint.org/docs/rules/no-case-declarations
|
||||
'no-case-declarations': 'error',
|
||||
|
||||
// Disallow returning value in constructor
|
||||
// https://eslint.org/docs/rules/no-constructor-return
|
||||
// TODO: enable, semver-major
|
||||
'no-constructor-return': 'off',
|
||||
'no-constructor-return': 'error',
|
||||
|
||||
// disallow division operators explicitly at beginning of regular expression
|
||||
// https://eslint.org/docs/rules/no-div-regex
|
||||
@@ -93,15 +104,19 @@ module.exports = {
|
||||
'no-empty-pattern': 'error',
|
||||
|
||||
// disallow comparisons to null without a type-checking operator
|
||||
// https://eslint.org/docs/rules/no-eq-null
|
||||
'no-eq-null': 'off',
|
||||
|
||||
// disallow use of eval()
|
||||
// https://eslint.org/docs/rules/no-eval
|
||||
'no-eval': 'error',
|
||||
|
||||
// disallow adding to native types
|
||||
// https://eslint.org/docs/rules/no-extend-native
|
||||
'no-extend-native': 'error',
|
||||
|
||||
// disallow unnecessary function binding
|
||||
// https://eslint.org/docs/rules/no-extra-bind
|
||||
'no-extra-bind': 'error',
|
||||
|
||||
// disallow Unnecessary Labels
|
||||
@@ -109,15 +124,19 @@ module.exports = {
|
||||
'no-extra-label': 'error',
|
||||
|
||||
// disallow fallthrough of case statements
|
||||
// https://eslint.org/docs/rules/no-fallthrough
|
||||
'no-fallthrough': 'error',
|
||||
|
||||
// disallow the use of leading or trailing decimal points in numeric literals
|
||||
// https://eslint.org/docs/rules/no-floating-decimal
|
||||
'no-floating-decimal': 'error',
|
||||
|
||||
// disallow reassignments of native objects or read-only globals
|
||||
// https://eslint.org/docs/rules/no-global-assign
|
||||
'no-global-assign': ['error', { exceptions: [] }],
|
||||
|
||||
// deprecated in favor of no-global-assign
|
||||
// https://eslint.org/docs/rules/no-native-reassign
|
||||
'no-native-reassign': 'off',
|
||||
|
||||
// disallow implicit type conversions
|
||||
@@ -134,21 +153,27 @@ module.exports = {
|
||||
'no-implicit-globals': 'off',
|
||||
|
||||
// disallow use of eval()-like methods
|
||||
// https://eslint.org/docs/rules/no-implied-eval
|
||||
'no-implied-eval': 'error',
|
||||
|
||||
// disallow this keywords outside of classes or class-like objects
|
||||
// https://eslint.org/docs/rules/no-invalid-this
|
||||
'no-invalid-this': 'off',
|
||||
|
||||
// disallow usage of __iterator__ property
|
||||
// https://eslint.org/docs/rules/no-iterator
|
||||
'no-iterator': 'error',
|
||||
|
||||
// disallow use of labels for anything other then loops and switches
|
||||
// disallow use of labels for anything other than loops and switches
|
||||
// https://eslint.org/docs/rules/no-labels
|
||||
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
|
||||
|
||||
// disallow unnecessary nested blocks
|
||||
// https://eslint.org/docs/rules/no-lone-blocks
|
||||
'no-lone-blocks': 'error',
|
||||
|
||||
// disallow creation of functions within loops
|
||||
// https://eslint.org/docs/rules/no-loop-func
|
||||
'no-loop-func': 'error',
|
||||
|
||||
// disallow magic numbers
|
||||
@@ -161,27 +186,38 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// disallow use of multiple spaces
|
||||
// https://eslint.org/docs/rules/no-multi-spaces
|
||||
'no-multi-spaces': ['error', {
|
||||
ignoreEOLComments: false,
|
||||
}],
|
||||
|
||||
// disallow use of multiline strings
|
||||
// https://eslint.org/docs/rules/no-multi-str
|
||||
'no-multi-str': 'error',
|
||||
|
||||
// disallow use of new operator when not part of the assignment or comparison
|
||||
// https://eslint.org/docs/rules/no-new
|
||||
'no-new': 'error',
|
||||
|
||||
// disallow use of new operator for Function object
|
||||
// https://eslint.org/docs/rules/no-new-func
|
||||
'no-new-func': 'error',
|
||||
|
||||
// disallows creating new instances of String, Number, and Boolean
|
||||
// https://eslint.org/docs/rules/no-new-wrappers
|
||||
'no-new-wrappers': 'error',
|
||||
|
||||
// Disallow \8 and \9 escape sequences in string literals
|
||||
// https://eslint.org/docs/rules/no-nonoctal-decimal-escape
|
||||
'no-nonoctal-decimal-escape': 'error',
|
||||
|
||||
// disallow use of (old style) octal literals
|
||||
// https://eslint.org/docs/rules/no-octal
|
||||
'no-octal': 'error',
|
||||
|
||||
// disallow use of octal escape sequences in string literals, such as
|
||||
// var foo = 'Copyright \251';
|
||||
// https://eslint.org/docs/rules/no-octal-escape
|
||||
'no-octal-escape': 'error',
|
||||
|
||||
// disallow reassignment of function parameters
|
||||
@@ -194,6 +230,7 @@ module.exports = {
|
||||
'accumulator', // for reduce accumulators
|
||||
'e', // for e.returnvalue
|
||||
'ctx', // for Koa routing
|
||||
'context', // for Koa routing
|
||||
'req', // for Express requests
|
||||
'request', // for Express requests
|
||||
'res', // for Express responses
|
||||
@@ -204,9 +241,11 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// disallow usage of __proto__ property
|
||||
// https://eslint.org/docs/rules/no-proto
|
||||
'no-proto': 'error',
|
||||
|
||||
// disallow declaring the same variable more then once
|
||||
// disallow declaring the same variable more than once
|
||||
// https://eslint.org/docs/rules/no-redeclare
|
||||
'no-redeclare': 'error',
|
||||
|
||||
// disallow certain object properties
|
||||
@@ -252,12 +291,15 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// disallow use of assignment in return statement
|
||||
// https://eslint.org/docs/rules/no-return-assign
|
||||
'no-return-assign': ['error', 'always'],
|
||||
|
||||
// disallow redundant `return await`
|
||||
// https://eslint.org/docs/rules/no-return-await
|
||||
'no-return-await': 'error',
|
||||
|
||||
// disallow use of `javascript:` urls.
|
||||
// https://eslint.org/docs/rules/no-script-url
|
||||
'no-script-url': 'error',
|
||||
|
||||
// disallow self assignment
|
||||
@@ -267,12 +309,15 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// disallow comparisons where both sides are exactly the same
|
||||
// https://eslint.org/docs/rules/no-self-compare
|
||||
'no-self-compare': 'error',
|
||||
|
||||
// disallow use of comma operator
|
||||
// https://eslint.org/docs/rules/no-sequences
|
||||
'no-sequences': 'error',
|
||||
|
||||
// restrict what can be thrown as an exception
|
||||
// https://eslint.org/docs/rules/no-throw-literal
|
||||
'no-throw-literal': 'error',
|
||||
|
||||
// disallow unmodified conditions of loops
|
||||
@@ -280,6 +325,7 @@ module.exports = {
|
||||
'no-unmodified-loop-condition': 'off',
|
||||
|
||||
// disallow usage of expressions in statement position
|
||||
// https://eslint.org/docs/rules/no-unused-expressions
|
||||
'no-unused-expressions': ['error', {
|
||||
allowShortCircuit: false,
|
||||
allowTernary: false,
|
||||
@@ -291,6 +337,7 @@ module.exports = {
|
||||
'no-unused-labels': 'error',
|
||||
|
||||
// disallow unnecessary .call() and .apply()
|
||||
// https://eslint.org/docs/rules/no-useless-call
|
||||
'no-useless-call': 'off',
|
||||
|
||||
// Disallow unnecessary catch clauses
|
||||
@@ -314,9 +361,11 @@ module.exports = {
|
||||
'no-void': 'error',
|
||||
|
||||
// disallow usage of configurable warning terms in comments: e.g. todo
|
||||
// https://eslint.org/docs/rules/no-warning-comments
|
||||
'no-warning-comments': ['off', { terms: ['todo', 'fixme', 'xxx'], location: 'start' }],
|
||||
|
||||
// disallow use of the with statement
|
||||
// https://eslint.org/docs/rules/no-with
|
||||
'no-with': 'error',
|
||||
|
||||
// require using Error objects as Promise rejection reasons
|
||||
@@ -327,11 +376,18 @@ module.exports = {
|
||||
// https://eslint.org/docs/rules/prefer-named-capture-group
|
||||
'prefer-named-capture-group': 'off',
|
||||
|
||||
// Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call()
|
||||
// https://eslint.org/docs/rules/prefer-object-has-own
|
||||
// TODO: semver-major: enable thus rule, once eslint v8.5.0 is required
|
||||
'prefer-object-has-own': 'off',
|
||||
|
||||
// https://eslint.org/docs/rules/prefer-regex-literals
|
||||
// TODO; enable, semver-minor, once eslint v6.4 is required (which is a major)
|
||||
'prefer-regex-literals': 'off',
|
||||
'prefer-regex-literals': ['error', {
|
||||
disallowRedundantWrapping: true,
|
||||
}],
|
||||
|
||||
// require use of the second argument for parseInt()
|
||||
// https://eslint.org/docs/rules/radix
|
||||
radix: 'error',
|
||||
|
||||
// require `await` in `async function` (note: this is a horrible rule that should never be used)
|
||||
@@ -343,6 +399,7 @@ module.exports = {
|
||||
'require-unicode-regexp': 'off',
|
||||
|
||||
// requires to declare all vars on top of their containing scope
|
||||
// https://eslint.org/docs/rules/vars-on-top
|
||||
'vars-on-top': 'error',
|
||||
|
||||
// require immediate function invocation to be wrapped in parentheses
|
||||
@@ -350,6 +407,7 @@ module.exports = {
|
||||
'wrap-iife': ['error', 'outside', { functionPrototypeMethods: false }],
|
||||
|
||||
// require or disallow Yoda conditions
|
||||
// https://eslint.org/docs/rules/yoda
|
||||
yoda: 'error'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -40,8 +40,7 @@ module.exports = {
|
||||
|
||||
// Disallow duplicate conditions in if-else-if chains
|
||||
// https://eslint.org/docs/rules/no-dupe-else-if
|
||||
// TODO: enable, semver-major
|
||||
'no-dupe-else-if': 'off',
|
||||
'no-dupe-else-if': 'error',
|
||||
|
||||
// disallow duplicate keys when creating object literals
|
||||
'no-dupe-keys': 'error',
|
||||
@@ -79,8 +78,7 @@ module.exports = {
|
||||
'no-func-assign': 'error',
|
||||
|
||||
// https://eslint.org/docs/rules/no-import-assign
|
||||
// TODO: enable, semver-minor, once eslint v6.4 is required (which is a major)
|
||||
'no-import-assign': 'off',
|
||||
'no-import-assign': 'error',
|
||||
|
||||
// disallow function or variable declarations in nested blocks
|
||||
'no-inner-declarations': 'error',
|
||||
@@ -91,6 +89,10 @@ module.exports = {
|
||||
// disallow irregular whitespace outside of strings and comments
|
||||
'no-irregular-whitespace': 'error',
|
||||
|
||||
// Disallow Number Literals That Lose Precision
|
||||
// https://eslint.org/docs/rules/no-loss-of-precision
|
||||
'no-loss-of-precision': 'error',
|
||||
|
||||
// Disallow characters which are made with multiple code points in character class syntax
|
||||
// https://eslint.org/docs/rules/no-misleading-character-class
|
||||
'no-misleading-character-class': 'error',
|
||||
@@ -98,6 +100,10 @@ module.exports = {
|
||||
// disallow the use of object properties of the global object (Math and JSON) as functions
|
||||
'no-obj-calls': 'error',
|
||||
|
||||
// Disallow returning values from Promise executor functions
|
||||
// https://eslint.org/docs/rules/no-promise-executor-return
|
||||
'no-promise-executor-return': 'error',
|
||||
|
||||
// disallow use of Object.prototypes builtins directly
|
||||
// https://eslint.org/docs/rules/no-prototype-builtins
|
||||
'no-prototype-builtins': 'error',
|
||||
@@ -107,8 +113,7 @@ module.exports = {
|
||||
|
||||
// Disallow returning values from setters
|
||||
// https://eslint.org/docs/rules/no-setter-return
|
||||
// TODO: enable, semver-major (altho the guide forbids getters/setters already)
|
||||
'no-setter-return': 'off',
|
||||
'no-setter-return': 'error',
|
||||
|
||||
// disallow sparse arrays
|
||||
'no-sparse-arrays': 'error',
|
||||
@@ -124,6 +129,12 @@ module.exports = {
|
||||
// disallow unreachable statements after a return, throw, continue, or break statement
|
||||
'no-unreachable': 'error',
|
||||
|
||||
// Disallow loops with a body that allows only one iteration
|
||||
// https://eslint.org/docs/rules/no-unreachable-loop
|
||||
'no-unreachable-loop': ['error', {
|
||||
ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
|
||||
}],
|
||||
|
||||
// disallow return/throw/break/continue inside finally blocks
|
||||
// https://eslint.org/docs/rules/no-unsafe-finally
|
||||
'no-unsafe-finally': 'error',
|
||||
@@ -131,13 +142,27 @@ module.exports = {
|
||||
// disallow negating the left operand of relational operators
|
||||
// https://eslint.org/docs/rules/no-unsafe-negation
|
||||
'no-unsafe-negation': 'error',
|
||||
|
||||
// disallow use of optional chaining in contexts where the undefined value is not allowed
|
||||
// https://eslint.org/docs/rules/no-unsafe-optional-chaining
|
||||
'no-unsafe-optional-chaining': ['error', { disallowArithmeticOperators: true }],
|
||||
|
||||
// Disallow Unused Private Class Members
|
||||
// https://eslint.org/docs/rules/no-unused-private-class-members
|
||||
// TODO: enable once eslint 7 is dropped (which is semver-major)
|
||||
'no-unused-private-class-members': 'off',
|
||||
|
||||
// Disallow useless backreferences in regular expressions
|
||||
// https://eslint.org/docs/rules/no-useless-backreference
|
||||
'no-useless-backreference': 'error',
|
||||
|
||||
// disallow negation of the left operand of an in expression
|
||||
// deprecated in favor of no-unsafe-negation
|
||||
'no-negated-in-lhs': 'off',
|
||||
|
||||
// Disallow assignments that can lead to race conditions due to usage of await or yield
|
||||
// https://eslint.org/docs/rules/require-atomic-updates
|
||||
// TODO: enable, semver-major
|
||||
// note: not enabled because it is very buggy
|
||||
'require-atomic-updates': 'off',
|
||||
|
||||
// disallow comparisons with the value NaN
|
||||
|
||||
@@ -60,6 +60,15 @@ module.exports = {
|
||||
// https://eslint.org/docs/rules/no-new-symbol
|
||||
'no-new-symbol': 'error',
|
||||
|
||||
// Disallow specified names in exports
|
||||
// https://eslint.org/docs/rules/no-restricted-exports
|
||||
'no-restricted-exports': ['error', {
|
||||
restrictedNamedExports: [
|
||||
'default', // use `export default` to provide a default export
|
||||
'then', // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
|
||||
],
|
||||
}],
|
||||
|
||||
// disallow specific imports
|
||||
// https://eslint.org/docs/rules/no-restricted-imports
|
||||
'no-restricted-imports': ['off', {
|
||||
@@ -136,7 +145,7 @@ module.exports = {
|
||||
// https://eslint.org/docs/rules/prefer-rest-params
|
||||
'prefer-rest-params': 'error',
|
||||
|
||||
// suggest using the spread operator instead of .apply()
|
||||
// suggest using the spread syntax instead of .apply()
|
||||
// https://eslint.org/docs/rules/prefer-spread
|
||||
'prefer-spread': 'error',
|
||||
|
||||
|
||||
@@ -90,7 +90,8 @@ module.exports = {
|
||||
'**/Gruntfile{,.js}', // grunt config
|
||||
'**/protractor.conf.js', // protractor config
|
||||
'**/protractor.conf.*.js', // protractor config
|
||||
'**/karma.conf.js' // karma config
|
||||
'**/karma.conf.js', // karma config
|
||||
'**/.eslintrc.js' // eslint config
|
||||
],
|
||||
optionalDependencies: false,
|
||||
}],
|
||||
@@ -233,7 +234,7 @@ module.exports = {
|
||||
|
||||
// Forbid cyclical dependencies between modules
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
|
||||
'import/no-cycle': ['error', { maxDepth: Infinity }],
|
||||
'import/no-cycle': ['error', { maxDepth: '∞' }],
|
||||
|
||||
// Ensures that there are no useless path segments
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
|
||||
@@ -252,11 +253,21 @@ module.exports = {
|
||||
|
||||
// Reports modules without any exports, or with unused exports
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
|
||||
// TODO: enable, semver-major
|
||||
// TODO: enable once it supports CJS
|
||||
'import/no-unused-modules': ['off', {
|
||||
ignoreExports: [],
|
||||
missingExports: true,
|
||||
unusedExports: true,
|
||||
}],
|
||||
|
||||
// Reports the use of import declarations with CommonJS exports in any module except for the main module.
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-import-module-exports.md
|
||||
'import/no-import-module-exports': ['error', {
|
||||
exceptions: [],
|
||||
}],
|
||||
|
||||
// Use this rule to prevent importing packages through relative paths.
|
||||
// https://github.com/benmosher/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
|
||||
'import/no-relative-packages': 'error',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -77,8 +77,7 @@ module.exports = {
|
||||
'eol-last': ['error', 'always'],
|
||||
|
||||
// https://eslint.org/docs/rules/function-call-argument-newline
|
||||
// TODO: enable, semver-minor, once eslint v6.2 is required (which is a major)
|
||||
'function-call-argument-newline': ['off', 'consistent'],
|
||||
'function-call-argument-newline': ['error', 'consistent'],
|
||||
|
||||
// enforce spacing between functions and their invocations
|
||||
// https://eslint.org/docs/rules/func-call-spacing
|
||||
@@ -101,13 +100,13 @@ module.exports = {
|
||||
// TODO: enable
|
||||
'func-style': ['off', 'expression'],
|
||||
|
||||
// enforce consistent line breaks inside function parentheses
|
||||
// require line breaks inside function parentheses if there are line breaks between parameters
|
||||
// https://eslint.org/docs/rules/function-paren-newline
|
||||
'function-paren-newline': ['error', 'consistent'],
|
||||
'function-paren-newline': ['error', 'multiline-arguments'],
|
||||
|
||||
// Blacklist certain identifiers to prevent them being used
|
||||
// https://eslint.org/docs/rules/id-blacklist
|
||||
'id-blacklist': 'off',
|
||||
// disallow specified identifiers
|
||||
// https://eslint.org/docs/rules/id-denylist
|
||||
'id-denylist': 'off',
|
||||
|
||||
// this option enforces minimum and maximum identifier lengths
|
||||
// (variable names, property names etc.)
|
||||
@@ -288,7 +287,7 @@ module.exports = {
|
||||
// disallow un-paren'd mixes of different operators
|
||||
// https://eslint.org/docs/rules/no-mixed-operators
|
||||
'no-mixed-operators': ['error', {
|
||||
// the list of arthmetic groups disallows mixing `%` and `**`
|
||||
// the list of arithmetic groups disallows mixing `%` and `**`
|
||||
// with other arithmetic operators.
|
||||
groups: [
|
||||
['%', '**'],
|
||||
@@ -313,7 +312,7 @@ module.exports = {
|
||||
|
||||
// disallow multiple empty lines, only one newline at the end, and no new lines at the beginning
|
||||
// https://eslint.org/docs/rules/no-multiple-empty-lines
|
||||
'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 1, maxEOF: 0 }],
|
||||
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
|
||||
|
||||
// disallow negated conditions
|
||||
// https://eslint.org/docs/rules/no-negated-condition
|
||||
@@ -436,8 +435,7 @@ module.exports = {
|
||||
|
||||
// Disallow the use of Math.pow in favor of the ** operator
|
||||
// https://eslint.org/docs/rules/prefer-exponentiation-operator
|
||||
// TODO: enable, semver-major when eslint 5 is dropped
|
||||
'prefer-exponentiation-operator': 'off',
|
||||
'prefer-exponentiation-operator': 'error',
|
||||
|
||||
// Prefer use of an object spread over Object.assign
|
||||
// https://eslint.org/docs/rules/prefer-object-spread
|
||||
@@ -501,7 +499,7 @@ module.exports = {
|
||||
'spaced-comment': ['error', 'always', {
|
||||
line: {
|
||||
exceptions: ['-', '+'],
|
||||
markers: ['=', '!'], // space here to support sprockets directives
|
||||
markers: ['=', '!', '/'], // space here to support sprockets directives, slash for TS /// comments
|
||||
},
|
||||
block: {
|
||||
exceptions: ['-', '+'],
|
||||
|
||||
@@ -16,7 +16,19 @@ module.exports = {
|
||||
'no-label-var': 'error',
|
||||
|
||||
// disallow specific globals
|
||||
'no-restricted-globals': ['error', 'isFinite', 'isNaN'].concat(confusingBrowserGlobals),
|
||||
'no-restricted-globals': [
|
||||
'error',
|
||||
{
|
||||
name: 'isFinite',
|
||||
message:
|
||||
'Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite',
|
||||
},
|
||||
{
|
||||
name: 'isNaN',
|
||||
message:
|
||||
'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
|
||||
},
|
||||
].concat(confusingBrowserGlobals),
|
||||
|
||||
// disallow declaration of variables already declared in the outer scope
|
||||
'no-shadow': 'error',
|
||||
|
||||
49
packages/eslint-config-airbnb-base/whitespace-async.js
Executable file
49
packages/eslint-config-airbnb-base/whitespace-async.js
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
const { ESLint } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
|
||||
async function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new ESLint({
|
||||
useEslintrc: false,
|
||||
baseConfig: config
|
||||
});
|
||||
const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errorsOnly;
|
||||
}
|
||||
|
||||
onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config)));
|
||||
@@ -1,91 +1,55 @@
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
const { CLIEngine } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
if (CLIEngine) {
|
||||
/* eslint no-inner-declarations: 0 */
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
const baseConfig = require('.');
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
|
||||
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
});
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
|
||||
return errorsOnly;
|
||||
function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
|
||||
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errorsOnly;
|
||||
}
|
||||
|
||||
module.exports = onlyErrorOnRules(whitespaceRules, baseConfig);
|
||||
} else {
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'))));
|
||||
}
|
||||
|
||||
module.exports = onlyErrorOnRules([
|
||||
'array-bracket-newline',
|
||||
'array-bracket-spacing',
|
||||
'array-element-newline',
|
||||
'arrow-spacing',
|
||||
'block-spacing',
|
||||
'comma-spacing',
|
||||
'computed-property-spacing',
|
||||
'dot-location',
|
||||
'eol-last',
|
||||
'func-call-spacing',
|
||||
'function-paren-newline',
|
||||
'generator-star-spacing',
|
||||
'implicit-arrow-linebreak',
|
||||
'indent',
|
||||
'key-spacing',
|
||||
'keyword-spacing',
|
||||
'line-comment-position',
|
||||
'linebreak-style',
|
||||
'multiline-ternary',
|
||||
'newline-per-chained-call',
|
||||
'no-irregular-whitespace',
|
||||
'no-mixed-spaces-and-tabs',
|
||||
'no-multi-spaces',
|
||||
'no-regex-spaces',
|
||||
'no-spaced-func',
|
||||
'no-trailing-spaces',
|
||||
'no-whitespace-before-property',
|
||||
'nonblock-statement-body-position',
|
||||
'object-curly-newline',
|
||||
'object-curly-spacing',
|
||||
'object-property-newline',
|
||||
'one-var-declaration-per-line',
|
||||
'operator-linebreak',
|
||||
'padded-blocks',
|
||||
'padding-line-between-statements',
|
||||
'rest-spread-spacing',
|
||||
'semi-spacing',
|
||||
'semi-style',
|
||||
'space-before-blocks',
|
||||
'space-before-function-paren',
|
||||
'space-in-parens',
|
||||
'space-infix-ops',
|
||||
'space-unary-ops',
|
||||
'spaced-comment',
|
||||
'switch-colon-spacing',
|
||||
'template-tag-spacing',
|
||||
'import/newline-after-import',
|
||||
], baseConfig);
|
||||
|
||||
49
packages/eslint-config-airbnb-base/whitespaceRules.js
Normal file
49
packages/eslint-config-airbnb-base/whitespaceRules.js
Normal file
@@ -0,0 +1,49 @@
|
||||
module.exports = [
|
||||
'array-bracket-newline',
|
||||
'array-bracket-spacing',
|
||||
'array-element-newline',
|
||||
'arrow-spacing',
|
||||
'block-spacing',
|
||||
'comma-spacing',
|
||||
'computed-property-spacing',
|
||||
'dot-location',
|
||||
'eol-last',
|
||||
'func-call-spacing',
|
||||
'function-paren-newline',
|
||||
'generator-star-spacing',
|
||||
'implicit-arrow-linebreak',
|
||||
'indent',
|
||||
'key-spacing',
|
||||
'keyword-spacing',
|
||||
'line-comment-position',
|
||||
'linebreak-style',
|
||||
'multiline-ternary',
|
||||
'newline-per-chained-call',
|
||||
'no-irregular-whitespace',
|
||||
'no-mixed-spaces-and-tabs',
|
||||
'no-multi-spaces',
|
||||
'no-regex-spaces',
|
||||
'no-spaced-func',
|
||||
'no-trailing-spaces',
|
||||
'no-whitespace-before-property',
|
||||
'nonblock-statement-body-position',
|
||||
'object-curly-newline',
|
||||
'object-curly-spacing',
|
||||
'object-property-newline',
|
||||
'one-var-declaration-per-line',
|
||||
'operator-linebreak',
|
||||
'padded-blocks',
|
||||
'padding-line-between-statements',
|
||||
'rest-spread-spacing',
|
||||
'semi-spacing',
|
||||
'semi-style',
|
||||
'space-before-blocks',
|
||||
'space-before-function-paren',
|
||||
'space-in-parens',
|
||||
'space-infix-ops',
|
||||
'space-unary-ops',
|
||||
'spaced-comment',
|
||||
'switch-colon-spacing',
|
||||
'template-tag-spacing',
|
||||
'import/newline-after-import'
|
||||
];
|
||||
@@ -1,3 +1,56 @@
|
||||
19.0.4 / 2021-12-25
|
||||
==================
|
||||
- republish to fix #2529
|
||||
|
||||
19.0.3 / 2021-12-24
|
||||
==================
|
||||
- [patch] set `namedComponents` option to match style guide
|
||||
- [deps] update `eslint-plugin-react`
|
||||
|
||||
19.0.2 / 2021-12-02
|
||||
==================
|
||||
- [meta] fix "exports" path (#2525)
|
||||
- [Tests] re-enable tests disabled for the eslint 8 upgrade
|
||||
|
||||
19.0.1 / 2021-11-22
|
||||
==================
|
||||
- [fix] `whitespace`: update to support eslint 8 (#2517)
|
||||
- [deps] update `eslint-plugin-react`
|
||||
- [dev deps] update `tape`
|
||||
|
||||
19.0.0 / 2021-11-10
|
||||
==================
|
||||
- [breaking] support `eslint` 8; drop `eslint` < 7
|
||||
- [patch] Explain why `react/jsx-key` is turned off (#2474)
|
||||
- [fix] bump eslint-plugin-react-hooks peer dependency version (#2356)
|
||||
- [patch] Alphabetize the rules for react-a11y.js (#2407)
|
||||
- [Docs] HTTP => HTTPS (#2489)
|
||||
- [readme] clarify hooks requirement (#2482)
|
||||
- [deps] update `eslint-config-airbnb-base`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, `safe-publish-latest`, `eslint-plugin-import`, `object.entries`
|
||||
- [meta] add `--no-save` to link scripts
|
||||
- [meta] use `prepublishOnly` script for npm 7+
|
||||
- [dev deps] update `@babel/runtime`, `tape`
|
||||
|
||||
18.2.1 / 2020-11-06
|
||||
==================
|
||||
- [patch] remove deprecated `jsx-a11y/accessible-emoji` rule (#2322)
|
||||
- [patch] Fix ignoreNonDOM typo in jsx-a11y/aria-role rule (#2318)
|
||||
- [patch] Fixed `handle` and `on` ordering in `sort-comp` rule (#2287)
|
||||
- [deps] update `eslint-plugin-jsx-a11y`, `eslint-plugin-react`
|
||||
- [deps] update `eslint-config-airbnb-base`, `object.assign`
|
||||
- [dev deps] update `@babel/runtime`, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`
|
||||
|
||||
18.2.0 / 2020-06-18
|
||||
==================
|
||||
- [new] add `eslint` `v7` (#2240)
|
||||
- [minor] Allow using `eslint-plugin-react-hooks` v3 and v4 (#2235, #2207)
|
||||
- [minor] Fix typo in no-multiple-empty-lines rule (#2168)
|
||||
- [patch] set `explicitSpread` to ignore for `react/jsx-props-no-spreading` (#2237)
|
||||
- [patch] relax `eslint-plugin-react-hooks` down to v2.3, due to a controversial change in v2.5
|
||||
- [readme] fix typo (#2194)
|
||||
- [deps] update `eslint-config-airbnb-base`, `eslint-plugin-jsx-a11y`, `eslint-plugin-import`, `eslint-plugin-react`, `babel-preset-airbnb`, `eslint-find-rules`, `in-publish`, `tape`, `object.entries`
|
||||
- [tests] fix for eslint 7
|
||||
|
||||
18.1.0 / 2020-03-12
|
||||
==================
|
||||
- [minor] Support eslint-plugin-react-hooks@2 (#2090)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# eslint-config-airbnb
|
||||
|
||||
[](http://badge.fury.io/js/eslint-config-airbnb)
|
||||
[](https://badge.fury.io/js/eslint-config-airbnb)
|
||||
|
||||
This package provides Airbnb's .eslintrc as an extensible shared config.
|
||||
|
||||
@@ -10,7 +10,9 @@ 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`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, and `eslint-plugin-jsx-a11y`. If you don't need React, see [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
Our default export contains most of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, and `eslint-plugin-jsx-a11y`. Note that it does not enable our React Hooks rules. To enable those, see the [`eslint-config-airbnb/hooks` section](#eslint-config-airbnbhooks).
|
||||
|
||||
If you don't need React, see [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
|
||||
1. Install the correct versions of each package, which are listed by the command:
|
||||
|
||||
@@ -56,9 +58,9 @@ Our default export contains all of our ESLint rules, including ECMAScript 6+ and
|
||||
|
||||
2. Add `"extends": "airbnb"` to your `.eslintrc`
|
||||
|
||||
### eslint-config/airbnb/hooks
|
||||
### eslint-config-airbnb/hooks
|
||||
|
||||
This entry point enables the linting rules for React hooks (requires v16.8+). To use, add `"extends": ["airbnb", "airbnb/hooks"]` to your `.eslintrc`
|
||||
This entry point enables the linting rules for React hooks (requires v16.8+). To use, add `"extends": ["airbnb", "airbnb/hooks"]` to your `.eslintrc`.
|
||||
|
||||
### eslint-config-airbnb/whitespace
|
||||
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb",
|
||||
"version": "18.1.0",
|
||||
"version": "19.0.4",
|
||||
"description": "Airbnb's ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./base": "./base.js",
|
||||
"./hooks": "./hooks.js",
|
||||
"./legacy": "./legacy.js",
|
||||
"./whitespace": "./whitespace.js",
|
||||
"./rules/react": "./rules/react.js",
|
||||
"./rules/react-a11y": "./rules/react-a11y.js",
|
||||
"./rules/react-hooks": "./rules/react-hooks.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"prelint": "eclint check * rules/* test/*",
|
||||
"lint": "eslint .",
|
||||
"pretests-only": "node ./test/requires",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest",
|
||||
"prepublishOnly": "eslint-find-rules --unused && npm test && safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"link:eslint": "cd node_modules/eslint && npm link --production && cd -",
|
||||
"pretravis": "npm run link:eslint && cd ../eslint-config-airbnb-base && npm link eslint && npm install && npm link && cd - && npm link --no-save eslint-config-airbnb-base",
|
||||
"pretravis": "npm run link:eslint && cd ../eslint-config-airbnb-base && npm link --no-save eslint && npm install && npm link && cd - && npm link --no-save eslint-config-airbnb-base",
|
||||
"travis": "npm run --silent tests-only",
|
||||
"posttravis": "npm unlink --no-save eslint-config-airbnb-base eslint >/dev/null &"
|
||||
},
|
||||
@@ -54,34 +66,34 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"dependencies": {
|
||||
"eslint-config-airbnb-base": "^14.1.0",
|
||||
"object.assign": "^4.1.0",
|
||||
"object.entries": "^1.1.1"
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"object.assign": "^4.1.2",
|
||||
"object.entries": "^1.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "^7.8.7",
|
||||
"babel-preset-airbnb": "^4.4.0",
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"babel-preset-airbnb": "^4.5.0",
|
||||
"babel-tape-runner": "^3.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^5.16.0 || ^6.8.0",
|
||||
"eslint-find-rules": "^3.4.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.3",
|
||||
"eslint-plugin-react": "^7.19.0",
|
||||
"eslint-plugin-react-hooks": "^2.5.0 || ^1.7.0",
|
||||
"in-publish": "^2.0.0",
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-find-rules": "^4.0.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||
"eslint-plugin-react": "^7.28.0",
|
||||
"eslint-plugin-react-hooks": "^4.3.0",
|
||||
"in-publish": "^2.0.1",
|
||||
"react": ">= 0.13.0",
|
||||
"safe-publish-latest": "^1.1.4",
|
||||
"tape": "^5.0.0-next.4"
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^5.16.0 || ^6.8.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.3",
|
||||
"eslint-plugin-react": "^7.19.0",
|
||||
"eslint-plugin-react-hooks": "^2.5.0 || ^1.7.0"
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||
"eslint-plugin-react": "^7.28.0",
|
||||
"eslint-plugin-react-hooks": "^4.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
"node": "^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
269
packages/eslint-config-airbnb/rules/react-a11y.js
vendored
269
packages/eslint-config-airbnb/rules/react-a11y.js
vendored
@@ -11,26 +11,10 @@ module.exports = {
|
||||
},
|
||||
|
||||
rules: {
|
||||
// Enforce that anchors have content
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
|
||||
'jsx-a11y/anchor-has-content': ['error', { components: [] }],
|
||||
|
||||
// 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': ['error', { ignoreNonDom: false }],
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
// ensure emoji are accessible
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/accessible-emoji.md
|
||||
// disabled; rule is deprecated
|
||||
'jsx-a11y/accessible-emoji': 'off',
|
||||
|
||||
// Enforce that all elements that require alternative text have meaningful information
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md
|
||||
@@ -42,31 +26,49 @@ module.exports = {
|
||||
'input[type="image"]': [],
|
||||
}],
|
||||
|
||||
// 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': 'error',
|
||||
// Enforce that anchors have content
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
|
||||
'jsx-a11y/anchor-has-content': ['error', { components: [] }],
|
||||
|
||||
// require that JSX labels use "htmlFor"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
|
||||
// deprecated: replaced by `label-has-associated-control` rule
|
||||
'jsx-a11y/label-has-for': ['off', {
|
||||
components: [],
|
||||
required: {
|
||||
every: ['nesting', 'id'],
|
||||
},
|
||||
allowChildren: false,
|
||||
// ensure <a> tags are valid
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/0745af376cdc8686d85a361ce36952b1fb1ccf6e/docs/rules/anchor-is-valid.md
|
||||
'jsx-a11y/anchor-is-valid': ['error', {
|
||||
components: ['Link'],
|
||||
specialLink: ['to'],
|
||||
aspects: ['noHref', 'invalidHref', 'preferButton'],
|
||||
}],
|
||||
|
||||
// Enforce that a label tag has a text label and an associated control.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/b800f40a2a69ad48015ae9226fbe879f946757ed/docs/rules/label-has-associated-control.md
|
||||
'jsx-a11y/label-has-associated-control': ['error', {
|
||||
labelComponents: [],
|
||||
labelAttributes: [],
|
||||
controlComponents: [],
|
||||
assert: 'both',
|
||||
depth: 25
|
||||
// elements with aria-activedescendant must be tabbable
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-activedescendant-has-tabindex.md
|
||||
'jsx-a11y/aria-activedescendant-has-tabindex': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': ['error', { ignoreNonDOM: false }],
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// Ensure the autocomplete attribute is correct and suitable for the form field it is used with
|
||||
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/29c68596b15c4ff0a40daae6d4a2670e36e37d35/docs/rules/autocomplete-valid.md
|
||||
'jsx-a11y/autocomplete-valid': ['off', {
|
||||
inputComponents: [],
|
||||
}],
|
||||
|
||||
// require onClick be accompanied by onKeyUp/onKeyDown/onKeyPress
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md
|
||||
'jsx-a11y/click-events-have-key-events': 'error',
|
||||
|
||||
// Enforce that a control (an interactive element) has a text label.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/control-has-associated-label.md
|
||||
'jsx-a11y/control-has-associated-label': ['error', {
|
||||
@@ -96,36 +98,6 @@ module.exports = {
|
||||
depth: 5,
|
||||
}],
|
||||
|
||||
// require that mouseover/out come with focus/blur, for keyboard-only users
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// require onBlur instead of onChange
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md
|
||||
'jsx-a11y/no-onchange': 'off',
|
||||
|
||||
// Elements with an interactive role and interaction handlers must be focusable
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/interactive-supports-focus.md
|
||||
'jsx-a11y/interactive-supports-focus': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// Enforce tabIndex value is not greater than zero.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md
|
||||
'jsx-a11y/tabindex-no-positive': 'error',
|
||||
|
||||
// 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': ['error', { components: [''] }],
|
||||
@@ -134,35 +106,62 @@ module.exports = {
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/html-has-lang.md
|
||||
'jsx-a11y/html-has-lang': 'error',
|
||||
|
||||
// ensure iframe elements have a unique title
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/iframe-has-title.md
|
||||
'jsx-a11y/iframe-has-title': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// Elements with an interactive role and interaction handlers must be focusable
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/interactive-supports-focus.md
|
||||
'jsx-a11y/interactive-supports-focus': 'error',
|
||||
|
||||
// Enforce that a label tag has a text label and an associated control.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/b800f40a2a69ad48015ae9226fbe879f946757ed/docs/rules/label-has-associated-control.md
|
||||
'jsx-a11y/label-has-associated-control': ['error', {
|
||||
labelComponents: [],
|
||||
labelAttributes: [],
|
||||
controlComponents: [],
|
||||
assert: 'both',
|
||||
depth: 25
|
||||
}],
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// media elements must have captions
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/media-has-caption.md
|
||||
'jsx-a11y/media-has-caption': ['error', {
|
||||
audio: [],
|
||||
video: [],
|
||||
track: [],
|
||||
}],
|
||||
|
||||
// require that mouseover/out come with focus/blur, for keyboard-only users
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// prohibit autoFocus prop
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md
|
||||
'jsx-a11y/no-autofocus': ['error', { ignoreNonDOM: true }],
|
||||
|
||||
// prevent distracting elements, like <marquee> and <blink>
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-distracting-elements.md
|
||||
'jsx-a11y/no-distracting-elements': ['error', {
|
||||
elements: ['marquee', 'blink'],
|
||||
}],
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// require onClick be accompanied by onKeyUp/onKeyDown/onKeyPress
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md
|
||||
'jsx-a11y/click-events-have-key-events': 'error',
|
||||
|
||||
// Enforce that DOM elements without semantic behavior not have interaction handlers
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
|
||||
'jsx-a11y/no-static-element-interactions': ['error', {
|
||||
handlers: [
|
||||
'onClick',
|
||||
'onMouseDown',
|
||||
'onMouseUp',
|
||||
'onKeyPress',
|
||||
'onKeyDown',
|
||||
'onKeyUp',
|
||||
]
|
||||
// WAI-ARIA roles should not be used to convert an interactive element to non-interactive
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-interactive-element-to-noninteractive-role.md
|
||||
'jsx-a11y/no-interactive-element-to-noninteractive-role': ['error', {
|
||||
tr: ['none', 'presentation'],
|
||||
}],
|
||||
|
||||
// A non-interactive element does not support event handlers (mouse and key handlers)
|
||||
@@ -178,40 +177,6 @@ module.exports = {
|
||||
]
|
||||
}],
|
||||
|
||||
// ensure emoji are accessible
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/accessible-emoji.md
|
||||
'jsx-a11y/accessible-emoji': 'error',
|
||||
|
||||
// elements with aria-activedescendant must be tabbable
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-activedescendant-has-tabindex.md
|
||||
'jsx-a11y/aria-activedescendant-has-tabindex': 'error',
|
||||
|
||||
// ensure iframe elements have a unique title
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/iframe-has-title.md
|
||||
'jsx-a11y/iframe-has-title': 'error',
|
||||
|
||||
// prohibit autoFocus prop
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md
|
||||
'jsx-a11y/no-autofocus': ['error', { ignoreNonDOM: true }],
|
||||
|
||||
// ensure HTML elements do not specify redundant ARIA roles
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md
|
||||
'jsx-a11y/no-redundant-roles': 'error',
|
||||
|
||||
// media elements must have captions
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/media-has-caption.md
|
||||
'jsx-a11y/media-has-caption': ['error', {
|
||||
audio: [],
|
||||
video: [],
|
||||
track: [],
|
||||
}],
|
||||
|
||||
// WAI-ARIA roles should not be used to convert an interactive element to non-interactive
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-interactive-element-to-noninteractive-role.md
|
||||
'jsx-a11y/no-interactive-element-to-noninteractive-role': ['error', {
|
||||
tr: ['none', 'presentation'],
|
||||
}],
|
||||
|
||||
// WAI-ARIA roles should not be used to convert a non-interactive element to interactive
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-to-interactive-role.md
|
||||
'jsx-a11y/no-noninteractive-element-to-interactive-role': ['error', {
|
||||
@@ -229,12 +194,58 @@ module.exports = {
|
||||
roles: ['tabpanel'],
|
||||
}],
|
||||
|
||||
// ensure <a> tags are valid
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/0745af376cdc8686d85a361ce36952b1fb1ccf6e/docs/rules/anchor-is-valid.md
|
||||
'jsx-a11y/anchor-is-valid': ['error', {
|
||||
components: ['Link'],
|
||||
specialLink: ['to'],
|
||||
aspects: ['noHref', 'invalidHref', 'preferButton'],
|
||||
// require onBlur instead of onChange
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-onchange.md
|
||||
'jsx-a11y/no-onchange': 'off',
|
||||
|
||||
// ensure HTML elements do not specify redundant ARIA roles
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md
|
||||
'jsx-a11y/no-redundant-roles': 'error',
|
||||
|
||||
// Enforce that DOM elements without semantic behavior not have interaction handlers
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
|
||||
'jsx-a11y/no-static-element-interactions': ['error', {
|
||||
handlers: [
|
||||
'onClick',
|
||||
'onMouseDown',
|
||||
'onMouseUp',
|
||||
'onKeyPress',
|
||||
'onKeyDown',
|
||||
'onKeyUp',
|
||||
]
|
||||
}],
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// 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': 'error',
|
||||
|
||||
// Enforce tabIndex value is not greater than zero.
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/tabindex-no-positive.md
|
||||
'jsx-a11y/tabindex-no-positive': 'error',
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Rules that no longer exist in eslint-plugin-jsx-a11y
|
||||
// ----------------------------------------------------
|
||||
|
||||
// require that JSX labels use "htmlFor"
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
|
||||
// deprecated: replaced by `label-has-associated-control` rule
|
||||
'jsx-a11y/label-has-for': ['off', {
|
||||
components: [],
|
||||
required: {
|
||||
every: ['nesting', 'id'],
|
||||
},
|
||||
allowChildren: false,
|
||||
}],
|
||||
},
|
||||
};
|
||||
|
||||
47
packages/eslint-config-airbnb/rules/react.js
vendored
47
packages/eslint-config-airbnb/rules/react.js
vendored
@@ -91,6 +91,7 @@ module.exports = {
|
||||
|
||||
// Validate JSX has key prop when in array or iterator
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
|
||||
// Turned off because it has too many false positives
|
||||
'react/jsx-key': 'off',
|
||||
|
||||
// Limit maximum of props on a single line in JSX
|
||||
@@ -244,6 +245,7 @@ module.exports = {
|
||||
'static-methods',
|
||||
'instance-variables',
|
||||
'lifecycle',
|
||||
'/^handle.+$/',
|
||||
'/^on.+$/',
|
||||
'getters',
|
||||
'setters',
|
||||
@@ -494,6 +496,7 @@ module.exports = {
|
||||
'react/jsx-props-no-spreading': ['error', {
|
||||
html: 'enforce',
|
||||
custom: 'enforce',
|
||||
explicitSpread: 'ignore',
|
||||
exceptions: [],
|
||||
}],
|
||||
|
||||
@@ -503,8 +506,7 @@ module.exports = {
|
||||
|
||||
// Prevent usage of `javascript:` URLs
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md
|
||||
// TODO: enable, semver-major
|
||||
'react/jsx-no-script-url': ['off', [
|
||||
'react/jsx-no-script-url': ['error', [
|
||||
{
|
||||
name: 'Link',
|
||||
props: ['to'],
|
||||
@@ -513,8 +515,7 @@ module.exports = {
|
||||
|
||||
// Disallow unnecessary fragments
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
|
||||
// TODO: enable, semver-major
|
||||
'react/jsx-no-useless-fragment': 'off',
|
||||
'react/jsx-no-useless-fragment': 'error',
|
||||
|
||||
// Prevent adjacent inline elements not separated by whitespace
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-adjacent-inline-elements.md
|
||||
@@ -523,12 +524,42 @@ module.exports = {
|
||||
|
||||
// Enforce a specific function type for function components
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
|
||||
// TODO: enable! semver-minor, but do it in a major to be safe
|
||||
// TODO: investigate if setting namedComponents to expression vs declaration is problematic
|
||||
'react/function-component-definition': ['off', {
|
||||
namedComponents: 'function-expression',
|
||||
'react/function-component-definition': ['error', {
|
||||
namedComponents: ['function-declaration', 'function-expression'],
|
||||
unnamedComponents: 'function-expression',
|
||||
}],
|
||||
|
||||
// Enforce a new line after jsx elements and expressions
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/e2eaadae316f9506d163812a09424eb42698470a/docs/rules/jsx-newline.md
|
||||
'react/jsx-newline': 'off',
|
||||
|
||||
// Prevent react contexts from taking non-stable values
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/e2eaadae316f9506d163812a09424eb42698470a/docs/rules/jsx-no-constructed-context-values.md
|
||||
'react/jsx-no-constructed-context-values': 'error',
|
||||
|
||||
// Prevent creating unstable components inside components
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/c2a790a3472eea0f6de984bdc3ee2a62197417fb/docs/rules/no-unstable-nested-components.md
|
||||
'react/no-unstable-nested-components': 'error',
|
||||
|
||||
// Enforce that namespaces are not used in React elements
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/8785c169c25b09b33c95655bf508cf46263bc53f/docs/rules/no-namespace.md
|
||||
'react/no-namespace': 'error',
|
||||
|
||||
// Prefer exact proptype definitions
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/8785c169c25b09b33c95655bf508cf46263bc53f/docs/rules/prefer-exact-props.md
|
||||
'react/prefer-exact-props': 'error',
|
||||
|
||||
// Lifecycle methods should be methods on the prototype, not class fields
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-arrow-function-lifecycle.md
|
||||
'react/no-arrow-function-lifecycle': 'error',
|
||||
|
||||
// Prevent usage of invalid attributes
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-invalid-html-attribute.md
|
||||
'react/no-invalid-html-attribute': 'error',
|
||||
|
||||
// Prevent declaring unused methods of component class
|
||||
// https://github.com/yannickcr/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-unused-class-component-methods.md
|
||||
'react/no-unused-class-component-methods': 'error',
|
||||
},
|
||||
|
||||
settings: {
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
import test from 'tape';
|
||||
import { CLIEngine } from 'eslint';
|
||||
import { CLIEngine, ESLint } from 'eslint';
|
||||
import eslintrc from '..';
|
||||
import reactRules from '../rules/react';
|
||||
import reactA11yRules from '../rules/react-a11y';
|
||||
|
||||
const cli = new CLIEngine({
|
||||
const rules = {
|
||||
// It is okay to import devDependencies in tests.
|
||||
'import/no-extraneous-dependencies': [2, { devDependencies: true }],
|
||||
// this doesn't matter for tests
|
||||
'lines-between-class-members': 0,
|
||||
// otherwise we need some junk in our fixture code
|
||||
'react/no-unused-class-component-methods': 0,
|
||||
};
|
||||
const cli = new (CLIEngine || ESLint)({
|
||||
useEslintrc: false,
|
||||
baseConfig: eslintrc,
|
||||
|
||||
rules: {
|
||||
// It is okay to import devDependencies in tests.
|
||||
'import/no-extraneous-dependencies': [2, { devDependencies: true }],
|
||||
// this doesn't matter for tests
|
||||
'lines-between-class-members': 0,
|
||||
},
|
||||
...(CLIEngine ? { rules } : { overrideConfig: { rules } }),
|
||||
});
|
||||
|
||||
function lint(text) {
|
||||
async function lint(text) {
|
||||
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles
|
||||
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeontext
|
||||
const linter = cli.executeOnText(text);
|
||||
return linter.results[0];
|
||||
const linter = CLIEngine ? cli.executeOnText(text) : await cli.lintText(text);
|
||||
return (CLIEngine ? linter.results : linter)[0];
|
||||
}
|
||||
|
||||
function wrapComponent(body) {
|
||||
return `
|
||||
return `\
|
||||
import React from 'react';
|
||||
|
||||
export default class MyComponent extends React.Component {
|
||||
@@ -33,17 +35,18 @@ ${body}}
|
||||
`;
|
||||
}
|
||||
|
||||
test('validate react prop order', (t) => {
|
||||
test('validate react methods 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.plan(3);
|
||||
const result = lint(wrapComponent(`
|
||||
t.test('passes a good component', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
componentDidMount() {}
|
||||
handleSubmit() {}
|
||||
onButtonAClick() {}
|
||||
setFoo() {}
|
||||
getFoo() {}
|
||||
setBar() {}
|
||||
@@ -57,9 +60,8 @@ test('validate react prop order', (t) => {
|
||||
t.notOk(result.errorCount, 'no errors');
|
||||
});
|
||||
|
||||
t.test('order: when random method is first', (t) => {
|
||||
t.plan(2);
|
||||
const result = lint(wrapComponent(`
|
||||
t.test('order: when random method is first', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
someMethod() {}
|
||||
componentDidMount() {}
|
||||
setFoo() {}
|
||||
@@ -73,9 +75,8 @@ test('validate react prop order', (t) => {
|
||||
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
|
||||
});
|
||||
|
||||
t.test('order: when random method after lifecycle methods', (t) => {
|
||||
t.plan(2);
|
||||
const result = lint(wrapComponent(`
|
||||
t.test('order: when random method after lifecycle methods', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
componentDidMount() {}
|
||||
someMethod() {}
|
||||
setFoo() {}
|
||||
@@ -88,4 +89,44 @@ test('validate react prop order', (t) => {
|
||||
t.ok(result.errorCount, 'fails');
|
||||
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
|
||||
});
|
||||
|
||||
t.test('order: when handler method with `handle` prefix after method with `on` prefix', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
componentDidMount() {}
|
||||
onButtonAClick() {}
|
||||
handleSubmit() {}
|
||||
setFoo() {}
|
||||
getFoo() {}
|
||||
render() { return <div />; }
|
||||
`));
|
||||
|
||||
t.ok(result.errorCount, 'fails');
|
||||
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
|
||||
});
|
||||
|
||||
t.test('order: when lifecycle methods after event handler methods', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
handleSubmit() {}
|
||||
componentDidMount() {}
|
||||
setFoo() {}
|
||||
getFoo() {}
|
||||
render() { return <div />; }
|
||||
`));
|
||||
|
||||
t.ok(result.errorCount, 'fails');
|
||||
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
|
||||
});
|
||||
|
||||
t.test('order: when event handler methods after getters and setters', async (t) => {
|
||||
const result = await lint(wrapComponent(`
|
||||
componentDidMount() {}
|
||||
setFoo() {}
|
||||
getFoo() {}
|
||||
handleSubmit() {}
|
||||
render() { return <div />; }
|
||||
`));
|
||||
|
||||
t.ok(result.errorCount, 'fails');
|
||||
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
|
||||
});
|
||||
});
|
||||
|
||||
49
packages/eslint-config-airbnb/whitespace-async.js
Executable file
49
packages/eslint-config-airbnb/whitespace-async.js
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
const { ESLint } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
|
||||
async function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new ESLint({
|
||||
useEslintrc: false,
|
||||
baseConfig: config
|
||||
});
|
||||
const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errorsOnly;
|
||||
}
|
||||
|
||||
onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config)));
|
||||
@@ -1,105 +1,55 @@
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
const { CLIEngine } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
if (CLIEngine) {
|
||||
/* eslint no-inner-declarations: 0 */
|
||||
const assign = require('object.assign');
|
||||
const entries = require('object.entries');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
const baseConfig = require('.');
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
|
||||
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
});
|
||||
if (typeof ruleConfig === 'number') {
|
||||
return severities[ruleConfig];
|
||||
}
|
||||
return ruleConfig;
|
||||
}
|
||||
|
||||
return errorsOnly;
|
||||
function onlyErrorOnRules(rulesToError, config) {
|
||||
const errorsOnly = assign({}, config);
|
||||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
|
||||
const baseRules = cli.getConfigForFile(require.resolve('./')).rules;
|
||||
|
||||
entries(baseRules).forEach((rule) => {
|
||||
const ruleName = rule[0];
|
||||
const ruleConfig = rule[1];
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
} else {
|
||||
errorsOnly.rules[ruleName] = 'warn';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errorsOnly;
|
||||
}
|
||||
|
||||
module.exports = onlyErrorOnRules(whitespaceRules, baseConfig);
|
||||
} else {
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'))));
|
||||
}
|
||||
|
||||
module.exports = onlyErrorOnRules([
|
||||
'array-bracket-newline',
|
||||
'array-bracket-spacing',
|
||||
'array-element-newline',
|
||||
'arrow-spacing',
|
||||
'block-spacing',
|
||||
'comma-spacing',
|
||||
'computed-property-spacing',
|
||||
'dot-location',
|
||||
'eol-last',
|
||||
'func-call-spacing',
|
||||
'function-paren-newline',
|
||||
'generator-star-spacing',
|
||||
'implicit-arrow-linebreak',
|
||||
'indent',
|
||||
'key-spacing',
|
||||
'keyword-spacing',
|
||||
'line-comment-position',
|
||||
'linebreak-style',
|
||||
'multiline-ternary',
|
||||
'newline-per-chained-call',
|
||||
'no-irregular-whitespace',
|
||||
'no-mixed-spaces-and-tabs',
|
||||
'no-multi-spaces',
|
||||
'no-regex-spaces',
|
||||
'no-spaced-func',
|
||||
'no-trailing-spaces',
|
||||
'no-whitespace-before-property',
|
||||
'nonblock-statement-body-position',
|
||||
'object-curly-newline',
|
||||
'object-curly-spacing',
|
||||
'object-property-newline',
|
||||
'one-var-declaration-per-line',
|
||||
'operator-linebreak',
|
||||
'padded-blocks',
|
||||
'padding-line-between-statements',
|
||||
'rest-spread-spacing',
|
||||
'semi-spacing',
|
||||
'semi-style',
|
||||
'space-before-blocks',
|
||||
'space-before-function-paren',
|
||||
'space-in-parens',
|
||||
'space-infix-ops',
|
||||
'space-unary-ops',
|
||||
'spaced-comment',
|
||||
'switch-colon-spacing',
|
||||
'template-tag-spacing',
|
||||
'import/newline-after-import',
|
||||
// eslint-plugin-react rules
|
||||
'react/jsx-child-element-spacing',
|
||||
'react/jsx-closing-bracket-location',
|
||||
'react/jsx-closing-tag-location',
|
||||
'react/jsx-curly-spacing',
|
||||
'react/jsx-equals-spacing',
|
||||
'react/jsx-first-prop-newline',
|
||||
'react/jsx-indent',
|
||||
'react/jsx-indent-props',
|
||||
'react/jsx-max-props-per-line',
|
||||
'react/jsx-one-expression-per-line',
|
||||
'react/jsx-space-before-closing',
|
||||
'react/jsx-tag-spacing',
|
||||
'react/jsx-wrap-multilines',
|
||||
], baseConfig);
|
||||
|
||||
64
packages/eslint-config-airbnb/whitespaceRules.js
Normal file
64
packages/eslint-config-airbnb/whitespaceRules.js
Normal file
@@ -0,0 +1,64 @@
|
||||
module.exports = [
|
||||
'array-bracket-newline',
|
||||
'array-bracket-spacing',
|
||||
'array-element-newline',
|
||||
'arrow-spacing',
|
||||
'block-spacing',
|
||||
'comma-spacing',
|
||||
'computed-property-spacing',
|
||||
'dot-location',
|
||||
'eol-last',
|
||||
'func-call-spacing',
|
||||
'function-paren-newline',
|
||||
'generator-star-spacing',
|
||||
'implicit-arrow-linebreak',
|
||||
'indent',
|
||||
'key-spacing',
|
||||
'keyword-spacing',
|
||||
'line-comment-position',
|
||||
'linebreak-style',
|
||||
'multiline-ternary',
|
||||
'newline-per-chained-call',
|
||||
'no-irregular-whitespace',
|
||||
'no-mixed-spaces-and-tabs',
|
||||
'no-multi-spaces',
|
||||
'no-regex-spaces',
|
||||
'no-spaced-func',
|
||||
'no-trailing-spaces',
|
||||
'no-whitespace-before-property',
|
||||
'nonblock-statement-body-position',
|
||||
'object-curly-newline',
|
||||
'object-curly-spacing',
|
||||
'object-property-newline',
|
||||
'one-var-declaration-per-line',
|
||||
'operator-linebreak',
|
||||
'padded-blocks',
|
||||
'padding-line-between-statements',
|
||||
'rest-spread-spacing',
|
||||
'semi-spacing',
|
||||
'semi-style',
|
||||
'space-before-blocks',
|
||||
'space-before-function-paren',
|
||||
'space-in-parens',
|
||||
'space-infix-ops',
|
||||
'space-unary-ops',
|
||||
'spaced-comment',
|
||||
'switch-colon-spacing',
|
||||
'template-tag-spacing',
|
||||
'import/newline-after-import',
|
||||
|
||||
// eslint-plugin-react rules
|
||||
'react/jsx-child-element-spacing',
|
||||
'react/jsx-closing-bracket-location',
|
||||
'react/jsx-closing-tag-location',
|
||||
'react/jsx-curly-spacing',
|
||||
'react/jsx-equals-spacing',
|
||||
'react/jsx-first-prop-newline',
|
||||
'react/jsx-indent',
|
||||
'react/jsx-indent-props',
|
||||
'react/jsx-max-props-per-line',
|
||||
'react/jsx-one-expression-per-line',
|
||||
'react/jsx-space-before-closing',
|
||||
'react/jsx-tag-spacing',
|
||||
'react/jsx-wrap-multilines',
|
||||
];
|
||||
@@ -214,6 +214,27 @@ This style guide is mostly based on the standards that are currently prevalent i
|
||||
|
||||
// good
|
||||
{showButton && <Button />}
|
||||
|
||||
// good
|
||||
{someReallyLongConditional
|
||||
&& anotherLongConditional
|
||||
&& (
|
||||
<Foo
|
||||
superLongParam="bar"
|
||||
anotherSuperLongParam="baz"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// good
|
||||
{someConditional ? (
|
||||
<Foo />
|
||||
) : (
|
||||
<Foo
|
||||
superLongParam="bar"
|
||||
anotherSuperLongParam="baz"
|
||||
/>
|
||||
)}
|
||||
```
|
||||
|
||||
## Quotes
|
||||
@@ -267,7 +288,7 @@ This style guide is mostly based on the standards that are currently prevalent i
|
||||
|
||||
## Props
|
||||
|
||||
- Always use camelCase for prop names.
|
||||
- Always use camelCase for prop names, or PascalCase if the prop value is a React component.
|
||||
|
||||
```jsx
|
||||
// bad
|
||||
@@ -280,6 +301,7 @@ This style guide is mostly based on the standards that are currently prevalent i
|
||||
<Foo
|
||||
userName="hello"
|
||||
phoneNumber={12345678}
|
||||
Component={SomeComponent}
|
||||
/>
|
||||
```
|
||||
|
||||
@@ -645,7 +667,8 @@ We don’t recommend using indexes for keys if the order of items may change.
|
||||
1. `componentWillUpdate`
|
||||
1. `componentDidUpdate`
|
||||
1. `componentWillUnmount`
|
||||
1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
|
||||
1. *event handlers starting with 'handle'* like `handleSubmit()` or `handleChangeDescription()`
|
||||
1. *event handlers starting with 'on'* like `onClickSubmit()` or `onChangeDescription()`
|
||||
1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
|
||||
1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
|
||||
1. `render`
|
||||
@@ -718,7 +741,7 @@ We don’t recommend using indexes for keys if the order of items may change.
|
||||
|
||||
This JSX/React style guide is also available in other languages:
|
||||
|
||||
-  **Chinese (Simplified)**: [JasonBoy/javascript](https://github.com/JasonBoy/javascript/tree/master/react)
|
||||
-  **Chinese (Simplified)**: [jhcccc/javascript](https://github.com/jhcccc/javascript/tree/master/react)
|
||||
-  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript/tree/master/react)
|
||||
-  **Español**: [agrcrobles/javascript](https://github.com/agrcrobles/javascript/tree/master/react)
|
||||
-  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide/tree/master/react)
|
||||
|
||||
Reference in New Issue
Block a user