Skip to content

Commit 7a5d4ca

Browse files
committed
Merge pull request #825 from lencioni/eslint-plugin-import
[eslint config] [semver-minor] Enable import/no-unresolved and import/export rules
2 parents 1973e5c + 35be2cc commit 7a5d4ca

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

packages/eslint-config-airbnb/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ We export three ESLint configurations for your usage.
1111
### eslint-config-airbnb
1212

1313
Our default export contains all of our ESLint rules, including EcmaScript 6+
14-
and React. It requires `eslint`, `eslint-plugin-react`, and `eslint-plugin-jsx-a11y`.
14+
and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`,
15+
and `eslint-plugin-jsx-a11y`.
1516

16-
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-react eslint-plugin-jsx-a11y eslint`
17+
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y eslint`
1718
2. add `"extends": "airbnb"` to your .eslintrc
1819

1920
### eslint-config-airbnb/base
2021

2122
Lints ES6+ but does not lint React. Requires `eslint`.
2223

23-
1. `npm install --save-dev eslint-config-airbnb eslint`
24+
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint`
2425
2. add `"extends": "airbnb/base"` to your .eslintrc
2526

2627
### eslint-config-airbnb/legacy
2728

2829
Lints ES5 and below. Only requires `eslint`.
2930

30-
1. `npm install --save-dev eslint-config-airbnb eslint`
31+
1. `npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint`
3132
2. add `"extends": "airbnb/legacy"` to your .eslintrc
3233

3334
See [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript) and

packages/eslint-config-airbnb/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"babel-tape-runner": "^1.3.1",
4646
"eslint": "^2.7.0",
4747
"eslint-plugin-jsx-a11y": "^0.6.2",
48+
"eslint-plugin-import": "^1.4.0",
4849
"eslint-plugin-react": "^4.3.0",
4950
"react": "^0.14.8",
5051
"tape": "^4.5.1",
@@ -53,6 +54,7 @@
5354
"peerDependencies": {
5455
"eslint": "^2.7.0",
5556
"eslint-plugin-jsx-a11y": "^0.6.2",
57+
"eslint-plugin-import": "^1.4.0",
5658
"eslint-plugin-react": "^4.3.0"
5759
}
5860
}

packages/eslint-config-airbnb/rules/es6.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module.exports = {
1111
'objectLiteralDuplicateProperties': false
1212
}
1313
},
14+
'plugins': [
15+
'import'
16+
],
1417
'rules': {
1518
// enforces no braces where they can be omitted
1619
// http://eslint.org/docs/rules/arrow-body-style
@@ -83,6 +86,19 @@ module.exports = {
8386
'template-curly-spacing': 2,
8487
// enforce spacing around the * in yield* expressions
8588
// http://eslint.org/docs/rules/yield-star-spacing
86-
'yield-star-spacing': [2, 'after']
89+
'yield-star-spacing': [2, 'after'],
90+
// disallow invalid exports, e.g. multiple defaults
91+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
92+
'import/export': 2,
93+
// ensure imports point to files/modules that can be resolved
94+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
95+
'import/no-unresolved': [2, { 'commonjs': true }]
96+
},
97+
'settings': {
98+
'import/resolver': {
99+
'node': {
100+
'extensions': ['.js', '.json']
101+
}
102+
}
87103
}
88104
};

packages/eslint-config-airbnb/rules/node.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ module.exports = {
22
'env': {
33
'node': true
44
},
5+
'plugins': [
6+
'import'
7+
],
58
'rules': {
69
// enforce return after a callback
710
'callback-return': 0,
@@ -18,6 +21,16 @@ module.exports = {
1821
// restrict usage of specified node modules
1922
'no-restricted-modules': 0,
2023
// disallow use of synchronous methods (off by default)
21-
'no-sync': 0
24+
'no-sync': 0,
25+
// ensure imports point to files/modules that can be resolved
26+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
27+
'import/no-unresolved': [2, { 'commonjs': true }]
28+
},
29+
'settings': {
30+
'import/resolver': {
31+
'node': {
32+
'extensions': ['.js', '.json']
33+
}
34+
}
2235
}
2336
};

packages/eslint-config-airbnb/rules/react.js

+7
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@ module.exports = {
166166
assignment: true,
167167
return: true
168168
}],
169+
},
170+
'settings': {
171+
'import/resolver': {
172+
'node': {
173+
'extensions': ['.js', '.jsx', '.json']
174+
}
175+
}
169176
}
170177
};

packages/eslint-config-airbnb/test/test-base.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ Object.keys(files).forEach(name => {
2020
test(`${name}: does not reference react`, t => {
2121
t.plan(2);
2222

23-
t.notOk(config.plugins, 'plugins is unspecified');
23+
// scan plugins for react and fail if it is found
24+
const hasReactPlugin = Object.prototype.hasOwnProperty.call(config, 'plugins') &&
25+
config.plugins.indexOf('react') !== -1;
26+
t.notOk(hasReactPlugin, 'there is no react plugin');
2427

2528
// scan rules for react/ and fail if any exist
2629
const reactRuleIds = Object.keys(config.rules)

0 commit comments

Comments
 (0)