Skip to content

Commit f3ff68f

Browse files
authored
Merge pull request #1055 from benmosher/release-2.10.0
Release 2.10.0
2 parents 180d71a + 47ac30f commit f3ff68f

34 files changed

+1122
-62
lines changed

CHANGELOG.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
55

66
## [Unreleased]
77

8+
9+
## [2.10.0] - 2018-03-29
10+
### Added
11+
- Autofixer for [`order`] rule ([#711], thanks [@tihonove])
12+
- Add [`no-cycle`] rule: reports import cycles.
13+
814
## [2.9.0] - 2018-02-21
915
### Added
1016
- Add [`group-exports`] rule: style-guide rule to report use of multiple named exports ([#721], thanks [@robertrossmann])
1117
- Add [`no-self-import`] rule: forbids a module from importing itself. ([#727], [#449], [#447], thanks [@giodamelio]).
1218
- Add [`no-default-export`] rule ([#889], thanks [@isiahmeadows])
19+
- Add [`no-useless-path-segments`] rule ([#912], thanks [@graingert] and [@danny-andrews])
1320
- ... and more! check the commits for v[2.9.0]
1421

1522
## [2.8.0] - 2017-10-18
@@ -440,6 +447,8 @@ for info on changes for earlier releases.
440447
[`group-exports`]: ./docs/rules/group-exports.md
441448
[`no-self-import`]: ./docs/rules/no-self-import.md
442449
[`no-default-export`]: ./docs/rules/no-default-export.md
450+
[`no-useless-path-segments`]: ./docs/rules/no-useless-path-segments.md
451+
[`no-cycle`]: ./docs/rules/no-cycle.md
443452

444453
[`memo-parser`]: ./memo-parser/README.md
445454

@@ -512,6 +521,7 @@ for info on changes for earlier releases.
512521
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
513522
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
514523
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314
524+
[#912]: https://github.com/benmosher/eslint-plugin-import/pull/912
515525

516526
[#886]: https://github.com/benmosher/eslint-plugin-import/issues/886
517527
[#863]: https://github.com/benmosher/eslint-plugin-import/issues/863
@@ -579,7 +589,8 @@ for info on changes for earlier releases.
579589
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
580590
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89
581591

582-
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...HEAD
592+
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.10.0...HEAD
593+
[2.10.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...v2.10.0
583594
[2.9.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.8.0...v2.9.0
584595
[2.8.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.7.0...v2.8.0
585596
[2.7.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.6.1...v2.7.0
@@ -676,5 +687,8 @@ for info on changes for earlier releases.
676687
[@mplewis]: https://github.com/mplewis
677688
[@rosswarren]: https://github.com/rosswarren
678689
[@alexgorbatchev]: https://github.com/alexgorbatchev
690+
[@tihonove]: https://github.com/tihonove
679691
[@robertrossmann]: https://github.com/robertrossmann
680692
[@isiahmeadows]: https://github.com/isiahmeadows
693+
[@graingert]: https://github.com/graingert
694+
[@danny-andrews]: https://github.com/dany-andrews

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
1212

1313
## Rules
1414

15-
**Static analysis:**
15+
### Static analysis
1616

1717
* Ensure imports point to a file/module that can be resolved. ([`no-unresolved`])
1818
* Ensure named imports correspond to a named export in the remote file. ([`named`])
@@ -24,6 +24,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
2424
* Prevent importing the submodules of other modules ([`no-internal-modules`])
2525
* Forbid Webpack loader syntax in imports ([`no-webpack-loader-syntax`])
2626
* Forbid a module from importing itself ([`no-self-import`])
27+
* Forbid a module from importing a module with a dependency path back to itself ([`no-cycle`])
2728

2829
[`no-unresolved`]: ./docs/rules/no-unresolved.md
2930
[`named`]: ./docs/rules/named.md
@@ -35,8 +36,9 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
3536
[`no-internal-modules`]: ./docs/rules/no-internal-modules.md
3637
[`no-webpack-loader-syntax`]: ./docs/rules/no-webpack-loader-syntax.md
3738
[`no-self-import`]: ./docs/rules/no-self-import.md
39+
[`no-cycle`]: ./docs/rules/no-cycle.md
3840

39-
**Helpful warnings:**
41+
### Helpful warnings
4042

4143

4244
* Report any invalid exports, i.e. re-export of the same name ([`export`])
@@ -53,7 +55,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
5355
[`no-extraneous-dependencies`]: ./docs/rules/no-extraneous-dependencies.md
5456
[`no-mutable-exports`]: ./docs/rules/no-mutable-exports.md
5557

56-
**Module systems:**
58+
### Module systems
5759

5860
* Report potentially ambiguous parse goal (`script` vs. `module`) ([`unambiguous`])
5961
* Report CommonJS `require` calls and `module.exports` or `exports.*`. ([`no-commonjs`])
@@ -66,7 +68,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
6668
[`no-nodejs-modules`]: ./docs/rules/no-nodejs-modules.md
6769

6870

69-
**Style guide:**
71+
### Style guide
7072

7173
* Ensure all imports appear before other statements ([`first`])
7274
* Ensure all exports appear after other statements ([`exports-last`])

appveyor.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ install:
2121
}
2222
- npm install
2323

24+
# fix symlinks
25+
- cmd: git config core.symlinks true
26+
- cmd: git reset --hard
27+
2428
# todo: learn how to do this for all .\resolvers\* on Windows
2529
- cd .\resolvers\webpack && npm install && cd ..\..
2630
- cd .\resolvers\node && npm install && cd ..\..

docs/rules/extensions.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,33 @@ In order to provide a consistent use of file extensions across your code base, t
88

99
This rule either takes one string option, one object option, or a string and an object option. If it is the string `"never"` (the default value), then the rule forbids the use for any extension. If it is the string `"always"`, then the rule enforces the use of extensions for all import statements. If it is the string `"ignorePackages"`, then the rule enforces the use of extensions for all import statements except package imports.
1010

11-
By providing an object you can configure each extension separately, so for example `{ "js": "always", "json": "never" }` would always enforce the use of the `.js` extension but never allow the use of the `.json` extension.
11+
```
12+
"import/extensions": [<severity>, "never" | "always" | "ignorePackages"]
13+
```
14+
15+
By providing an object you can configure each extension separately.
16+
17+
```
18+
"import/extensions": [<severity>, {
19+
<extension>: "never" | "always" | "ignorePackages"
20+
}]
21+
```
22+
23+
For example `{ "js": "always", "json": "never" }` would always enforce the use of the `.js` extension but never allow the use of the `.json` extension.
24+
25+
By providing both a string and an object, the string will set the default setting for all extensions, and the object can be used to set granular overrides for specific extensions.
26+
27+
```
28+
"import/extensions": [
29+
<severity>,
30+
"never" | "always" | "ignorePackages",
31+
{
32+
<extension>: "never" | "always" | "ignorePackages"
33+
}
34+
]
35+
```
1236

13-
By providing both a string and an object, the string will set the default setting for all extensions, and the object can be used to set granular overrides for specific extensions. For example, `[<enabled>, "never", { "svg": "always" }]` would require that all extensions are omitted, except for "svg".
37+
For example, `["error", "never", { "svg": "always" }]` would require that all extensions are omitted, except for "svg".
1438

1539
### Exception
1640

@@ -110,7 +134,7 @@ import express from 'express';
110134

111135
```
112136

113-
The following patterns are not considered problems when configuration set to `[ 'always', {ignorePackages: true} ]`:
137+
The following patterns are not considered problems when configuration set to `['error', 'always', {ignorePackages: true} ]`:
114138

115139
```js
116140
import Component from './Component.jsx';

docs/rules/no-cycle.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# import/no-cycle
2+
3+
Ensures that there is no resolvable path back to this module via its dependencies.
4+
5+
This includes cycles of depth 1 (imported module imports me) to `Infinity`, if the
6+
[`maxDepth`](#maxdepth) option is not set.
7+
8+
```js
9+
// dep-b.js
10+
import './dep-a.js'
11+
12+
export function b() { /* ... */ }
13+
14+
// dep-a.js
15+
import { b } from './dep-b.js' // reported: Dependency cycle detected.
16+
```
17+
18+
This rule does _not_ detect imports that resolve directly to the linted module;
19+
for that, see [`no-self-import`].
20+
21+
22+
## Rule Details
23+
24+
### Options
25+
26+
By default, this rule only detects cycles for ES6 imports, but see the [`no-unresolved` options](./no-unresolved.md#options) as this rule also supports the same `commonjs` and `amd` flags. However, these flags only impact which import types are _linted_; the
27+
import/export infrastructure only registers `import` statements in dependencies, so
28+
cycles created by `require` within imported modules may not be detected.
29+
30+
#### `maxDepth`
31+
32+
There is a `maxDepth` option available to prevent full expansion of very deep dependency trees:
33+
34+
```js
35+
/*eslint import/no-unresolved: [2, { maxDepth: 1 }]*/
36+
37+
// dep-c.js
38+
import './dep-a.js'
39+
40+
// dep-b.js
41+
import './dep-c.js'
42+
43+
export function b() { /* ... */ }
44+
45+
// dep-a.js
46+
import { b } from './dep-b.js' // not reported as the cycle is at depth 2
47+
```
48+
49+
This is not necessarily recommended, but available as a cost/benefit tradeoff mechanism
50+
for reducing total project lint time, if needed.
51+
52+
## When Not To Use It
53+
54+
This rule is comparatively computationally expensive. If you are pressed for lint
55+
time, or don't think you have an issue with dependency cycles, you may not want
56+
this rule enabled.
57+
58+
## Further Reading
59+
60+
- [Original inspiring issue](https://github.com/benmosher/eslint-plugin-import/issues/941)
61+
- Rule to detect that module imports itself: [`no-self-import`]
62+
63+
[`no-self-import`]: ./no-self-import.md

docs/rules/order.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# import/order: Enforce a convention in module import order
22

3-
Enforce a convention in the order of `require()` / `import` statements. The order is as shown in the following example:
3+
Enforce a convention in the order of `require()` / `import` statements.
4+
+(fixable) The `--fix` option on the [command line] automatically fixes problems reported by this rule.
5+
The order is as shown in the following example:
46

57
```js
68
// 1. node "builtin" modules

import.sublime-project

+4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
},
1717
"eslint_d":
1818
{
19+
"disable": true,
1920
"chdir": "${project}"
2021
}
22+
},
23+
"paths": {
24+
"osx": ["${project}/node_modules/.bin"]
2125
}
2226
}
2327
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-import",
3-
"version": "2.9.0",
3+
"version": "2.10.0",
44
"description": "Import with sanity.",
55
"engines": {
66
"node": ">=4"
@@ -84,7 +84,7 @@
8484
"debug": "^2.6.8",
8585
"doctrine": "1.5.0",
8686
"eslint-import-resolver-node": "^0.3.1",
87-
"eslint-module-utils": "^2.1.1",
87+
"eslint-module-utils": "^2.2.0",
8888
"has": "^1.0.1",
8989
"lodash": "^4.17.4",
9090
"minimatch": "^3.0.3",

resolvers/webpack/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
55

66
## Unreleased
77

8+
9+
## 0.9.0 - 2018-03-29
10+
### Breaking
11+
- Fix with `pnpm` by bumping `resolve` ([#968])
12+
813
## 0.8.4 - 2018-01-05
914
### Changed
1015
- allow newer version of node-libs-browser ([#969])
@@ -93,6 +98,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
9398
Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]).
9499

95100
[#969]: https://github.com/benmosher/eslint-plugin-import/pull/969
101+
[#968]: https://github.com/benmosher/eslint-plugin-import/pull/968
96102
[#683]: https://github.com/benmosher/eslint-plugin-import/pull/683
97103
[#572]: https://github.com/benmosher/eslint-plugin-import/pull/572
98104
[#569]: https://github.com/benmosher/eslint-plugin-import/pull/569

resolvers/webpack/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ exports.resolve = function (source, file, settings) {
4747

4848
var configPath = get(settings, 'config')
4949
, configIndex = get(settings, 'config-index')
50+
, env = get(settings, 'env')
5051
, packageDir
5152

5253
log('Config path from settings:', configPath)
@@ -82,7 +83,7 @@ exports.resolve = function (source, file, settings) {
8283
}
8384

8485
if (typeof webpackConfig === 'function') {
85-
webpackConfig = webpackConfig()
86+
webpackConfig = webpackConfig(env)
8687
}
8788

8889
if (Array.isArray(webpackConfig)) {
@@ -122,8 +123,8 @@ function createResolveSync(configPath, webpackConfig) {
122123
}
123124

124125
try {
125-
var webpackFilename = resolve.sync('webpack', { basedir })
126-
var webpackResolveOpts = { basedir: path.dirname(webpackFilename) }
126+
var webpackFilename = resolve.sync('webpack', { basedir, preserveSymlinks: false })
127+
var webpackResolveOpts = { basedir: path.dirname(webpackFilename), preserveSymlinks: false }
127128

128129
webpackRequire = function (id) {
129130
return require(resolve.sync(id, webpackResolveOpts))

resolvers/webpack/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-import-resolver-webpack",
3-
"version": "0.8.4",
3+
"version": "0.9.0",
44
"description": "Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.",
55
"main": "index.js",
66
"scripts": {
@@ -27,7 +27,7 @@
2727
"bugs": {
2828
"url": "https://github.com/benmosher/eslint-plugin-import/issues"
2929
},
30-
"homepage": "https://github.com/benmosher/eslint-plugin-import#readme",
30+
"homepage": "https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/webpack",
3131
"dependencies": {
3232
"array-find": "^1.0.0",
3333
"debug": "^2.6.8",
@@ -38,7 +38,7 @@
3838
"is-absolute": "^0.2.3",
3939
"lodash.get": "^4.4.2",
4040
"node-libs-browser": "^1.0.0 || ^2.0.0",
41-
"resolve": "^1.2.0",
41+
"resolve": "^1.4.0",
4242
"semver": "^5.3.0"
4343
},
4444
"peerDependencies": {

resolvers/webpack/test/config.js

+12
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,16 @@ describe("config", function () {
9191
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'))
9292
})
9393

94+
it('finds the config at option env when config is a function', function() {
95+
var settings = {
96+
config: require(path.join(__dirname, './files/webpack.function.config.js')),
97+
env: {
98+
dummy: true,
99+
},
100+
}
101+
102+
expect(resolve('bar', file, settings)).to.have.property('path')
103+
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'))
104+
})
105+
94106
})

resolvers/webpack/test/files/some/goofy/path/bar.js

Whitespace-only changes.

resolvers/webpack/test/files/webpack.function.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
var path = require('path')
22
var pluginsTest = require('webpack-resolver-plugin-test')
33

4-
module.exports = function() {
4+
module.exports = function(env) {
55
return {
66
resolve: {
77
alias: {
88
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
9+
'bar': env ? path.join(__dirname, 'some', 'goofy', 'path', 'bar.js') : undefined,
910
'some-alias': path.join(__dirname, 'some'),
1011
},
1112
modules: [

0 commit comments

Comments
 (0)