Skip to content

Commit 1eea3ad

Browse files
committed
Forbid Webpack loader syntax in imports
Enable no-webpack-loader-syntax rule in eslint-config-react-app.
1 parent 0ad930e commit 1eea3ad

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"eslint": "3.5.0",
1515
"eslint-config-react-app": "file:packages/eslint-config-react-app",
1616
"eslint-plugin-flowtype": "2.18.1",
17-
"eslint-plugin-import": "1.12.0",
17+
"eslint-plugin-import": "2.0.0",
1818
"eslint-plugin-jsx-a11y": "2.2.2",
1919
"eslint-plugin-react": "6.3.0",
2020
"lerna": "2.0.0-beta.29"

packages/eslint-config-react-app/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you want to use this ESLint configuration in a project not built with Create
1717
First, install this package, ESLint and the necessary plugins.
1818

1919
```sh
20-
npm install --save-dev eslint-config-react-app [email protected] [email protected] [email protected] eslint-plugin-import@1.12.0 [email protected] eslint-plugin-react@5.2.2
20+
npm install --save-dev eslint-config-react-app [email protected] [email protected] [email protected] eslint-plugin-import@2.0.0 [email protected] eslint-plugin-react@6.3.0
2121
```
2222

2323
Then create a file named `.eslintrc` with following contents in the root folder of your project:

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ module.exports = {
2121

2222
parser: 'babel-eslint',
2323

24-
// import plugin is temporarily disabled, scroll below to see why
25-
plugins: [/*'import', */'flowtype', 'jsx-a11y', 'react'],
24+
plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],
2625

2726
env: {
2827
browser: true,
@@ -170,6 +169,9 @@ module.exports = {
170169
// This is probably fixable with a patch to eslint-loader.
171170
// When file A is saved, we want to invalidate all files that import it
172171
// *and* that currently have lint errors. This should fix the problem.
172+
// (As an exception, import/no-webpack-loader-syntax can be enabled already
173+
// because it doesn't depend on whether the file exists, so this issue
174+
// doesn't apply to it.)
173175

174176
// 'import/default': 'warn',
175177
// 'import/export': 'warn',
@@ -181,6 +183,9 @@ module.exports = {
181183
// 'import/no-named-as-default': 'warn',
182184
// 'import/no-named-as-default-member': 'warn',
183185
// 'import/no-unresolved': ['warn', { commonjs: true }],
186+
// We don't support configuring Webpack using import source strings, so this
187+
// is always an error.
188+
'import/no-webpack-loader-syntax': 'error',
184189

185190
// https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
186191
'react/jsx-equals-spacing': ['warn', 'never'],

packages/eslint-config-react-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"babel-eslint": "6.1.2",
1515
"eslint": "3.5.0",
1616
"eslint-plugin-flowtype": "2.18.1",
17-
"eslint-plugin-import": "1.12.0",
17+
"eslint-plugin-import": "2.0.0",
1818
"eslint-plugin-jsx-a11y": "2.2.2",
1919
"eslint-plugin-react": "6.3.0"
2020
}

packages/react-scripts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"eslint-config-react-app": "^0.2.1",
4141
"eslint-loader": "1.5.0",
4242
"eslint-plugin-flowtype": "2.18.1",
43-
"eslint-plugin-import": "1.12.0",
43+
"eslint-plugin-import": "2.0.0",
4444
"eslint-plugin-jsx-a11y": "2.2.2",
4545
"eslint-plugin-react": "6.3.0",
4646
"extract-text-webpack-plugin": "1.0.1",

packages/react-scripts/template/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Then add this block to the `package.json` file of your project:
174174
Finally, you will need to install some packages *globally*:
175175

176176
```sh
177-
177+
178178
```
179179

180180
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.
@@ -362,7 +362,7 @@ Inside `index.html`, you can use it like this:
362362

363363
Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build.
364364

365-
When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL.
365+
When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL.
366366

367367
In JavaScript code, you can use `process.env.PUBLIC_URL` for similar purposes:
368368

0 commit comments

Comments
 (0)