Skip to content

Support flat config #3080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/eslint-config-airbnb-base/README.md
Original file line number Diff line number Diff line change
@@ -62,6 +62,28 @@ Our default export contains all of our ESLint rules, including ECMAScript 6+. It

2. Add `"extends": "airbnb-base"` to your .eslintrc.

If using **flat config**, add `eslint-config-airbnb-base/flat` to `eslint.config.mjs` / `eslint.config.cjs` / `eslint.config.js` :

```js
// eslint.config.cjs
const airbnbBase = require('eslint-config-airbnb-base/flat');

module.exports = [
...airbnbBase,
// ......
];
```

```js
// eslint.config.mjs
import airbnbBase from 'eslint-config-airbnb-base/flat';

export default [
...airbnbBase,
// ......
];
```

### eslint-config-airbnb-base/legacy

Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
12 changes: 12 additions & 0 deletions packages/eslint-config-airbnb-base/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = [
...require('./flat'),
{
rules: {
// disable requiring trailing commas because it might be nice to revert to
// being JSON at some point, and I don't want to make big changes now.
"comma-dangle": 0,

"max-len": 0
}
}
];
21 changes: 21 additions & 0 deletions packages/eslint-config-airbnb-base/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = [
...([
'./rules/flat/best-practices',
'./rules/flat/errors',
'./rules/flat/node',
'./rules/flat/style',
'./rules/flat/variables',
'./rules/flat/es6',
'./rules/flat/imports',
'./rules/flat/strict',
].reduce((p, c) => p.concat(require(c)), [])), // eslint-disable-line global-require, import/no-dynamic-require
{
languageOptions: {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
}
},
rules: {}
}
];
26 changes: 22 additions & 4 deletions packages/eslint-config-airbnb-base/package.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"main": "index.js",
"exports": {
".": "./index.js",
"./flat": "./flat.js",
"./legacy": "./legacy.js",
"./whitespace": "./whitespace.js",
"./rules/best-practices": "./rules/best-practices.js",
@@ -15,6 +16,22 @@
"./rules/imports": "./rules/imports.js",
"./rules/strict": "./rules/strict.js",
"./rules/variables": "./rules/variables.js",
"./rules/base/best-practices": "./rules/base/best-practices.js",
"./rules/base/es6": "./rules/base/es6.js",
"./rules/base/node": "./rules/base/node.js",
"./rules/base/style": "./rules/base/style.js",
"./rules/base/errors": "./rules/base/errors.js",
"./rules/base/imports": "./rules/base/imports.js",
"./rules/base/strict": "./rules/base/strict.js",
"./rules/base/variables": "./rules/base/variables.js",
"./rules/flat/best-practices": "./rules/flat/best-practices.js",
"./rules/flat/es6": "./rules/flat/es6.js",
"./rules/flat/node": "./rules/flat/node.js",
"./rules/flat/style": "./rules/flat/style.js",
"./rules/flat/errors": "./rules/flat/errors.js",
"./rules/flat/imports": "./rules/flat/imports.js",
"./rules/flat/strict": "./rules/flat/strict.js",
"./rules/flat/variables": "./rules/flat/variables.js",
"./package.json": "./package.json"
},
"scripts": {
@@ -72,21 +89,22 @@
"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": "^7.32.0 || ^8.2.0 || >= 9",
"eslint-find-rules": "^5.0.0",
"eslint-plugin-import": "^2.30.0",
"in-publish": "^2.0.1",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0"
},
"peerDependencies": {
"eslint": "^7.32.0 || ^8.2.0",
"eslint": "^7.32.0 || ^8.2.0 || >= 9",
"eslint-plugin-import": "^2.30.0"
},
"engines": {
"node": "^10.12.0 || >=12.0.0"
},
"dependencies": {
"confusing-browser-globals": "^1.0.11"
"confusing-browser-globals": "^1.0.11",
"globals": "^15.14.0"
}
}
424 changes: 424 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/best-practices.js

Large diffs are not rendered by default.

189 changes: 189 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
module.exports = {
rules: {
// Enforce “for” loop update clause moving the counter in the right direction
// https://eslint.org/docs/rules/for-direction
'for-direction': 'error',

// Enforces that a return statement is present in property getters
// https://eslint.org/docs/rules/getter-return
'getter-return': ['error', { allowImplicit: true }],

// disallow using an async function as a Promise executor
// https://eslint.org/docs/rules/no-async-promise-executor
'no-async-promise-executor': 'error',

// Disallow await inside of loops
// https://eslint.org/docs/rules/no-await-in-loop
'no-await-in-loop': 'error',

// Disallow comparisons to negative zero
// https://eslint.org/docs/rules/no-compare-neg-zero
'no-compare-neg-zero': 'error',

// disallow assignment in conditional expressions
'no-cond-assign': ['error', 'always'],

// disallow use of console
'no-console': 'warn',

// Disallows expressions where the operation doesn't affect the value
// https://eslint.org/docs/rules/no-constant-binary-expression
// TODO: semver-major, enable
'no-constant-binary-expression': 'off',

// disallow use of constant expressions in conditions
'no-constant-condition': 'warn',

// disallow control characters in regular expressions
'no-control-regex': 'error',

// disallow use of debugger
'no-debugger': 'error',

// disallow duplicate arguments in functions
'no-dupe-args': 'error',

// Disallow duplicate conditions in if-else-if chains
// https://eslint.org/docs/rules/no-dupe-else-if
'no-dupe-else-if': 'error',

// disallow duplicate keys when creating object literals
'no-dupe-keys': 'error',

// disallow a duplicate case label.
'no-duplicate-case': 'error',

// disallow empty statements
'no-empty': 'error',

// disallow the use of empty character classes in regular expressions
'no-empty-character-class': 'error',

// disallow assigning to the exception in a catch block
'no-ex-assign': 'error',

// disallow double-negation boolean casts in a boolean context
// https://eslint.org/docs/rules/no-extra-boolean-cast
'no-extra-boolean-cast': 'error',

// disallow unnecessary parentheses
// https://eslint.org/docs/rules/no-extra-parens
'no-extra-parens': ['off', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all', // delegate to eslint-plugin-react
enforceForArrowConditionals: false,
}],

// disallow unnecessary semicolons
'no-extra-semi': 'error',

// disallow overwriting functions written as function declarations
'no-func-assign': 'error',

// https://eslint.org/docs/rules/no-import-assign
'no-import-assign': 'error',

// disallow function or variable declarations in nested blocks
'no-inner-declarations': 'error',

// disallow invalid regular expression strings in the RegExp constructor
'no-invalid-regexp': 'error',

// 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',

// disallow the use of object properties of the global object (Math and JSON) as functions
'no-obj-calls': 'error',

// Disallow new operators with global non-constructor functions
// https://eslint.org/docs/latest/rules/no-new-native-nonconstructor
// TODO: semver-major, enable
'no-new-native-nonconstructor': 'off',

// 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',

// disallow multiple spaces in a regular expression literal
'no-regex-spaces': 'error',

// Disallow returning values from setters
// https://eslint.org/docs/rules/no-setter-return
'no-setter-return': 'error',

// disallow sparse arrays
'no-sparse-arrays': 'error',

// Disallow template literal placeholder syntax in regular strings
// https://eslint.org/docs/rules/no-template-curly-in-string
'no-template-curly-in-string': 'error',

// Avoid code that looks like two expressions but is actually one
// https://eslint.org/docs/rules/no-unexpected-multiline
'no-unexpected-multiline': 'error',

// 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',

// 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
// note: not enabled because it is very buggy
'require-atomic-updates': 'off',

// disallow comparisons with the value NaN
'use-isnan': 'error',

// ensure JSDoc comments are valid
// https://eslint.org/docs/rules/valid-jsdoc
'valid-jsdoc': 'off',

// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'valid-typeof': ['error', { requireStringLiterals: true }]
}
};
182 changes: 182 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
module.exports = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
generators: false,
objectLiteralDuplicateProperties: false
}
},

