mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
[eslint config] [eslint config base] [breaking] Migrate non-React rules to a separate linter config.
This commit is contained in:
8
packages/eslint-config-airbnb-base/.eslintrc
Normal file
8
packages/eslint-config-airbnb-base/.eslintrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./index.js",
|
||||
"rules": {
|
||||
// disable requiring trailing commas because it might be nice to revert to
|
||||
// being JSON at some point, and I don't want to make big changes now.
|
||||
"comma-dangle": 0
|
||||
}
|
||||
}
|
||||
3
packages/eslint-config-airbnb-base/CHANGELOG.md
Normal file
3
packages/eslint-config-airbnb-base/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
1.0.0 / 2016-04-16
|
||||
==================
|
||||
- Initial commmit; moved content over from `eslint-config-airbnb` package.
|
||||
33
packages/eslint-config-airbnb-base/README.md
Normal file
33
packages/eslint-config-airbnb-base/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# eslint-config-airbnb-base
|
||||
|
||||
[](http://badge.fury.io/js/eslint-config-airbnb-base)
|
||||
|
||||
This package provides Airbnb's base JS .eslintrc as an extensible shared config.
|
||||
|
||||
## Usage
|
||||
|
||||
We export two ESLint configurations for your usage.
|
||||
|
||||
### eslint-config-airbnb-base
|
||||
|
||||
Our default export contains all of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint` and `eslint-plugin-import`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint`
|
||||
2. add `"extends": "airbnb-base"` to your .eslintrc
|
||||
|
||||
### eslint-config-airbnb-base/legacy
|
||||
|
||||
Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb-base eslint-plugin-import eslint`
|
||||
2. add `"extends": "airbnb-base/legacy"` to your .eslintrc
|
||||
|
||||
See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb), [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript), and the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information.
|
||||
|
||||
## Improving this config
|
||||
|
||||
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
|
||||
|
||||
You can run tests with `npm test`.
|
||||
|
||||
You can make sure this module lints with itself using `npm run lint`.
|
||||
13
packages/eslint-config-airbnb-base/index.js
Normal file
13
packages/eslint-config-airbnb-base/index.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./legacy',
|
||||
'./rules/es6',
|
||||
].map(require.resolve),
|
||||
parserOptions: {
|
||||
ecmaVersion: 7,
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
strict: 2,
|
||||
}
|
||||
};
|
||||
20
packages/eslint-config-airbnb-base/legacy.js
Normal file
20
packages/eslint-config-airbnb-base/legacy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./rules/best-practices',
|
||||
'./rules/errors',
|
||||
'./rules/legacy',
|
||||
'./rules/node',
|
||||
'./rules/style',
|
||||
'./rules/variables'
|
||||
].map(require.resolve),
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
amd: false,
|
||||
mocha: false,
|
||||
jasmine: false
|
||||
},
|
||||
ecmaFeatures: {},
|
||||
globals: {},
|
||||
rules: {}
|
||||
};
|
||||
56
packages/eslint-config-airbnb-base/package.json
Normal file
56
packages/eslint-config-airbnb-base/package.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb-base",
|
||||
"version": "1.0.0",
|
||||
"description": "Airbnb's base JS ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"pretest": "eslint-find-rules --unused",
|
||||
"test": "npm run --silent lint && npm run --silent tests-only"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/airbnb/javascript"
|
||||
},
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"eslintconfig",
|
||||
"config",
|
||||
"airbnb",
|
||||
"javascript",
|
||||
"styleguide"
|
||||
],
|
||||
"author": "Jake Teton-Landis (https://twitter.com/@jitl)",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jake Teton-Landis",
|
||||
"url": "https://twitter.com/jitl"
|
||||
},
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
},
|
||||
{
|
||||
"name": "Harrison Shoff",
|
||||
"url": "https://twitter.com/hshoff"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/airbnb/javascript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"devDependencies": {
|
||||
"babel-tape-runner": "^1.3.1",
|
||||
"eslint": "^2.8.0",
|
||||
"eslint-find-rules": "^1.3.0",
|
||||
"eslint-plugin-import": "^1.5.0",
|
||||
"tape": "^4.5.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^2.8.0",
|
||||
"eslint-plugin-import": "^1.5.0"
|
||||
}
|
||||
}
|
||||
5
packages/eslint-config-airbnb-base/rules/.eslintrc.json
Normal file
5
packages/eslint-config-airbnb-base/rules/.eslintrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"rules": {
|
||||
"quote-props": 0
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ module.exports = {
|
||||
'ecmaVersion': 6,
|
||||
'sourceType': 'module',
|
||||
'ecmaFeatures': {
|
||||
'jsx': true,
|
||||
'generators': false,
|
||||
'objectLiteralDuplicateProperties': false
|
||||
}
|
||||
@@ -31,7 +31,7 @@ module.exports = {
|
||||
'indent': [2, 2, { 'SwitchCase': 1, 'VariableDeclarator': 1 }],
|
||||
// specify whether double or single quotes should be used in JSX attributes
|
||||
// http://eslint.org/docs/rules/jsx-quotes
|
||||
'jsx-quotes': [2, 'prefer-double'],
|
||||
'jsx-quotes': 0,
|
||||
// enforces spacing between keys and values in object literal properties
|
||||
'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }],
|
||||
// require a space before & after certain keywords
|
||||
9
packages/eslint-config-airbnb-base/test/.eslintrc
Normal file
9
packages/eslint-config-airbnb-base/test/.eslintrc
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"rules": {
|
||||
// disabled because I find it tedious to write tests while following this
|
||||
// rule
|
||||
"no-shadow": 0,
|
||||
// tests uses `t` for tape
|
||||
"id-length": [2, {"min": 2, "properties": "never", "exceptions": ["t"]}]
|
||||
}
|
||||
}
|
||||
29
packages/eslint-config-airbnb-base/test/test-base.js
Normal file
29
packages/eslint-config-airbnb-base/test/test-base.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import test from 'tape';
|
||||
|
||||
const index = require('../');
|
||||
|
||||
const files = { index };
|
||||
|
||||
fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
|
||||
files[name] = require(`../rules/${name}`); // eslint-disable-line global-require
|
||||
});
|
||||
|
||||
Object.keys(files).forEach(name => {
|
||||
const config = files[name];
|
||||
|
||||
test(`${name}: does not reference react`, t => {
|
||||
t.plan(2);
|
||||
|
||||
// scan plugins for react and fail if it is found
|
||||
const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') &&
|
||||
config.plugins.indexOf('react') !== -1;
|
||||
t.notOk(hasReactPlugin, 'there is no react plugin');
|
||||
|
||||
// scan rules for react/ and fail if any exist
|
||||
const reactRuleIds = Object.keys(config.rules)
|
||||
.filter(ruleId => ruleId.indexOf('react/') === 0);
|
||||
t.deepEquals(reactRuleIds, [], 'there are no react/ rules');
|
||||
});
|
||||
});
|
||||
@@ -10,27 +10,18 @@ We export three ESLint configurations for your usage.
|
||||
|
||||
### eslint-config-airbnb
|
||||
|
||||
Our default export contains all of our ESLint rules, including ECMAScript 6+
|
||||
and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`,
|
||||
and `eslint-plugin-jsx-a11y`.
|
||||
Our default export contains all of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-config-airbnb-base`, `eslint-plugin-import`, `eslint-plugin-react`, and `eslint-plugin-jsx-a11y`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint`
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint-config-airbnb-base eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint`
|
||||
2. add `"extends": "airbnb"` to your .eslintrc
|
||||
|
||||
### eslint-config-airbnb/base
|
||||
|
||||
Lints ES6+ but does not lint React. Requires `eslint` and
|
||||
`eslint-plugin-import`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint`
|
||||
2. add `"extends": "airbnb/base"` to your .eslintrc
|
||||
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
|
||||
### eslint-config-airbnb/legacy
|
||||
|
||||
Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
|
||||
|
||||
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint`
|
||||
2. add `"extends": "airbnb/legacy"` to your .eslintrc
|
||||
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
|
||||
|
||||
See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and
|
||||
the [ESlint config docs](http://eslint.org/docs/user-guide/configuring#extending-configuration-files)
|
||||
@@ -38,9 +29,7 @@ for more information.
|
||||
|
||||
## Improving this config
|
||||
|
||||
Consider adding test cases if you're making complicated rules changes, like
|
||||
anything involving regexes. Perhaps in a distant future, we could use literate
|
||||
programming to structure our README as test cases for our .eslintrc?
|
||||
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
|
||||
|
||||
You can run tests with `npm test`.
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./legacy',
|
||||
'./rules/es6',
|
||||
].map(require.resolve),
|
||||
rules: {}
|
||||
extends: ['eslint-config-airbnb-base'].map(require.resolve),
|
||||
rules: {},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./base',
|
||||
'./rules/strict',
|
||||
'eslint-config-airbnb-base',
|
||||
'eslint-config-airbnb-base/rules/strict',
|
||||
'./rules/react',
|
||||
'./rules/react-a11y',
|
||||
].map(require.resolve),
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'./rules/best-practices',
|
||||
'./rules/errors',
|
||||
'./rules/legacy',
|
||||
'./rules/node',
|
||||
'./rules/style',
|
||||
'./rules/variables'
|
||||
].map(require.resolve),
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
amd: false,
|
||||
mocha: false,
|
||||
jasmine: false
|
||||
},
|
||||
ecmaFeatures: {},
|
||||
globals: {},
|
||||
rules: {}
|
||||
extends: ['eslint-config-airbnb-base/legacy'].map(require.resolve),
|
||||
rules: {},
|
||||
};
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
"babel-tape-runner": "^1.3.1",
|
||||
"eslint": "^2.8.0",
|
||||
"eslint-find-rules": "^1.3.0",
|
||||
"eslint-config-airbnb-base": "^1.0.0",
|
||||
"eslint-plugin-jsx-a11y": "^0.6.2",
|
||||
"eslint-plugin-import": "^1.5.0",
|
||||
"eslint-plugin-jsx-a11y": "^0.6.2",
|
||||
"eslint-plugin-react": "^5.0.1",
|
||||
@@ -54,6 +56,7 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^2.8.0",
|
||||
"eslint-config-airbnb-base": "^1.0.0",
|
||||
"eslint-plugin-jsx-a11y": "^0.6.2",
|
||||
"eslint-plugin-import": "^1.5.0",
|
||||
"eslint-plugin-react": "^5.0.1"
|
||||
|
||||
5
packages/eslint-config-airbnb/rules/react.js
vendored
5
packages/eslint-config-airbnb/rules/react.js
vendored
@@ -2,6 +2,11 @@ module.exports = {
|
||||
'plugins': [
|
||||
'react'
|
||||
],
|
||||
'parserOptions': {
|
||||
'ecmaFeatures': {
|
||||
'jsx': true,
|
||||
},
|
||||
},
|
||||
'ecmaFeatures': {
|
||||
'jsx': true
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user