mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 15:37:55 -05:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2ef178a2 | ||
|
|
99ade7a6b1 | ||
|
|
11f986fdc7 | ||
|
|
6499695ac1 | ||
|
|
f45bd1ebc0 | ||
|
|
e6080c7bee | ||
|
|
b912288e4b | ||
|
|
39b970f702 | ||
|
|
d1705c389e | ||
|
|
e6f292286b | ||
|
|
7a8f568769 | ||
|
|
c25bce83be | ||
|
|
f20eca9f64 | ||
|
|
932951adc2 | ||
|
|
5f019b1b11 | ||
|
|
b23992033c | ||
|
|
09adc22031 | ||
|
|
51a37d0fa5 | ||
|
|
0681a43e0a | ||
|
|
55899b57a6 | ||
|
|
e95b1f2754 | ||
|
|
11ab37144b | ||
|
|
46ae3e2256 | ||
|
|
cb191776db | ||
|
|
cda44dad40 | ||
|
|
2fc5e2d52c | ||
|
|
749f4c2bd0 | ||
|
|
4aee38f1e7 | ||
|
|
18a08b862b | ||
|
|
fd77bbebb7 | ||
|
|
7916d6f538 | ||
|
|
01f046dc05 |
3
CODE_OF_CONDUCT.md
Normal file
3
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Airbnb has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full Code of Conduct text](https://airbnb.io/codeofconduct/) so that you can understand what actions will and will not be tolerated. Report violations to the maintainers of this project or to [opensource-conduct@airbnb.com](mailto:opensource-conduct@airbnb.com).
|
||||
|
||||
Reports sent to [opensource-conduct@airbnb.com](mailto:opensource-conduct@airbnb.com) are received by Airbnb's open source code of conduct moderation team, which is composed of Airbnb employees. All communications are private and confidential.
|
||||
105
README.md
105
README.md
@@ -296,7 +296,7 @@ Other Style Guides
|
||||
<a name="objects--prototype-builtins"></a>
|
||||
- [3.7](#objects--prototype-builtins) Do not call `Object.prototype` methods directly, such as `hasOwnProperty`, `propertyIsEnumerable`, and `isPrototypeOf`. eslint: [`no-prototype-builtins`](https://eslint.org/docs/rules/no-prototype-builtins)
|
||||
|
||||
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`).
|
||||
> Why? These methods may be shadowed by properties on the object in question - consider `{ hasOwnProperty: false }` - or, the object may be a null object (`Object.create(null)`). In modern browsers that support ES2022, or with a polyfill such as <https://npmjs.com/object.hasown>, `Object.hasOwn` can also be used as an alternative to `Object.prototype.hasOwnProperty.call`.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -305,9 +305,13 @@ Other Style Guides
|
||||
// good
|
||||
console.log(Object.prototype.hasOwnProperty.call(object, key));
|
||||
|
||||
// best
|
||||
// better
|
||||
const has = Object.prototype.hasOwnProperty; // cache the lookup once, in module scope.
|
||||
console.log(has.call(object, key));
|
||||
|
||||
// best
|
||||
console.log(Object.hasOwn(object, key)); // only supported in browsers that support ES2022
|
||||
|
||||
/* or */
|
||||
import has from 'has'; // https://www.npmjs.com/package/has
|
||||
console.log(has(object, key));
|
||||
@@ -636,7 +640,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="strings--eval"></a><a name="6.5"></a>
|
||||
- [6.4](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. eslint: [`no-eval`](https://eslint.org/docs/rules/no-eval)
|
||||
- [6.4](#strings--eval) Never use `eval()` on a string; it opens too many vulnerabilities. eslint: [`no-eval`](https://eslint.org/docs/rules/no-eval)
|
||||
|
||||
<a name="strings--escaping"></a>
|
||||
- [6.5](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](https://eslint.org/docs/rules/no-useless-escape)
|
||||
@@ -657,7 +661,7 @@ Other Style Guides
|
||||
## Functions
|
||||
|
||||
<a name="functions--declarations"></a><a name="7.1"></a>
|
||||
- [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](https://eslint.org/docs/rules/func-style)
|
||||
- [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](https://eslint.org/docs/rules/func-style), [`func-names`](https://eslint.org/docs/latest/rules/func-names)
|
||||
|
||||
> Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to explicitly name the expression, regardless of whether or not the name is inferred from the containing variable (which is often the case in modern browsers or when using compilers such as Babel). This eliminates any assumptions made about the Error’s call stack. ([Discussion](https://github.com/airbnb/javascript/issues/794))
|
||||
|
||||
@@ -1961,6 +1965,56 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
<a name="no-use-before-define"></a>
|
||||
- [14.5](#no-use-before-define) Variables, classes, and functions should be defined before they can be used. eslint: [`no-use-before-define`](https://eslint.org/docs/latest/rules/no-use-before-define)
|
||||
|
||||
> Why? When variables, classes, or functions are declared after being used, it can harm readability since a reader won't know what a thing that's referenced is. It's much clearer for a reader to first encounter the source of a thing (whether imported from another module, or defined in the file) before encountering a use of the thing.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
|
||||
// Variable a is being used before it is being defined.
|
||||
console.log(a); // this will be undefined, since while the declaration is hoisted, the initialization is not
|
||||
var a = 10;
|
||||
|
||||
// Function fun is being called before being defined.
|
||||
fun();
|
||||
function fun() {}
|
||||
|
||||
// Class A is being used before being defined.
|
||||
new A(); // ReferenceError: Cannot access 'A' before initialization
|
||||
class A {
|
||||
}
|
||||
|
||||
// `let` and `const` are hoisted, but they don't have a default initialization.
|
||||
// The variables 'a' and 'b' are in a Temporal Dead Zone where JavaScript
|
||||
// knows they exist (declaration is hoisted) but they are not accessible
|
||||
// (as they are not yet initialized).
|
||||
|
||||
console.log(a); // ReferenceError: Cannot access 'a' before initialization
|
||||
console.log(b); // ReferenceError: Cannot access 'b' before initialization
|
||||
let a = 10;
|
||||
const b = 5;
|
||||
|
||||
|
||||
// good
|
||||
|
||||
var a = 10;
|
||||
console.log(a); // 10
|
||||
|
||||
function fun() {}
|
||||
fun();
|
||||
|
||||
class A {
|
||||
}
|
||||
new A();
|
||||
|
||||
let a = 10;
|
||||
const b = 5;
|
||||
console.log(a); // 10
|
||||
console.log(b); // 5
|
||||
```
|
||||
|
||||
- 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)**
|
||||
@@ -2023,7 +2077,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="comparison--moreinfo"></a><a name="15.4"></a>
|
||||
- [15.4](#comparison--moreinfo) For more information see [Truth Equality and JavaScript](https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
|
||||
- [15.4](#comparison--moreinfo) For more information see [Truth, Equality, and JavaScript](https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
|
||||
|
||||
<a name="comparison--switch-blocks"></a><a name="15.5"></a>
|
||||
- [15.5](#comparison--switch-blocks) Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`). eslint: [`no-case-declarations`](https://eslint.org/docs/rules/no-case-declarations)
|
||||
@@ -2148,6 +2202,33 @@ Other Style Guides
|
||||
const bar = a + (b / c) * d;
|
||||
```
|
||||
|
||||
<a name="nullish-coalescing-operator"></a>
|
||||
- [15.9](#nullish-coalescing-operator) The nullish coalescing operator (`??`) is a logical operator that returns its right-hand side operand when its left-hand side operand is `null` or `undefined`. Otherwise, it returns the left-hand side operand.
|
||||
|
||||
> Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const value = 0 ?? 'default';
|
||||
// returns 0, not 'default'
|
||||
|
||||
// bad
|
||||
const value = '' ?? 'default';
|
||||
// returns '', not 'default'
|
||||
|
||||
// good
|
||||
const value = null ?? 'default';
|
||||
// returns 'default'
|
||||
|
||||
// good
|
||||
const user = {
|
||||
name: 'John',
|
||||
age: null
|
||||
};
|
||||
const age = user.age ?? 18;
|
||||
// returns 18
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Blocks
|
||||
@@ -3325,7 +3406,7 @@ Other Style Guides
|
||||
this.firstName = 'Panda';
|
||||
|
||||
// good, in environments where WeakMaps are available
|
||||
// see https://kangax.github.io/compat-table/es6/#test-WeakMap
|
||||
// see https://compat-table.github.io/compat-table/es6/#test-WeakMap
|
||||
const firstNames = new WeakMap();
|
||||
firstNames.set(this, 'Panda');
|
||||
```
|
||||
@@ -3665,7 +3746,7 @@ Other Style Guides
|
||||
## ECMAScript 5 Compatibility
|
||||
|
||||
<a name="es5-compat--kangax"></a><a name="26.1"></a>
|
||||
- [27.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)’s ES5 [compatibility table](https://kangax.github.io/es5-compat-table/).
|
||||
- [27.1](#es5-compat--kangax) Refer to [Kangax](https://twitter.com/kangax/)’s ES5 [compatibility table](https://compat-table.github.io/compat-table/es5/).
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
@@ -3779,8 +3860,8 @@ Other Style Guides
|
||||
|
||||
- [Latest ECMA spec](https://tc39.github.io/ecma262/)
|
||||
- [ExploringJS](https://exploringjs.com/)
|
||||
- [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/)
|
||||
- [Comprehensive Overview of ES6 Features](http://es6-features.org/)
|
||||
- [ES6 Compatibility Table](https://compat-table.github.io/compat-table/es6/)
|
||||
- [Comprehensive Overview of ES6 Features](https://web.archive.org/web/20240404212626/http://es6-features.org/)
|
||||
- [JavaScript Roadmap](https://roadmap.sh/javascript)
|
||||
|
||||
**Read This**
|
||||
@@ -3871,7 +3952,6 @@ Other Style Guides
|
||||
- **Axept**: [axept/javascript](https://github.com/axept/javascript)
|
||||
- **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
|
||||
- **Bisk**: [bisk](https://github.com/Bisk/)
|
||||
- **Bonhomme**: [bonhommeparis/javascript](https://github.com/bonhommeparis/javascript)
|
||||
- **Brainshark**: [brainshark/javascript](https://github.com/brainshark/javascript)
|
||||
- **CaseNine**: [CaseNine/javascript](https://github.com/CaseNine/javascript)
|
||||
- **Cerner**: [Cerner](https://github.com/cerner/)
|
||||
@@ -3884,7 +3964,6 @@ Other Style Guides
|
||||
- **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)
|
||||
- **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)
|
||||
@@ -3897,10 +3976,10 @@ Other Style Guides
|
||||
- **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
|
||||
- **Grupo-Abraxas**: [Grupo-Abraxas/javascript](https://github.com/Grupo-Abraxas/javascript)
|
||||
- **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)
|
||||
- **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)
|
||||
- **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)
|
||||
- **ILIAS**: [ILIAS](https://github.com/ILIAS-eLearning/ILIAS)
|
||||
- **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)
|
||||
- **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
|
||||
@@ -3923,7 +4002,6 @@ Other Style Guides
|
||||
- **Pier 1**: [Pier1/javascript](https://github.com/pier1/javascript)
|
||||
- **Qotto**: [Qotto/javascript-style-guide](https://github.com/Qotto/javascript-style-guide)
|
||||
- **React**: [reactjs.org/docs/how-to-contribute.html#style-guide](https://reactjs.org/docs/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)
|
||||
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
|
||||
@@ -3947,6 +4025,7 @@ Other Style Guides
|
||||
- **WeBox Studio**: [weboxstudio/javascript](https://github.com/weboxstudio/javascript)
|
||||
- **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript)
|
||||
- **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
|
||||
- **Zit Software**: [zit-software/javascript](https://github.com/zit-software/javascript)
|
||||
- **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
- Use an underscore for modifiers to other styles.
|
||||
|
||||
> Why? Similar to BEM, this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes.
|
||||
> Why? Similar to [BEM](https://getbem.com/introduction/), this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes.
|
||||
|
||||
```js
|
||||
// bad
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"markdownlint": "^0.28.2",
|
||||
"markdownlint-cli": "^0.34.0"
|
||||
"markdownlint": "^0.29.0",
|
||||
"markdownlint-cli": "^0.35.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,26 +68,25 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "^7.21.5",
|
||||
"@babel/runtime": "^7.25.6",
|
||||
"babel-preset-airbnb": "^4.5.0",
|
||||
"babel-tape-runner": "^3.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-find-rules": "^4.1.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-import": "^2.30.0",
|
||||
"in-publish": "^2.0.1",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.6.3"
|
||||
"tape": "^5.9.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-plugin-import": "^2.27.5"
|
||||
"eslint-plugin-import": "^2.30.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10.12.0 || >=12.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"confusing-browser-globals": "^1.0.11",
|
||||
"object.entries": "^1.1.6"
|
||||
"confusing-browser-globals": "^1.0.11"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,11 @@ module.exports = {
|
||||
// https://eslint.org/docs/rules/no-nonoctal-decimal-escape
|
||||
'no-nonoctal-decimal-escape': 'error',
|
||||
|
||||
// Disallow calls to the Object constructor without an argument
|
||||
// https://eslint.org/docs/latest/rules/no-object-constructor
|
||||
// TODO: enable, semver-major
|
||||
'no-object-constructor': 'off',
|
||||
|
||||
// disallow use of (old style) octal literals
|
||||
// https://eslint.org/docs/rules/no-octal
|
||||
'no-octal': 'error',
|
||||
|
||||
@@ -28,7 +28,10 @@ module.exports = {
|
||||
message:
|
||||
'Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan',
|
||||
},
|
||||
].concat(confusingBrowserGlobals),
|
||||
].concat(confusingBrowserGlobals.map((g) => ({
|
||||
name: g,
|
||||
message: `Use window.${g} instead. https://github.com/facebook/create-react-app/blob/HEAD/packages/confusing-browser-globals/README.md`,
|
||||
}))),
|
||||
|
||||
// disallow declaration of variables already declared in the outer scope
|
||||
'no-shadow': 'error',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const entries = require('object.entries');
|
||||
const { isArray } = Array;
|
||||
const { entries } = Object;
|
||||
const { ESLint } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
@@ -9,7 +10,7 @@ const whitespaceRules = require('./whitespaceRules');
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
@@ -32,7 +33,7 @@ async function onlyErrorOnRules(rulesToError, config) {
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
const { isArray } = Array;
|
||||
const { entries } = Object;
|
||||
const { CLIEngine } = require('eslint');
|
||||
|
||||
if (CLIEngine) {
|
||||
/* eslint no-inner-declarations: 0 */
|
||||
const entries = require('object.entries');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const baseConfig = require('.');
|
||||
@@ -12,7 +13,7 @@ if (CLIEngine) {
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
@@ -32,7 +33,7 @@ if (CLIEngine) {
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
@@ -50,5 +51,11 @@ if (CLIEngine) {
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'))));
|
||||
// NOTE: ESLint adds runtime statistics to the output (so it's no longer JSON) if TIMING is set
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'), {
|
||||
env: {
|
||||
...process.env,
|
||||
TIMING: undefined,
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
@@ -66,31 +66,30 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"dependencies": {
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"object.entries": "^1.1.6"
|
||||
"eslint-config-airbnb-base": "^15.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/runtime": "^7.21.5",
|
||||
"@babel/runtime": "^7.25.6",
|
||||
"babel-preset-airbnb": "^4.5.0",
|
||||
"babel-tape-runner": "^3.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-find-rules": "^4.1.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-import": "^2.30.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.10.0",
|
||||
"eslint-plugin-react": "^7.36.1",
|
||||
"eslint-plugin-react-hooks": "^5.1.0",
|
||||
"in-publish": "^2.0.1",
|
||||
"react": ">= 0.13.0",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.6.3"
|
||||
"tape": "^5.9.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^7.32.0 || ^8.2.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0"
|
||||
"eslint-plugin-import": "^2.30.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.10.0",
|
||||
"eslint-plugin-react": "^7.36.1",
|
||||
"eslint-plugin-react-hooks": "^5.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10.12.0 || ^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
|
||||
@@ -192,6 +192,7 @@ module.exports = {
|
||||
'jsx-a11y/no-noninteractive-tabindex': ['error', {
|
||||
tags: [],
|
||||
roles: ['tabpanel'],
|
||||
allowExpressionValues: true,
|
||||
}],
|
||||
|
||||
// require onBlur instead of onChange
|
||||
@@ -200,7 +201,9 @@ module.exports = {
|
||||
|
||||
// ensure HTML elements do not specify redundant ARIA roles
|
||||
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md
|
||||
'jsx-a11y/no-redundant-roles': 'error',
|
||||
'jsx-a11y/no-redundant-roles': ['error', {
|
||||
nav: ['navigation'],
|
||||
}],
|
||||
|
||||
// Enforce that DOM elements without semantic behavior not have interaction handlers
|
||||
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
|
||||
|
||||
17
packages/eslint-config-airbnb/rules/react.js
vendored
17
packages/eslint-config-airbnb/rules/react.js
vendored
@@ -46,6 +46,13 @@ module.exports = {
|
||||
],
|
||||
}],
|
||||
|
||||
// This rule enforces onChange or readonly attribute for checked property of input elements.
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/checked-requires-onchange-or-readonly.md
|
||||
'react/checked-requires-onchange-or-readonly': ['off', {
|
||||
ignoreMissingProperties: false,
|
||||
ignoreExclusiveCheckedAttribute: false
|
||||
}],
|
||||
|
||||
// Prevent missing displayName in a React component definition
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/display-name.md
|
||||
'react/display-name': ['off', { ignoreTranspilerName: false }],
|
||||
@@ -576,17 +583,23 @@ module.exports = {
|
||||
// TODO: semver-major, enable
|
||||
'react/jsx-no-leaked-render': 'off',
|
||||
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/66b58dd4864678eb869a7bf434c72ff7ac530eb1/docs/rules/no-object-type-as-default-prop.md
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/66b58dd4864678eb869a7bf434c72ff7ac530eb1/docs/rules/no-object-type-as-default-prop.md
|
||||
// TODO: semver-major, enable
|
||||
'react/no-object-type-as-default-prop': 'off',
|
||||
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/66b58dd4864678eb869a7bf434c72ff7ac530eb1/docs/rules/sort-default-props.md
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/66b58dd4864678eb869a7bf434c72ff7ac530eb1/docs/rules/sort-default-props.md
|
||||
// TODO: semver-major, enable?
|
||||
'react/sort-default-props': ['off', {
|
||||
ignoreCase: false
|
||||
}],
|
||||
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/9668ee0762acd5c23f53cd3a372e2d8d9563944d/docs/rules/forward-ref-uses-ref.md
|
||||
// TODO: semver-major, enable
|
||||
'react/forward-ref-uses-ref': 'off',
|
||||
|
||||
// https://github.com/jsx-eslint/eslint-plugin-react/blob/9668ee0762acd5c23f53cd3a372e2d8d9563944d/docs/rules/jsx-props-no-spread-multi.md
|
||||
// TODO: semver-major, enable
|
||||
'react/jsx-props-no-spread-multi': 'off',
|
||||
},
|
||||
|
||||
settings: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const entries = require('object.entries');
|
||||
const { isArray } = Array;
|
||||
const { entries } = Object;
|
||||
const { ESLint } = require('eslint');
|
||||
|
||||
const baseConfig = require('.');
|
||||
@@ -9,7 +10,7 @@ const whitespaceRules = require('./whitespaceRules');
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
@@ -32,7 +33,7 @@ async function onlyErrorOnRules(rulesToError, config) {
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/* eslint global-require: 0 */
|
||||
|
||||
const { isArray } = Array;
|
||||
const { entries } = Object;
|
||||
const { CLIEngine } = require('eslint');
|
||||
|
||||
if (CLIEngine) {
|
||||
/* eslint no-inner-declarations: 0 */
|
||||
const entries = require('object.entries');
|
||||
const whitespaceRules = require('./whitespaceRules');
|
||||
|
||||
const baseConfig = require('.');
|
||||
@@ -12,7 +13,7 @@ if (CLIEngine) {
|
||||
const severities = ['off', 'warn', 'error'];
|
||||
|
||||
function getSeverity(ruleConfig) {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
return getSeverity(ruleConfig[0]);
|
||||
}
|
||||
if (typeof ruleConfig === 'number') {
|
||||
@@ -32,7 +33,7 @@ if (CLIEngine) {
|
||||
const severity = getSeverity(ruleConfig);
|
||||
|
||||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
|
||||
if (Array.isArray(ruleConfig)) {
|
||||
if (isArray(ruleConfig)) {
|
||||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
|
||||
} else if (typeof ruleConfig === 'number') {
|
||||
errorsOnly.rules[ruleName] = 1;
|
||||
@@ -50,5 +51,11 @@ if (CLIEngine) {
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'))));
|
||||
// NOTE: ESLint adds runtime statistics to the output (so it's no longer JSON) if TIMING is set
|
||||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js'), {
|
||||
env: {
|
||||
...process.env,
|
||||
TIMING: undefined,
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user