rules: {
// enforces no braces where they can be omitted
// https://eslint.org/docs/rules/arrow-body-style
// TODO: enable requireReturnForObjectLiteral?
'arrow-body-style': ['error', 'as-needed', {
requireReturnForObjectLiteral: false,
}],

// require parens in arrow function arguments
// https://eslint.org/docs/rules/arrow-parens
'arrow-parens': ['error', 'always'],

// require space before/after arrow function's arrow
// https://eslint.org/docs/rules/arrow-spacing
'arrow-spacing': ['error', { before: true, after: true }],

// verify super() callings in constructors
'constructor-super': 'error',

// enforce the spacing around the * in generator functions
// https://eslint.org/docs/rules/generator-star-spacing
'generator-star-spacing': ['error', { before: false, after: true }],

// disallow modifying variables of class declarations
// https://eslint.org/docs/rules/no-class-assign
'no-class-assign': 'error',

// disallow arrow functions where they could be confused with comparisons
// https://eslint.org/docs/rules/no-confusing-arrow
'no-confusing-arrow': ['error', {
allowParens: true,
}],

// disallow modifying variables that are declared using const
'no-const-assign': 'error',

// disallow duplicate class members
// https://eslint.org/docs/rules/no-dupe-class-members
'no-dupe-class-members': 'error',

// disallow importing from the same path more than once
// https://eslint.org/docs/rules/no-duplicate-imports
// replaced by https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
'no-duplicate-imports': 'off',

// disallow symbol constructor
// 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', {
paths: [],
patterns: []
}],

// disallow to use this/super before super() calling in constructors.
// https://eslint.org/docs/rules/no-this-before-super
'no-this-before-super': 'error',

// disallow useless computed property keys
// https://eslint.org/docs/rules/no-useless-computed-key
'no-useless-computed-key': 'error',

// disallow unnecessary constructor
// https://eslint.org/docs/rules/no-useless-constructor
'no-useless-constructor': 'error',

// disallow renaming import, export, and destructured assignments to the same name
// https://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': ['error', {
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
}],

// require let or const instead of var
'no-var': 'error',

// require method and property shorthand syntax for object literals
// https://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'always', {
ignoreConstructors: false,
avoidQuotes: true,
}],

// suggest using arrow functions as callbacks
'prefer-arrow-callback': ['error', {
allowNamedFunctions: false,
allowUnboundThis: true,
}],

// suggest using of const declaration for variables that are never modified after declared
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: true,
}],

// Prefer destructuring from arrays and objects
// https://eslint.org/docs/rules/prefer-destructuring
'prefer-destructuring': ['error', {
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: true,
object: false,
},
}, {
enforceForRenamedProperties: false,
}],

// disallow parseInt() in favor of binary, octal, and hexadecimal literals
// https://eslint.org/docs/rules/prefer-numeric-literals
'prefer-numeric-literals': 'error',

// suggest using Reflect methods where applicable
// https://eslint.org/docs/rules/prefer-reflect
'prefer-reflect': 'off',

// use rest parameters instead of arguments
// https://eslint.org/docs/rules/prefer-rest-params
'prefer-rest-params': 'error',

// suggest using the spread syntax instead of .apply()
// https://eslint.org/docs/rules/prefer-spread
'prefer-spread': 'error',

// suggest using template literals instead of string concatenation
// https://eslint.org/docs/rules/prefer-template
'prefer-template': 'error',

// disallow generator functions that do not have yield
// https://eslint.org/docs/rules/require-yield
'require-yield': 'error',

// enforce spacing between object rest-spread
// https://eslint.org/docs/rules/rest-spread-spacing
'rest-spread-spacing': ['error', 'never'],

// import sorting
// https://eslint.org/docs/rules/sort-imports
'sort-imports': ['off', {
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],

// require a Symbol description
// https://eslint.org/docs/rules/symbol-description
'symbol-description': 'error',

// enforce usage of spacing in template strings
// https://eslint.org/docs/rules/template-curly-spacing
'template-curly-spacing': 'error',

// enforce spacing around the * in yield* expressions
// https://eslint.org/docs/rules/yield-star-spacing
'yield-star-spacing': ['error', 'after']
}
};
277 changes: 277 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
module.exports = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},

settings: {
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.json']
}
},
'import/extensions': [
'.js',
'.mjs',
'.jsx',
],
'import/core-modules': [
],
'import/ignore': [
'node_modules',
'\\.(coffee|scss|css|less|hbs|svg|json)$',
],
},

