Skip to content

Commit

Permalink
Merge pull request #1055 from benmosher/release-2.10.0
Browse files Browse the repository at this point in the history
Release 2.10.0
  • Loading branch information
benmosher authored Mar 30, 2018
2 parents 180d71a + 47ac30f commit f3ff68f
Show file tree
Hide file tree
Showing 34 changed files with 1,122 additions and 62 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]


## [2.10.0] - 2018-03-29
### Added
- Autofixer for [`order`] rule ([#711], thanks [@tihonove])
- Add [`no-cycle`] rule: reports import cycles.

## [2.9.0] - 2018-02-21
### Added
- Add [`group-exports`] rule: style-guide rule to report use of multiple named exports ([#721], thanks [@robertrossmann])
- Add [`no-self-import`] rule: forbids a module from importing itself. ([#727], [#449], [#447], thanks [@giodamelio]).
- Add [`no-default-export`] rule ([#889], thanks [@isiahmeadows])
- Add [`no-useless-path-segments`] rule ([#912], thanks [@graingert] and [@danny-andrews])
- ... and more! check the commits for v[2.9.0]

## [2.8.0] - 2017-10-18
Expand Down Expand Up @@ -440,6 +447,8 @@ for info on changes for earlier releases.
[`group-exports`]: ./docs/rules/group-exports.md
[`no-self-import`]: ./docs/rules/no-self-import.md
[`no-default-export`]: ./docs/rules/no-default-export.md
[`no-useless-path-segments`]: ./docs/rules/no-useless-path-segments.md
[`no-cycle`]: ./docs/rules/no-cycle.md

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

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

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

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.10.0...HEAD
[2.10.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...v2.10.0
[2.9.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.8.0...v2.9.0
[2.8.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.7.0...v2.8.0
[2.7.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.6.1...v2.7.0
Expand Down Expand Up @@ -676,5 +687,8 @@ for info on changes for earlier releases.
[@mplewis]: https://github.com/mplewis
[@rosswarren]: https://github.com/rosswarren
[@alexgorbatchev]: https://github.com/alexgorbatchev
[@tihonove]: https://github.com/tihonove
[@robertrossmann]: https://github.com/robertrossmann
[@isiahmeadows]: https://github.com/isiahmeadows
[@graingert]: https://github.com/graingert
[@danny-andrews]: https://github.com/dany-andrews
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a

## Rules

**Static analysis:**
### Static analysis

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

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

**Helpful warnings:**
### Helpful warnings


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

**Module systems:**
### Module systems

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


**Style guide:**
### Style guide

* Ensure all imports appear before other statements ([`first`])
* Ensure all exports appear after other statements ([`exports-last`])
Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ install:
}
- npm install

# fix symlinks
- cmd: git config core.symlinks true
- cmd: git reset --hard

# todo: learn how to do this for all .\resolvers\* on Windows
- cd .\resolvers\webpack && npm install && cd ..\..
- cd .\resolvers\node && npm install && cd ..\..
Expand Down
30 changes: 27 additions & 3 deletions docs/rules/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,33 @@ In order to provide a consistent use of file extensions across your code base, t

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.

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.
```
"import/extensions": [<severity>, "never" | "always" | "ignorePackages"]
```

By providing an object you can configure each extension separately.

```
"import/extensions": [<severity>, {
<extension>: "never" | "always" | "ignorePackages"
}]
```

For example `{ "js": "always", "json": "never" }` would always enforce the use of the `.js` extension but never allow the use of the `.json` extension.

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.

```
"import/extensions": [
<severity>,
"never" | "always" | "ignorePackages",
{
<extension>: "never" | "always" | "ignorePackages"
}
]
```

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".
For example, `["error", "never", { "svg": "always" }]` would require that all extensions are omitted, except for "svg".

### Exception

Expand Down Expand Up @@ -110,7 +134,7 @@ import express from 'express';

```

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

```js
import Component from './Component.jsx';
Expand Down
63 changes: 63 additions & 0 deletions docs/rules/no-cycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# import/no-cycle

Ensures that there is no resolvable path back to this module via its dependencies.

This includes cycles of depth 1 (imported module imports me) to `Infinity`, if the
[`maxDepth`](#maxdepth) option is not set.

```js
// dep-b.js
import './dep-a.js'

export function b() { /* ... */ }

// dep-a.js
import { b } from './dep-b.js' // reported: Dependency cycle detected.
```

This rule does _not_ detect imports that resolve directly to the linted module;
for that, see [`no-self-import`].


## Rule Details

### Options

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
import/export infrastructure only registers `import` statements in dependencies, so
cycles created by `require` within imported modules may not be detected.

#### `maxDepth`

There is a `maxDepth` option available to prevent full expansion of very deep dependency trees:

```js
/*eslint import/no-unresolved: [2, { maxDepth: 1 }]*/

// dep-c.js
import './dep-a.js'

// dep-b.js
import './dep-c.js'

export function b() { /* ... */ }

// dep-a.js
import { b } from './dep-b.js' // not reported as the cycle is at depth 2
```

This is not necessarily recommended, but available as a cost/benefit tradeoff mechanism
for reducing total project lint time, if needed.

## When Not To Use It

This rule is comparatively computationally expensive. If you are pressed for lint
time, or don't think you have an issue with dependency cycles, you may not want
this rule enabled.

## Further Reading

- [Original inspiring issue](https://github.com/benmosher/eslint-plugin-import/issues/941)
- Rule to detect that module imports itself: [`no-self-import`]

[`no-self-import`]: ./no-self-import.md
4 changes: 3 additions & 1 deletion docs/rules/order.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# import/order: Enforce a convention in module import order

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

```js
// 1. node "builtin" modules
Expand Down
4 changes: 4 additions & 0 deletions import.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
},
"eslint_d":
{
"disable": true,
"chdir": "${project}"
}
},
"paths": {
"osx": ["${project}/node_modules/.bin"]
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "2.9.0",
"version": "2.10.0",
"description": "Import with sanity.",
"engines": {
"node": ">=4"
Expand Down Expand Up @@ -84,7 +84,7 @@
"debug": "^2.6.8",
"doctrine": "1.5.0",
"eslint-import-resolver-node": "^0.3.1",
"eslint-module-utils": "^2.1.1",
"eslint-module-utils": "^2.2.0",
"has": "^1.0.1",
"lodash": "^4.17.4",
"minimatch": "^3.0.3",
Expand Down
6 changes: 6 additions & 0 deletions resolvers/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased


## 0.9.0 - 2018-03-29
### Breaking
- Fix with `pnpm` by bumping `resolve` ([#968])

## 0.8.4 - 2018-01-05
### Changed
- allow newer version of node-libs-browser ([#969])
Expand Down Expand Up @@ -93,6 +98,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]).

[#969]: https://github.com/benmosher/eslint-plugin-import/pull/969
[#968]: https://github.com/benmosher/eslint-plugin-import/pull/968
[#683]: https://github.com/benmosher/eslint-plugin-import/pull/683
[#572]: https://github.com/benmosher/eslint-plugin-import/pull/572
[#569]: https://github.com/benmosher/eslint-plugin-import/pull/569
Expand Down
7 changes: 4 additions & 3 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exports.resolve = function (source, file, settings) {

var configPath = get(settings, 'config')
, configIndex = get(settings, 'config-index')
, env = get(settings, 'env')
, packageDir

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

if (typeof webpackConfig === 'function') {
webpackConfig = webpackConfig()
webpackConfig = webpackConfig(env)
}

if (Array.isArray(webpackConfig)) {
Expand Down Expand Up @@ -122,8 +123,8 @@ function createResolveSync(configPath, webpackConfig) {
}

try {
var webpackFilename = resolve.sync('webpack', { basedir })
var webpackResolveOpts = { basedir: path.dirname(webpackFilename) }
var webpackFilename = resolve.sync('webpack', { basedir, preserveSymlinks: false })
var webpackResolveOpts = { basedir: path.dirname(webpackFilename), preserveSymlinks: false }

webpackRequire = function (id) {
return require(resolve.sync(id, webpackResolveOpts))
Expand Down
6 changes: 3 additions & 3 deletions resolvers/webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-import-resolver-webpack",
"version": "0.8.4",
"version": "0.9.0",
"description": "Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.",
"main": "index.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"bugs": {
"url": "https://github.com/benmosher/eslint-plugin-import/issues"
},
"homepage": "https://github.com/benmosher/eslint-plugin-import#readme",
"homepage": "https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/webpack",
"dependencies": {
"array-find": "^1.0.0",
"debug": "^2.6.8",
Expand All @@ -38,7 +38,7 @@
"is-absolute": "^0.2.3",
"lodash.get": "^4.4.2",
"node-libs-browser": "^1.0.0 || ^2.0.0",
"resolve": "^1.2.0",
"resolve": "^1.4.0",
"semver": "^5.3.0"
},
"peerDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions resolvers/webpack/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@ describe("config", function () {
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'))
})

it('finds the config at option env when config is a function', function() {
var settings = {
config: require(path.join(__dirname, './files/webpack.function.config.js')),
env: {
dummy: true,
},
}

expect(resolve('bar', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'))
})

})
Empty file.
3 changes: 2 additions & 1 deletion resolvers/webpack/test/files/webpack.function.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var path = require('path')
var pluginsTest = require('webpack-resolver-plugin-test')

module.exports = function() {
module.exports = function(env) {
return {
resolve: {
alias: {
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
'bar': env ? path.join(__dirname, 'some', 'goofy', 'path', 'bar.js') : undefined,
'some-alias': path.join(__dirname, 'some'),
},
modules: [
Expand Down
Loading

0 comments on commit f3ff68f

Please sign in to comment.