[eslint config] [eslint config base] [breaking] Migrate non-React rules to a separate linter config.

This commit is contained in:
Jordan Harband
2016-04-16 11:04:28 -07:00
parent bdbecf23e2
commit 52d3401f95
27 changed files with 199 additions and 56 deletions

View 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
}
}

View File

@@ -0,0 +1,3 @@
1.0.0 / 2016-04-16
==================
- Initial commmit; moved content over from `eslint-config-airbnb` package.

View File

@@ -0,0 +1,33 @@
# eslint-config-airbnb-base
[![npm version](https://badge.fury.io/js/eslint-config-airbnb-base.svg)](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`.

View File

@@ -0,0 +1,13 @@
module.exports = {
extends: [
'./legacy',
'./rules/es6',
].map(require.resolve),
parserOptions: {
ecmaVersion: 7,
sourceType: 'module',
},
rules: {
strict: 2,
}
};

View 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: {}
};

View 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"
}
}

View File

@@ -0,0 +1,5 @@
{
"rules": {
"quote-props": 0
}
}

View File

@@ -6,7 +6,6 @@ module.exports = {
'ecmaVersion': 6,
'sourceType': 'module',
'ecmaFeatures': {
'jsx': true,
'generators': false,
'objectLiteralDuplicateProperties': false
}

View File

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

View 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"]}]
}
}

View 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');
});
});

View File

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

View File

@@ -1,7 +1,4 @@
module.exports = {
extends: [
'./legacy',
'./rules/es6',
].map(require.resolve),
rules: {}
extends: ['eslint-config-airbnb-base'].map(require.resolve),
rules: {},
};

View File

@@ -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),

View File

@@ -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: {},
};

View File

@@ -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"

View File

@@ -2,6 +2,11 @@ module.exports = {
'plugins': [
'react'
],
'parserOptions': {
'ecmaFeatures': {
'jsx': true,
},
},
'ecmaFeatures': {
'jsx': true
},