rules: {
// Static analysis:

// ensure imports point to files/modules that can be resolved
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
'import/no-unresolved': ['error', { commonjs: true, caseSensitive: true }],

// ensure named imports coupled with named exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
'import/named': 'error',

// ensure default import coupled with default export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
'import/default': 'off',

// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/namespace.md
'import/namespace': 'off',

// Helpful warnings:

// disallow invalid exports, e.g. multiple defaults
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md
'import/export': 'error',

// do not allow a default import name to match a named export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
'import/no-named-as-default': 'error',

// warn on accessing default export property names that are also named exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
'import/no-named-as-default-member': 'error',

// disallow use of jsdoc-marked-deprecated imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
'import/no-deprecated': 'off',

// Forbid the use of extraneous packages
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
// paths are treated both as absolute paths, and relative to process.cwd()
'import/no-extraneous-dependencies': ['error', {
devDependencies: [
'test/**', // tape, common npm pattern
'tests/**', // also common npm pattern
'spec/**', // mocha, rspec-like pattern
'**/__tests__/**', // jest pattern
'**/__mocks__/**', // jest pattern
'test.{js,jsx}', // repos with a single test file
'test-*.{js,jsx}', // repos with multiple top-level test files
'**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
'**/jest.config.js', // jest config
'**/jest.setup.js', // jest setup
'**/vue.config.js', // vue-cli config
'**/webpack.config.js', // webpack config
'**/webpack.config.*.js', // webpack config
'**/rollup.config.js', // rollup config
'**/rollup.config.*.js', // rollup config
'**/gulpfile.js', // gulp config
'**/gulpfile.*.js', // gulp config
'**/Gruntfile{,.js}', // grunt config
'**/protractor.conf.js', // protractor config
'**/protractor.conf.*.js', // protractor config
'**/karma.conf.js', // karma config
'**/.eslintrc.js' // eslint config
],
optionalDependencies: false,
}],

// Forbid mutable exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
'import/no-mutable-exports': 'error',

// Module systems:

// disallow require()
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
'import/no-commonjs': 'off',

// disallow AMD require/define
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md
'import/no-amd': 'error',

// No Node.js builtin modules
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
// TODO: enable?
'import/no-nodejs-modules': 'off',

// Style guide:

// disallow non-import statements appearing before import statements
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md
'import/first': 'error',

// disallow non-import statements appearing before import statements
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/imports-first.md
// deprecated: use `import/first`
'import/imports-first': 'off',

// disallow duplicate imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
'import/no-duplicates': 'error',

// disallow namespace imports
// TODO: enable?
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
'import/no-namespace': 'off',

// Ensure consistent use of file extension within the import path
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': ['error', 'ignorePackages', {
js: 'never',
mjs: 'never',
jsx: 'never',
}],

// ensure absolute imports are above relative imports and that unassigned imports are ignored
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md
// TODO: enforce a stricter convention in module import order?
'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }],

// Require a newline after the last import/require in a group
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
'import/newline-after-import': 'error',

// Require modules with a single export to use a default export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
'import/prefer-default-export': 'error',

// Restrict which files can be imported in a given folder
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
'import/no-restricted-paths': 'off',

// Forbid modules to have too many dependencies
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md
'import/max-dependencies': ['off', { max: 10 }],

// Forbid import of modules using absolute paths
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
'import/no-absolute-path': 'error',

// Forbid require() calls with expressions
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
'import/no-dynamic-require': 'error',

// prevent importing the submodules of other modules
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
'import/no-internal-modules': ['off', {
allow: [],
}],

// Warn if a module could be mistakenly parsed as a script by a consumer
// leveraging Unambiguous JavaScript Grammar
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/unambiguous.md
// this should not be enabled until this proposal has at least been *presented* to TC39.
// At the moment, it's not a thing.
'import/unambiguous': 'off',

// Forbid Webpack loader syntax in imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
'import/no-webpack-loader-syntax': 'error',

// Prevent unassigned imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
// importing for side effects is perfectly acceptable, if you need side effects.
'import/no-unassigned-import': 'off',

// Prevent importing the default as if it were named
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
'import/no-named-default': 'error',

// Reports if a module's default export is unnamed
// https://github.com/import-js/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
'import/no-anonymous-default-export': ['off', {
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowLiteral: false,
allowObject: false,
}],

// This rule enforces that all exports are declared at the bottom of the file.
// https://github.com/import-js/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
// TODO: enable?
'import/exports-last': 'off',

// Reports when named exports are not grouped together in a single export declaration
// or when multiple assignments to CommonJS module.exports or exports object are present
// in a single file.
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
'import/group-exports': 'off',

// forbid default exports. this is a terrible rule, do not use it.
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
'import/no-default-export': 'off',

// Prohibit named exports. this is a terrible rule, do not use it.
// https://github.com/import-js/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
'import/no-named-export': 'off',

// Forbid a module from importing itself
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
'import/no-self-import': 'error',

// Forbid cyclical dependencies between modules
// https://github.com/import-js/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
'import/no-cycle': ['error', { maxDepth: '∞' }],

// Ensures that there are no useless path segments
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
'import/no-useless-path-segments': ['error', { commonjs: true }],

// dynamic imports require a leading comment with a webpackChunkName
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
'import/dynamic-import-chunkname': ['off', {
importFunctions: [],
webpackChunknameFormat: '[0-9a-zA-Z-_/.]+',
}],

// Use this rule to prevent imports to folders in relative parent paths.
// https://github.com/import-js/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
'import/no-relative-parent-imports': 'off',

// Reports modules without any exports, or with unused exports
// https://github.com/import-js/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
// 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/import-js/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/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
'import/no-relative-packages': 'error',

// enforce a consistent style for type specifiers (inline or top-level)
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md
// TODO, semver-major: enable (just in case)
'import/consistent-type-specifier-style': ['off', 'prefer-inline'],

// Reports the use of empty named import blocks.
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/no-empty-named-blocks.md
// TODO, semver-minor: enable
'import/no-empty-named-blocks': 'off'
}
};
39 changes: 39 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
rules: {
// enforce return after a callback
'callback-return': 'off',

// require all requires be top-level
// https://eslint.org/docs/rules/global-require
'global-require': 'error',

// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',

// disallow use of the Buffer() constructor
// https://eslint.org/docs/rules/no-buffer-constructor
'no-buffer-constructor': 'error',

// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],

// disallow use of new operator with the require function
'no-new-require': 'error',

// disallow string concatenation with __dirname and __filename
// https://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',

// disallow use of process.env
'no-process-env': 'off',

// disallow process.exit()
'no-process-exit': 'off',

// restrict usage of specified node modules
'no-restricted-modules': 'off',

// disallow use of synchronous methods (off by default)
'no-sync': 'off',
}
};
6 changes: 6 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
rules: {
// babel inserts `'use strict';` for us
strict: ['error', 'never']
}
};
534 changes: 534 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/style.js

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions packages/eslint-config-airbnb-base/rules/base/variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const confusingBrowserGlobals = require('confusing-browser-globals');

