Skip to content

Commit a2d0469

Browse files
fsongaearon
authored andcommitted
Create a shareable ESLint configuration package (facebook#689)
* Move ESLint configuration to a separate package * Remove the ESLint configuration, moved to eslint-config-react-app * Update ESLint instructions * Pin the package versions in eslint-config-react-app * Add a README for eslint-config-react-app * Update README.md * Update README.md * Update README.md * Update README.md * Update package.json * Update package.json * Update production eslint-loader config * Add the ESLint config to devDependencies of the repo
1 parent 07623e2 commit a2d0469

File tree

12 files changed

+67
-19
lines changed

12 files changed

+67
-19
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "react-app"
3+
}

.eslintrc.js

-7
This file was deleted.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"test": "node packages/react-scripts/scripts/test.js --env=jsdom"
1111
},
1212
"devDependencies": {
13+
"babel-eslint": "6.1.2",
1314
"eslint": "3.5.0",
15+
"eslint-config-react-app": "file:packages/eslint-config-react-app",
1416
"eslint-plugin-flowtype": "2.18.1",
1517
"eslint-plugin-import": "1.12.0",
1618
"eslint-plugin-jsx-a11y": "2.2.2",
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# eslint-config-react-app
2+
3+
This package includes the shareable ESLint configuration used by [Create React App](https://github.com/facebookincubator/create-react-app).
4+
5+
## Usage in Create React App Projects
6+
7+
The easiest way to use this configuration is with [Create React App](https://github.com/facebookincubator/create-react-app), which includes it by default. **You don’t need to install it separately in Create React App projects.**
8+
9+
## Usage Outside of Create React App
10+
11+
If you want to use this ESLint configuration in a project not built with Create React App, you can install it with following steps.
12+
13+
First, install this package, ESLint and the necessary plugins.
14+
15+
```sh
16+
17+
```
18+
19+
Then create a file named `.eslintrc` with following contents in the root folder of your project:
20+
21+
```js
22+
{
23+
"extends": "react-app"
24+
}
25+
```
26+
27+
That's it! You can override the settings from `eslint-config-react-app` by editing the `.eslintrc` file. Learn more about [configuring ESLint](http://eslint.org/docs/user-guide/configuring) on the ESLint website.

packages/react-scripts/config/eslint.js packages/eslint-config-react-app/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @remove-on-eject-begin
21
/**
32
* Copyright (c) 2015-present, Facebook, Inc.
43
* All rights reserved.
@@ -7,7 +6,6 @@
76
* LICENSE file in the root directory of this source tree. An additional grant
87
* of patent rights can be found in the PATENTS file in the same directory.
98
*/
10-
// @remove-on-eject-end
119

1210
// Inspired by https://github.com/airbnb/javascript but less opinionated.
1311

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "eslint-config-react-app",
3+
"version": "0.1.0",
4+
"description": "ESLint configuration used by Create React App",
5+
"repository": "facebookincubator/create-react-app",
6+
"license": "BSD-3-Clause",
7+
"bugs": {
8+
"url": "https://github.com/facebookincubator/create-react-app/issues"
9+
},
10+
"files": [
11+
"index.js"
12+
],
13+
"peerDependencies": {
14+
"babel-eslint": "6.1.2",
15+
"eslint": "3.5.0",
16+
"eslint-plugin-flowtype": "2.18.1",
17+
"eslint-plugin-import": "1.12.0",
18+
"eslint-plugin-jsx-a11y": "2.2.2",
19+
"eslint-plugin-react": "5.2.2"
20+
}
21+
}

packages/react-scripts/.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "react-app"
3+
}

packages/react-scripts/config/webpack.config.dev.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ module.exports = {
165165
}
166166
]
167167
},
168+
// @remove-on-eject-begin
168169
// Point ESLint to our predefined config.
169170
eslint: {
170-
configFile: path.join(__dirname, 'eslint.js'),
171+
configFile: path.join(__dirname, '../.eslintrc'),
171172
useEslintrc: false
172173
},
174+
// @remove-on-eject-end
173175
// We use PostCSS for autoprefixing only.
174176
postcss: function() {
175177
return [

packages/react-scripts/config/webpack.config.prod.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ module.exports = {
175175
}
176176
]
177177
},
178+
// @remove-on-eject-begin
178179
// Point ESLint to our predefined config.
179180
eslint: {
180181
// TODO: consider separate config for production,
181182
// e.g. to enable no-console and no-debugger only in production.
182-
configFile: path.join(__dirname, 'eslint.js'),
183+
configFile: path.join(__dirname, '../.eslintrc'),
183184
useEslintrc: false
184185
},
186+
// @remove-on-eject-end
185187
// We use PostCSS for autoprefixing only.
186188
postcss: function() {
187189
return [

packages/react-scripts/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"url": "https://github.com/facebookincubator/create-react-app/issues"
1212
},
1313
"files": [
14+
".eslintrc",
1415
"bin",
1516
"config",
1617
"scripts",
@@ -40,6 +41,7 @@
4041
"css-loader": "0.24.0",
4142
"detect-port": "1.0.0",
4243
"eslint": "3.5.0",
44+
"eslint-config-react-app": "0.1.0",
4345
"eslint-loader": "1.5.0",
4446
"eslint-plugin-flowtype": "2.18.1",
4547
"eslint-plugin-import": "1.12.0",

packages/react-scripts/scripts/eject.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ prompt(
2929
var ownPath = path.join(__dirname, '..');
3030
var appPath = path.join(ownPath, '..', '..');
3131
var files = [
32+
'.eslintrc',
3233
path.join('config', 'babel.dev.js'),
3334
path.join('config', 'babel.prod.js'),
3435
path.join('config', 'flow', 'css.js.flow'),
3536
path.join('config', 'flow', 'file.js.flow'),
36-
path.join('config', 'eslint.js'),
3737
path.join('config', 'paths.js'),
3838
path.join('config', 'env.js'),
3939
path.join('config', 'polyfills.js'),
@@ -111,11 +111,6 @@ prompt(
111111
filePath => path.join('<rootDir>', filePath)
112112
);
113113

114-
// Explicitly specify ESLint config path for editor plugins
115-
appPackage.eslintConfig = {
116-
extends: './config/eslint.js',
117-
};
118-
119114
console.log('Writing package.json');
120115
fs.writeFileSync(
121116
path.join(appPath, 'package.json'),

packages/react-scripts/template/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ Then add this block to the `package.json` file of your project:
163163
{
164164
// ...
165165
"eslintConfig": {
166-
"extends": "./node_modules/react-scripts/config/eslint.js"
166+
"extends": "react-app"
167167
}
168168
}
169169
```
170170

171171
Finally, you will need to install some packages *globally*:
172172

173173
```sh
174-
npm install -g eslint babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
174+
npm install -g eslint-config-react-app eslint babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
175175
```
176176

177177
We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months.

0 commit comments

Comments
 (0)