Skip to content

Commit

Permalink
[eslint config] [eslint config base] [breaking] Migrate non-React rul…
Browse files Browse the repository at this point in the history
…es to a separate linter config.
  • Loading branch information
ljharb committed Apr 16, 2016
1 parent bdbecf2 commit 52d3401
Show file tree
Hide file tree
Showing 27 changed files with 199 additions and 56 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_js:
- "iojs"
env:
- 'TEST_DIR=packages/eslint-config-airbnb'
- 'TEST_DIR=packages/eslint-config-airbnb-base'
before_install:
- 'cd $TEST_DIR'
- 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*A mostly reasonable approach to JavaScript*

[![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb.svg)](https://www.npmjs.com/package/eslint-config-airbnb)
[![Downloads](https://img.shields.io/npm/dm/eslint-config-airbnb-base.svg)](https://www.npmjs.com/package/eslint-config-airbnb-base)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Other Style Guides
Expand Down
11 changes: 0 additions & 11 deletions linters/README.md

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "2.0.0",
"description": "A mostly reasonable approach to JavaScript.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"publish-all": "npm publish && cd ./packages/eslint-config-airbnb && npm publish"
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-config-airbnb-base/.eslintrc
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions packages/eslint-config-airbnb-base/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0.0 / 2016-04-16
==================
- Initial commmit; moved content over from `eslint-config-airbnb` package.
33 changes: 33 additions & 0 deletions packages/eslint-config-airbnb-base/README.md
Original file line number Diff line number Diff line change
@@ -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`.
13 changes: 13 additions & 0 deletions packages/eslint-config-airbnb-base/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: [
'./legacy',
'./rules/es6',
].map(require.resolve),
parserOptions: {
ecmaVersion: 7,
sourceType: 'module',
},
rules: {
strict: 2,
}
};
20 changes: 20 additions & 0 deletions packages/eslint-config-airbnb-base/legacy.js
Original file line number Diff line number Diff line change
@@ -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 changes: 56 additions & 0 deletions packages/eslint-config-airbnb-base/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions packages/eslint-config-airbnb-base/rules/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"quote-props": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
'ecmaVersion': 6,
'sourceType': 'module',
'ecmaFeatures': {
'jsx': true,
'generators': false,
'objectLiteralDuplicateProperties': false
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/eslint-config-airbnb-base/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions packages/eslint-config-airbnb-base/test/test-base.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
21 changes: 5 additions & 16 deletions packages/eslint-config-airbnb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,26 @@ 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)
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`.

Expand Down
7 changes: 2 additions & 5 deletions packages/eslint-config-airbnb/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
extends: [
'./legacy',
'./rules/es6',
].map(require.resolve),
rules: {}
extends: ['eslint-config-airbnb-base'].map(require.resolve),
rules: {},
};
4 changes: 2 additions & 2 deletions packages/eslint-config-airbnb/index.js
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
20 changes: 2 additions & 18 deletions packages/eslint-config-airbnb/legacy.js
Original file line number Diff line number Diff line change
@@ -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: {},
};
3 changes: 3 additions & 0 deletions packages/eslint-config-airbnb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-config-airbnb/rules/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module.exports = {
'plugins': [
'react'
],
'parserOptions': {
'ecmaFeatures': {
'jsx': true,
},
},
'ecmaFeatures': {
'jsx': true
},
Expand Down

0 comments on commit 52d3401

Please sign in to comment.