module.exports = {
rules: {
// enforce or disallow variable initializations at definition
'init-declarations': 'off',

// disallow the catch clause parameter name being the same as a variable in the outer scope
'no-catch-shadow': 'off',

// disallow deletion of variables
'no-delete-var': 'error',

// disallow labels that share a name with a variable
// https://eslint.org/docs/rules/no-label-var
'no-label-var': 'error',

// disallow specific globals
'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.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',

// disallow shadowing of names such as arguments
'no-shadow-restricted-names': 'error',

// disallow use of undeclared variables unless mentioned in a /*global */ block
'no-undef': 'error',

// disallow use of undefined when initializing variables
'no-undef-init': 'error',

// disallow use of undefined variable
// https://eslint.org/docs/rules/no-undefined
// TODO: enable?
'no-undefined': 'off',

// disallow declaration of variables that are not used in the code
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],

// disallow use of variables before they are defined
'no-use-before-define': ['error', { functions: true, classes: true, variables: true }],
}
};
425 changes: 3 additions & 422 deletions packages/eslint-config-airbnb-base/rules/best-practices.js

Large diffs are not rendered by default.

190 changes: 3 additions & 187 deletions packages/eslint-config-airbnb-base/rules/errors.js
Original file line number Diff line number Diff line change
@@ -1,189 +1,5 @@
module.exports = {
rules: {
// Enforce “for” loop update clause moving the counter in the right direction
// https://eslint.org/docs/rules/for-direction
'for-direction': 'error',

// Enforces that a return statement is present in property getters
// https://eslint.org/docs/rules/getter-return
'getter-return': ['error', { allowImplicit: true }],

// disallow using an async function as a Promise executor
// https://eslint.org/docs/rules/no-async-promise-executor
'no-async-promise-executor': 'error',

// Disallow await inside of loops
// https://eslint.org/docs/rules/no-await-in-loop
'no-await-in-loop': 'error',

// Disallow comparisons to negative zero
// https://eslint.org/docs/rules/no-compare-neg-zero
'no-compare-neg-zero': 'error',

// disallow assignment in conditional expressions
'no-cond-assign': ['error', 'always'],

// disallow use of console
'no-console': 'warn',

// Disallows expressions where the operation doesn't affect the value
// https://eslint.org/docs/rules/no-constant-binary-expression
// TODO: semver-major, enable
'no-constant-binary-expression': 'off',

// disallow use of constant expressions in conditions
'no-constant-condition': 'warn',

// disallow control characters in regular expressions
'no-control-regex': 'error',

// disallow use of debugger
'no-debugger': 'error',

// disallow duplicate arguments in functions
'no-dupe-args': 'error',

// Disallow duplicate conditions in if-else-if chains
// https://eslint.org/docs/rules/no-dupe-else-if
'no-dupe-else-if': 'error',

// disallow duplicate keys when creating object literals
'no-dupe-keys': 'error',

// disallow a duplicate case label.
'no-duplicate-case': 'error',

// disallow empty statements
'no-empty': 'error',

// disallow the use of empty character classes in regular expressions
'no-empty-character-class': 'error',

// disallow assigning to the exception in a catch block
'no-ex-assign': 'error',

// disallow double-negation boolean casts in a boolean context
// https://eslint.org/docs/rules/no-extra-boolean-cast
'no-extra-boolean-cast': 'error',

// disallow unnecessary parentheses
// https://eslint.org/docs/rules/no-extra-parens
'no-extra-parens': ['off', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all', // delegate to eslint-plugin-react
enforceForArrowConditionals: false,
}],

// disallow unnecessary semicolons
'no-extra-semi': 'error',

// disallow overwriting functions written as function declarations
'no-func-assign': 'error',

// https://eslint.org/docs/rules/no-import-assign
'no-import-assign': 'error',

// disallow function or variable declarations in nested blocks
'no-inner-declarations': 'error',

// disallow invalid regular expression strings in the RegExp constructor
'no-invalid-regexp': 'error',
const base = require('./base/errors');

// 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',

// disallow the use of object properties of the global object (Math and JSON) as functions
'no-obj-calls': 'error',

// Disallow new operators with global non-constructor functions
// https://eslint.org/docs/latest/rules/no-new-native-nonconstructor
// TODO: semver-major, enable
'no-new-native-nonconstructor': 'off',

// 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',

// disallow multiple spaces in a regular expression literal
'no-regex-spaces': 'error',

// Disallow returning values from setters
// https://eslint.org/docs/rules/no-setter-return
'no-setter-return': 'error',

// disallow sparse arrays
'no-sparse-arrays': 'error',

// Disallow template literal placeholder syntax in regular strings
// https://eslint.org/docs/rules/no-template-curly-in-string
'no-template-curly-in-string': 'error',

// Avoid code that looks like two expressions but is actually one
// https://eslint.org/docs/rules/no-unexpected-multiline
'no-unexpected-multiline': 'error',

// 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',

// 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
// note: not enabled because it is very buggy
'require-atomic-updates': 'off',

// disallow comparisons with the value NaN
'use-isnan': 'error',

// ensure JSDoc comments are valid
// https://eslint.org/docs/rules/valid-jsdoc
'valid-jsdoc': 'off',

// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'valid-typeof': ['error', { requireStringLiterals: true }],
}
module.exports = {
rules: base.rules
};
184 changes: 4 additions & 180 deletions packages/eslint-config-airbnb-base/rules/es6.js
Original file line number Diff line number Diff line change
@@ -1,185 +1,9 @@
const base = require('./base/es6');

module.exports = {
env: {
es6: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
generators: false,
objectLiteralDuplicateProperties: false
}
},

rules: {
// enforces no braces where they can be omitted
// https://eslint.org/docs/rules/arrow-body-style
// TODO: enable requireReturnForObjectLiteral?
'arrow-body-style': ['error', 'as-needed', {
requireReturnForObjectLiteral: false,
}],

// require parens in arrow function arguments
// https://eslint.org/docs/rules/arrow-parens
'arrow-parens': ['error', 'always'],

// require space before/after arrow function's arrow
// https://eslint.org/docs/rules/arrow-spacing
'arrow-spacing': ['error', { before: true, after: true }],

// verify super() callings in constructors
'constructor-super': 'error',

// enforce the spacing around the * in generator functions
// https://eslint.org/docs/rules/generator-star-spacing
'generator-star-spacing': ['error', { before: false, after: true }],

// disallow modifying variables of class declarations
// https://eslint.org/docs/rules/no-class-assign
'no-class-assign': 'error',

// disallow arrow functions where they could be confused with comparisons
// https://eslint.org/docs/rules/no-confusing-arrow
'no-confusing-arrow': ['error', {
allowParens: true,
}],

// disallow modifying variables that are declared using const
'no-const-assign': 'error',

// disallow duplicate class members
// https://eslint.org/docs/rules/no-dupe-class-members
'no-dupe-class-members': 'error',

// disallow importing from the same path more than once
// https://eslint.org/docs/rules/no-duplicate-imports
// replaced by https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
'no-duplicate-imports': 'off',

// disallow symbol constructor
// 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', {
paths: [],
patterns: []
}],

// disallow to use this/super before super() calling in constructors.
// https://eslint.org/docs/rules/no-this-before-super
'no-this-before-super': 'error',

// disallow useless computed property keys
// https://eslint.org/docs/rules/no-useless-computed-key
'no-useless-computed-key': 'error',

// disallow unnecessary constructor
// https://eslint.org/docs/rules/no-useless-constructor
'no-useless-constructor': 'error',

// disallow renaming import, export, and destructured assignments to the same name
// https://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': ['error', {
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
}],

// require let or const instead of var
'no-var': 'error',

// require method and property shorthand syntax for object literals
// https://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'always', {
ignoreConstructors: false,
avoidQuotes: true,
}],

// suggest using arrow functions as callbacks
'prefer-arrow-callback': ['error', {
allowNamedFunctions: false,
allowUnboundThis: true,
}],

// suggest using of const declaration for variables that are never modified after declared
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: true,
}],

// Prefer destructuring from arrays and objects
// https://eslint.org/docs/rules/prefer-destructuring
'prefer-destructuring': ['error', {
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: true,
object: false,
},
}, {
enforceForRenamedProperties: false,
}],

// disallow parseInt() in favor of binary, octal, and hexadecimal literals
// https://eslint.org/docs/rules/prefer-numeric-literals
'prefer-numeric-literals': 'error',

// suggest using Reflect methods where applicable
// https://eslint.org/docs/rules/prefer-reflect
'prefer-reflect': 'off',

// use rest parameters instead of arguments
// https://eslint.org/docs/rules/prefer-rest-params
'prefer-rest-params': 'error',

// suggest using the spread syntax instead of .apply()
// https://eslint.org/docs/rules/prefer-spread
'prefer-spread': 'error',

// suggest using template literals instead of string concatenation
// https://eslint.org/docs/rules/prefer-template
'prefer-template': 'error',

// disallow generator functions that do not have yield
// https://eslint.org/docs/rules/require-yield
'require-yield': 'error',

// enforce spacing between object rest-spread
// https://eslint.org/docs/rules/rest-spread-spacing
'rest-spread-spacing': ['error', 'never'],

// import sorting
// https://eslint.org/docs/rules/sort-imports
'sort-imports': ['off', {
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],

// require a Symbol description
// https://eslint.org/docs/rules/symbol-description
'symbol-description': 'error',

// enforce usage of spacing in template strings
// https://eslint.org/docs/rules/template-curly-spacing
'template-curly-spacing': 'error',

// enforce spacing around the * in yield* expressions
// https://eslint.org/docs/rules/yield-star-spacing
'yield-star-spacing': ['error', 'after']
}
parserOptions: base.parserOptions,
rules: base.rules
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('../base/best-practices');

module.exports = [{
name: 'eslint-config-airbnb-base/best-practices',
rules: base.rules
}];
6 changes: 6 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('../base/errors');

module.exports = [{
name: 'eslint-config-airbnb-base/errors',
rules: base.rules
}];
11 changes: 11 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const globals = require('globals');
const base = require('../base/es6');

module.exports = [{
name: 'eslint-config-airbnb-base/es6',
languageOptions: {
globals: globals.es2015,
parserOptions: base.parserOptions
},
rules: base.rules
}];
13 changes: 13 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const importPlugin = require('eslint-plugin-import');
const globals = require('globals');
const base = require('../base/imports');

module.exports = [importPlugin.flatConfigs.recommended, {
name: 'eslint-config-airbnb-base/imports',
languageOptions: {
globals: globals.es2015,
parserOptions: base.parserOptions
},
settings: base.settings,
rules: base.rules
}];
10 changes: 10 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const globals = require('globals');
const base = require('../base/node');

module.exports = [{
name: 'eslint-config-airbnb-base/node',
languageOptions: {
globals: globals.node
},
rules: base.rules
}];
6 changes: 6 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('../base/strict');

module.exports = [{
name: 'eslint-config-airbnb-base/strict',
rules: base.rules
}];
6 changes: 6 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('../base/style');

module.exports = [{
name: 'eslint-config-airbnb-base/style',
rules: base.rules
}];
6 changes: 6 additions & 0 deletions packages/eslint-config-airbnb-base/rules/flat/variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const base = require('../base/variables');

module.exports = [{
name: 'eslint-config-airbnb-base/variables',
rules: base.rules
}];
279 changes: 4 additions & 275 deletions packages/eslint-config-airbnb-base/rules/imports.js
Original file line number Diff line number Diff line change
@@ -1,283 +1,12 @@
const base = require('./base/imports');

module.exports = {
env: {
es6: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
plugins: [
'import'
],

settings: {
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.json']
}
},
'import/extensions': [
'.js',
'.mjs',
'.jsx',
],
'import/core-modules': [
],
'import/ignore': [
'node_modules',
'\\.(coffee|scss|css|less|hbs|svg|json)$',
],
},

rules: {
// Static analysis:

// ensure imports point to files/modules that can be resolved
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
'import/no-unresolved': ['error', { commonjs: true, caseSensitive: true }],

// ensure named imports coupled with named exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
'import/named': 'error',

// ensure default import coupled with default export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
'import/default': 'off',

// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/namespace.md
'import/namespace': 'off',

// Helpful warnings:

// disallow invalid exports, e.g. multiple defaults
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md
'import/export': 'error',

// do not allow a default import name to match a named export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
'import/no-named-as-default': 'error',

// warn on accessing default export property names that are also named exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
'import/no-named-as-default-member': 'error',

// disallow use of jsdoc-marked-deprecated imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
'import/no-deprecated': 'off',

// Forbid the use of extraneous packages
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
// paths are treated both as absolute paths, and relative to process.cwd()
'import/no-extraneous-dependencies': ['error', {
devDependencies: [
'test/**', // tape, common npm pattern
'tests/**', // also common npm pattern
'spec/**', // mocha, rspec-like pattern
'**/__tests__/**', // jest pattern
'**/__mocks__/**', // jest pattern
'test.{js,jsx}', // repos with a single test file
'test-*.{js,jsx}', // repos with multiple top-level test files
'**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
'**/jest.config.js', // jest config
'**/jest.setup.js', // jest setup
'**/vue.config.js', // vue-cli config
'**/webpack.config.js', // webpack config
'**/webpack.config.*.js', // webpack config
'**/rollup.config.js', // rollup config
'**/rollup.config.*.js', // rollup config
'**/gulpfile.js', // gulp config
'**/gulpfile.*.js', // gulp config
'**/Gruntfile{,.js}', // grunt config
'**/protractor.conf.js', // protractor config
'**/protractor.conf.*.js', // protractor config
'**/karma.conf.js', // karma config
'**/.eslintrc.js' // eslint config
],
optionalDependencies: false,
}],

// Forbid mutable exports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
'import/no-mutable-exports': 'error',

// Module systems:

// disallow require()
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
'import/no-commonjs': 'off',

// disallow AMD require/define
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md
'import/no-amd': 'error',

// No Node.js builtin modules
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
// TODO: enable?
'import/no-nodejs-modules': 'off',

// Style guide:

// disallow non-import statements appearing before import statements
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md
'import/first': 'error',

// disallow non-import statements appearing before import statements
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/imports-first.md
// deprecated: use `import/first`
'import/imports-first': 'off',

// disallow duplicate imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
'import/no-duplicates': 'error',

// disallow namespace imports
// TODO: enable?
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
'import/no-namespace': 'off',

// Ensure consistent use of file extension within the import path
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': ['error', 'ignorePackages', {
js: 'never',
mjs: 'never',
jsx: 'never',
}],

// ensure absolute imports are above relative imports and that unassigned imports are ignored
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md
// TODO: enforce a stricter convention in module import order?
'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }],

// Require a newline after the last import/require in a group
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
'import/newline-after-import': 'error',

// Require modules with a single export to use a default export
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
'import/prefer-default-export': 'error',

// Restrict which files can be imported in a given folder
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
'import/no-restricted-paths': 'off',

// Forbid modules to have too many dependencies
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md
'import/max-dependencies': ['off', { max: 10 }],

// Forbid import of modules using absolute paths
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
'import/no-absolute-path': 'error',

// Forbid require() calls with expressions
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
'import/no-dynamic-require': 'error',

// prevent importing the submodules of other modules
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
'import/no-internal-modules': ['off', {
allow: [],
}],

// Warn if a module could be mistakenly parsed as a script by a consumer
// leveraging Unambiguous JavaScript Grammar
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/unambiguous.md
// this should not be enabled until this proposal has at least been *presented* to TC39.
// At the moment, it's not a thing.
'import/unambiguous': 'off',

// Forbid Webpack loader syntax in imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
'import/no-webpack-loader-syntax': 'error',

// Prevent unassigned imports
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
// importing for side effects is perfectly acceptable, if you need side effects.
'import/no-unassigned-import': 'off',

// Prevent importing the default as if it were named
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
'import/no-named-default': 'error',

// Reports if a module's default export is unnamed
// https://github.com/import-js/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
'import/no-anonymous-default-export': ['off', {
allowArray: false,
allowArrowFunction: false,
allowAnonymousClass: false,
allowAnonymousFunction: false,
allowLiteral: false,
allowObject: false,
}],

// This rule enforces that all exports are declared at the bottom of the file.
// https://github.com/import-js/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
// TODO: enable?
'import/exports-last': 'off',

// Reports when named exports are not grouped together in a single export declaration
// or when multiple assignments to CommonJS module.exports or exports object are present
// in a single file.
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
'import/group-exports': 'off',

// forbid default exports. this is a terrible rule, do not use it.
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
'import/no-default-export': 'off',

// Prohibit named exports. this is a terrible rule, do not use it.
// https://github.com/import-js/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
'import/no-named-export': 'off',

// Forbid a module from importing itself
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
'import/no-self-import': 'error',

// Forbid cyclical dependencies between modules
// https://github.com/import-js/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
'import/no-cycle': ['error', { maxDepth: '∞' }],

// Ensures that there are no useless path segments
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
'import/no-useless-path-segments': ['error', { commonjs: true }],

// dynamic imports require a leading comment with a webpackChunkName
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
'import/dynamic-import-chunkname': ['off', {
importFunctions: [],
webpackChunknameFormat: '[0-9a-zA-Z-_/.]+',
}],

// Use this rule to prevent imports to folders in relative parent paths.
// https://github.com/import-js/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
'import/no-relative-parent-imports': 'off',

// Reports modules without any exports, or with unused exports
// https://github.com/import-js/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
// 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/import-js/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/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
'import/no-relative-packages': 'error',

// enforce a consistent style for type specifiers (inline or top-level)
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md
// TODO, semver-major: enable (just in case)
'import/consistent-type-specifier-style': ['off', 'prefer-inline'],

// Reports the use of empty named import blocks.
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/no-empty-named-blocks.md
// TODO, semver-minor: enable
'import/no-empty-named-blocks': 'off',
},
parserOptions: base.parserOptions,
rules: base.rules
};
41 changes: 3 additions & 38 deletions packages/eslint-config-airbnb-base/rules/node.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
const base = require('./base/node');

module.exports = {
env: {
node: true
},

rules: {
// enforce return after a callback
'callback-return': 'off',

// require all requires be top-level
// https://eslint.org/docs/rules/global-require
'global-require': 'error',

// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',

// disallow use of the Buffer() constructor
// https://eslint.org/docs/rules/no-buffer-constructor
'no-buffer-constructor': 'error',

// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],

// disallow use of new operator with the require function
'no-new-require': 'error',

// disallow string concatenation with __dirname and __filename
// https://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',

// disallow use of process.env
'no-process-env': 'off',

// disallow process.exit()
'no-process-exit': 'off',

// restrict usage of specified node modules
'no-restricted-modules': 'off',

// disallow use of synchronous methods (off by default)
'no-sync': 'off',
}
rules: base.rules
};
7 changes: 3 additions & 4 deletions packages/eslint-config-airbnb-base/rules/strict.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const base = require('./base/strict');

module.exports = {
rules: {
// babel inserts `'use strict';` for us
strict: ['error', 'never']
}
rules: base.rules
};
535 changes: 3 additions & 532 deletions packages/eslint-config-airbnb-base/rules/style.js

Large diffs are not rendered by default.

58 changes: 2 additions & 56 deletions packages/eslint-config-airbnb-base/rules/variables.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,5 @@
const confusingBrowserGlobals = require('confusing-browser-globals');
const base = require('./base/variables');

module.exports = {
rules: {
// enforce or disallow variable initializations at definition
'init-declarations': 'off',

// disallow the catch clause parameter name being the same as a variable in the outer scope
'no-catch-shadow': 'off',

// disallow deletion of variables
'no-delete-var': 'error',

// disallow labels that share a name with a variable
// https://eslint.org/docs/rules/no-label-var
'no-label-var': 'error',

// disallow specific globals
'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.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',

// disallow shadowing of names such as arguments
'no-shadow-restricted-names': 'error',

// disallow use of undeclared variables unless mentioned in a /*global */ block
'no-undef': 'error',

// disallow use of undefined when initializing variables
'no-undef-init': 'error',

// disallow use of undefined variable
// https://eslint.org/docs/rules/no-undefined
// TODO: enable?
'no-undefined': 'off',

// disallow declaration of variables that are not used in the code
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],

// disallow use of variables before they are defined
'no-use-before-define': ['error', { functions: true, classes: true, variables: true }],
}
rules: base.rules
};
44 changes: 44 additions & 0 deletions packages/eslint-config-airbnb/README.md
Original file line number Diff line number Diff line change
@@ -58,10 +58,54 @@ If you don't need React, see [eslint-config-airbnb-base](https://npmjs.com/eslin

2. Add `"extends": "airbnb"` to your `.eslintrc`

If using **flat config**, add `eslint-config-airbnb/flat` to `eslint.config.mjs` / `eslint.config.cjs` / `eslint.config.js` :

```js
// eslint.config.cjs
const airbnb = require('eslint-config-airbnb/flat');

module.exports = [
...airbnb,
// ......
];
```

```js
// eslint.config.mjs
import airbnb from 'eslint-config-airbnb/flat';

export default [
...airbnb,
// ......
];
```

### 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`.

If using **flat config**, add `eslint-config-airbnb/hooks-flat` to `eslint.config.mjs` / `eslint.config.cjs` / `eslint.config.js` :

```js
// eslint.config.cjs
const hooksFlat = require('eslint-config-airbnb/hooks-flat');

module.exports = [
...hooksFlat,
// ......
];
```

```js
// eslint.config.mjs
import hooksFlat from 'eslint-config-airbnb/hooks-flat';

export default [
...hooksFlat,
// ......
];
```

### eslint-config-airbnb/whitespace

This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js).
10 changes: 10 additions & 0 deletions packages/eslint-config-airbnb/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
...require('./flat'), // eslint-disable-line global-require
{
rules: {
// disable requiring trailing commas because it might be nice to revert to
// being JSON at some point, and I don't want to make big changes now.
'comma-dangle': 0,
}
}
];
8 changes: 8 additions & 0 deletions packages/eslint-config-airbnb/flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
...([
'eslint-config-airbnb-base/flat',
'./rules/flat/react',
'./rules/flat/react-a11y',
// eslint-disable-next-line global-require, import/no-dynamic-require
].reduce((p, c) => p.concat(require(c)), []))
];
1 change: 1 addition & 0 deletions packages/eslint-config-airbnb/hooks-flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./rules/flat/react-hooks');
16 changes: 12 additions & 4 deletions packages/eslint-config-airbnb/package.json
Original file line number Diff line number Diff line change
@@ -5,13 +5,21 @@
"main": "index.js",
"exports": {
".": "./index.js",
"./flat": "./flat.js",
"./base": "./base.js",
"./hooks": "./hooks.js",
"./hooks-flat": "./hooks-flat.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",
"./rules/base/react": "./rules/base/react.js",
"./rules/base/react-a11y": "./rules/base/react-a11y.js",
"./rules/base/react-hooks": "./rules/base/react-hooks.js",
"./rules/flat/react": "./rules/flat/react.js",
"./rules/flat/react-a11y": "./rules/flat/react-a11y.js",
"./rules/flat/react-hooks": "./rules/flat/react-hooks.js",
"./package.json": "./package.json"
},
"scripts": {
@@ -66,15 +74,15 @@
},
"homepage": "https://github.com/airbnb/javascript",
"dependencies": {
"eslint-config-airbnb-base": "^15.0.0"
"eslint-config-airbnb-base": "file:../eslint-config-airbnb-base"
},
"devDependencies": {
"@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": "^7.32.0 || ^8.2.0 || >= 9",
"eslint-find-rules": "^5.0.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.36.1",
@@ -85,7 +93,7 @@
"tape": "^5.9.0"
},
"peerDependencies": {
"eslint": "^7.32.0 || ^8.2.0",
"eslint": "^7.32.0 || ^8.2.0 || >= 9",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.36.1",
264 changes: 264 additions & 0 deletions packages/eslint-config-airbnb/rules/base/react-a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
module.exports = {
parserOptions: {
ecmaFeatures: {
jsx: true
}
},

rules: {
// ensure emoji are accessible
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md
'jsx-a11y/alt-text': ['error', {
elements: ['img', 'object', 'area', 'input[type="image"]'],
img: [],
object: [],
area: [],
'input[type="image"]': [],
}],

// Enforce that anchors have content
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
'jsx-a11y/anchor-has-content': ['error', { components: [] }],

// ensure <a> tags are valid
// https://github.com/jsx-eslint/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'],
}],

// elements with aria-activedescendant must be tabbable
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/control-has-associated-label.md
'jsx-a11y/control-has-associated-label': ['error', {
labelAttributes: ['label'],
controlComponents: [],
ignoreElements: [
'audio',
'canvas',
'embed',
'input',
'textarea',
'tr',
'video',
],
ignoreRoles: [
'grid',
'listbox',
'menu',
'menubar',
'radiogroup',
'row',
'tablist',
'toolbar',
'tree',
'treegrid',
],
depth: 5,
}],

// ensure <hX> tags have content and are not aria-hidden
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/heading-has-content.md
'jsx-a11y/heading-has-content': ['error', { components: [''] }],

// require HTML elements to have a "lang" prop
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/lang.md
'jsx-a11y/lang': 'error',

// media elements must have captions
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md
'jsx-a11y/no-access-key': 'error',

// prohibit autoFocus prop
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-distracting-elements.md
'jsx-a11y/no-distracting-elements': ['error', {
elements: ['marquee', 'blink'],
}],

// WAI-ARIA roles should not be used to convert an interactive element to non-interactive
// https://github.com/jsx-eslint/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)
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-interactions.md
'jsx-a11y/no-noninteractive-element-interactions': ['error', {
handlers: [
'onClick',
'onMouseDown',
'onMouseUp',
'onKeyPress',
'onKeyDown',
'onKeyUp',
]
}],

// WAI-ARIA roles should not be used to convert a non-interactive element to interactive
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-to-interactive-role.md
'jsx-a11y/no-noninteractive-element-to-interactive-role': ['error', {
ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
li: ['menuitem', 'option', 'row', 'tab', 'treeitem'],
table: ['grid'],
td: ['gridcell'],
}],

// Tab key navigation should be limited to elements on the page that can be interacted with.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-tabindex.md
'jsx-a11y/no-noninteractive-tabindex': ['error', {
tags: [],
roles: ['tabpanel'],
allowExpressionValues: true,
}],

// require onBlur instead of onChange
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md
'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
'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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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,
}],

// Ensures anchor text is not ambiguous
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/anchor-ambiguous-text.md
// TODO: semver-major, enable
'jsx-a11y/anchor-ambiguous-text': 'off',

// Enforce that aria-hidden="true" is not set on focusable elements.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/no-aria-hidden-on-focusable.md
// TODO: semver-major, enable
'jsx-a11y/no-aria-hidden-on-focusable': 'off',

// Enforces using semantic DOM elements over the ARIA role property.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/prefer-tag-over-role.md
// TODO: semver-major, enable
'jsx-a11y/prefer-tag-over-role': 'off'
}
};
17 changes: 17 additions & 0 deletions packages/eslint-config-airbnb/rules/base/react-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
parserOptions: {
ecmaFeatures: {
jsx: true
}
},

rules: {
// Enforce Rules of Hooks
// https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
'react-hooks/rules-of-hooks': 'error',

// Verify the list of the dependencies for Hooks like useEffect and similar
// https://github.com/facebook/react/blob/1204c789776cb01fbaf3e9f032e7e2ba85a44137/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
'react-hooks/exhaustive-deps': 'error'
}
};
617 changes: 617 additions & 0 deletions packages/eslint-config-airbnb/rules/base/react.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions packages/eslint-config-airbnb/rules/flat/react-a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y');
const reactPlugin = require('eslint-plugin-react');
const base = require('../base/react-a11y');

module.exports = {
plugins: {
'jsx-a11y': jsxA11yPlugin,
react: reactPlugin
},
languageOptions: {
parserOptions: base.parserOptions
},
rules: base.rules
};
12 changes: 12 additions & 0 deletions packages/eslint-config-airbnb/rules/flat/react-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const base = require('../base/react-hooks');

module.exports = [{
plugins: {
'react-hooks': reactHooksPlugin,
},
languageOptions: {
parserOptions: base.parserOptions
},
rules: base.rules
}];
13 changes: 13 additions & 0 deletions packages/eslint-config-airbnb/rules/flat/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reactPlugin = require('eslint-plugin-react');
const base = require('../base/react');

module.exports = [{
plugins: {
react: reactPlugin
},
languageOptions: {
parserOptions: base.parserOptions
},
rules: base.rules,
settings: base.settings
}];
267 changes: 4 additions & 263 deletions packages/eslint-config-airbnb/rules/react-a11y.js
Original file line number Diff line number Diff line change
@@ -1,269 +1,10 @@
const base = require('./base/react-a11y');

module.exports = {
plugins: [
'jsx-a11y',
'react'
],

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},

rules: {
// ensure emoji are accessible
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md
'jsx-a11y/alt-text': ['error', {
elements: ['img', 'object', 'area', 'input[type="image"]'],
img: [],
object: [],
area: [],
'input[type="image"]': [],
}],

// Enforce that anchors have content
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
'jsx-a11y/anchor-has-content': ['error', { components: [] }],

// ensure <a> tags are valid
// https://github.com/jsx-eslint/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'],
}],

// elements with aria-activedescendant must be tabbable
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/control-has-associated-label.md
'jsx-a11y/control-has-associated-label': ['error', {
labelAttributes: ['label'],
controlComponents: [],
ignoreElements: [
'audio',
'canvas',
'embed',
'input',
'textarea',
'tr',
'video',
],
ignoreRoles: [
'grid',
'listbox',
'menu',
'menubar',
'radiogroup',
'row',
'tablist',
'toolbar',
'tree',
'treegrid',
],
depth: 5,
}],

// ensure <hX> tags have content and are not aria-hidden
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/heading-has-content.md
'jsx-a11y/heading-has-content': ['error', { components: [''] }],

// require HTML elements to have a "lang" prop
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/lang.md
'jsx-a11y/lang': 'error',

// media elements must have captions
// https://github.com/jsx-eslint/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/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md
'jsx-a11y/no-access-key': 'error',

// prohibit autoFocus prop
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-distracting-elements.md
'jsx-a11y/no-distracting-elements': ['error', {
elements: ['marquee', 'blink'],
}],

// WAI-ARIA roles should not be used to convert an interactive element to non-interactive
// https://github.com/jsx-eslint/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)
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-interactions.md
'jsx-a11y/no-noninteractive-element-interactions': ['error', {
handlers: [
'onClick',
'onMouseDown',
'onMouseUp',
'onKeyPress',
'onKeyDown',
'onKeyUp',
]
}],

// WAI-ARIA roles should not be used to convert a non-interactive element to interactive
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-element-to-interactive-role.md
'jsx-a11y/no-noninteractive-element-to-interactive-role': ['error', {
ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
li: ['menuitem', 'option', 'row', 'tab', 'treeitem'],
table: ['grid'],
td: ['gridcell'],
}],

// Tab key navigation should be limited to elements on the page that can be interacted with.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-noninteractive-tabindex.md
'jsx-a11y/no-noninteractive-tabindex': ['error', {
tags: [],
roles: ['tabpanel'],
allowExpressionValues: true,
}],

// require onBlur instead of onChange
// https://github.com/jsx-eslint/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/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-redundant-roles.md
'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
'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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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/jsx-eslint/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,
}],

// Ensures anchor text is not ambiguous
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/anchor-ambiguous-text.md
// TODO: semver-major, enable
'jsx-a11y/anchor-ambiguous-text': 'off',

// Enforce that aria-hidden="true" is not set on focusable elements.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/no-aria-hidden-on-focusable.md
// TODO: semver-major, enable
'jsx-a11y/no-aria-hidden-on-focusable': 'off',

// Enforces using semantic DOM elements over the ARIA role property.
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/93f78856655696a55309440593e0948c6fb96134/docs/rules/prefer-tag-over-role.md
// TODO: semver-major, enable
'jsx-a11y/prefer-tag-over-role': 'off',
},
parserOptions: base.parserOptions,
rules: base.rules
};
20 changes: 4 additions & 16 deletions packages/eslint-config-airbnb/rules/react-hooks.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
const base = require('./base/react-hooks');

module.exports = {
plugins: [
'react-hooks',
],

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},

rules: {
// Enforce Rules of Hooks
// https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
'react-hooks/rules-of-hooks': 'error',

// Verify the list of the dependencies for Hooks like useEffect and similar
// https://github.com/facebook/react/blob/1204c789776cb01fbaf3e9f032e7e2ba85a44137/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
'react-hooks/exhaustive-deps': 'error',
},
parserOptions: base.parserOptions,
rules: base.rules
};
Loading