Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Mar 28, 2018
2 parents 066d2d3 + 1eac942 commit 41c4540
Show file tree
Hide file tree
Showing 125 changed files with 1,949 additions and 186 deletions.
43 changes: 26 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
language: node_js
node_js:
- 4
- 6
- 8
- '8'
- '6'
- '4'

os: linux

env:
- ESLINT_VERSION=2
- ESLINT_VERSION=3
- ESLINT_VERSION=4
- ESLINT_VERSION=3
- ESLINT_VERSION=2

# osx backlog is often deep, so to be polite we can just hit these highlights
matrix:
include:
- os: osx
env: ESLINT_VERSION=2
- env: PACKAGE=resolvers/node
node_js: 8
- env: PACKAGE=resolvers/node
node_js: 6
- env: PACKAGE=resolvers/node
node_js: 4
- os: osx
env: ESLINT_VERSION=3
- env: PACKAGE=resolvers/webpack
node_js: 8
- env: PACKAGE=resolvers/webpack
node_js: 6
- env: PACKAGE=resolvers/webpack
node_js: 4
- os: osx
env: ESLINT_VERSION=4
node_js: 8
- os: osx
env: ESLINT_VERSION=3
node_js: 6
- os: osx
env: ESLINT_VERSION=2
node_js: 4

before_install:
- 'nvm install-latest-npm'
- 'if [ -n "${PACKAGE-}" ]; then cd "${PACKAGE}"; fi'
install:
- if [ ${TRAVIS_NODE_VERSION} == "4" ]; then
npm install -g npm@3;
fi
- npm install
- npm install eslint@$ESLINT_VERSION --ignore-scripts || true
# install all resolver deps
- "for resolver in ./resolvers/*; do cd $resolver && npm install && cd ../..; done"
- npm install --no-save eslint@$ESLINT_VERSION --ignore-scripts || true

script:
- "npm test"
- "for resolver in ./resolvers/*; do cd $resolver && npm test && cd ../..; done"
- 'npm test'

after_success:
- npm run coveralls
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## [Unreleased]
- Autofixer for [`order`] rule ([#711], thanks [@tihonove])

## [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
### Added
Expand Down Expand Up @@ -432,17 +439,24 @@ for info on changes for earlier releases.
[`unambiguous`]: ./docs/rules/unambiguous.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
[`exports-last`]: ./docs/rules/exports-last.md
[`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

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

[#944]: https://github.com/benmosher/eslint-plugin-import/pull/944
[#891]: https://github.com/benmosher/eslint-plugin-import/pull/891
[#889]: https://github.com/benmosher/eslint-plugin-import/pull/889
[#858]: https://github.com/benmosher/eslint-plugin-import/pull/858
[#843]: https://github.com/benmosher/eslint-plugin-import/pull/843
[#871]: https://github.com/benmosher/eslint-plugin-import/pull/871
[#744]: https://github.com/benmosher/eslint-plugin-import/pull/744
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
[#737]: https://github.com/benmosher/eslint-plugin-import/pull/737
[#727]: https://github.com/benmosher/eslint-plugin-import/pull/727
[#721]: https://github.com/benmosher/eslint-plugin-import/pull/721
[#712]: https://github.com/benmosher/eslint-plugin-import/pull/712
[#696]: https://github.com/benmosher/eslint-plugin-import/pull/696
[#685]: https://github.com/benmosher/eslint-plugin-import/pull/685
Expand All @@ -466,6 +480,7 @@ for info on changes for earlier releases.
[#489]: https://github.com/benmosher/eslint-plugin-import/pull/489
[#485]: https://github.com/benmosher/eslint-plugin-import/pull/485
[#461]: https://github.com/benmosher/eslint-plugin-import/pull/461
[#449]: https://github.com/benmosher/eslint-plugin-import/pull/449
[#444]: https://github.com/benmosher/eslint-plugin-import/pull/444
[#428]: https://github.com/benmosher/eslint-plugin-import/pull/428
[#395]: https://github.com/benmosher/eslint-plugin-import/pull/395
Expand Down Expand Up @@ -500,13 +515,13 @@ 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
[#842]: https://github.com/benmosher/eslint-plugin-import/issues/842
[#839]: https://github.com/benmosher/eslint-plugin-import/issues/839
[#720]: https://github.com/benmosher/eslint-plugin-import/issues/720
[#711]: https://github.com/benmosher/eslint-plugin-import/issues/711
[#686]: https://github.com/benmosher/eslint-plugin-import/issues/686
[#671]: https://github.com/benmosher/eslint-plugin-import/issues/671
[#660]: https://github.com/benmosher/eslint-plugin-import/issues/660
Expand All @@ -532,6 +547,7 @@ for info on changes for earlier releases.
[#456]: https://github.com/benmosher/eslint-plugin-import/issues/456
[#453]: https://github.com/benmosher/eslint-plugin-import/issues/453
[#452]: https://github.com/benmosher/eslint-plugin-import/issues/452
[#447]: https://github.com/benmosher/eslint-plugin-import/issues/447
[#441]: https://github.com/benmosher/eslint-plugin-import/issues/441
[#423]: https://github.com/benmosher/eslint-plugin-import/issues/423
[#416]: https://github.com/benmosher/eslint-plugin-import/issues/416
Expand Down Expand Up @@ -567,7 +583,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.8.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...HEAD
[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
[2.6.1]: https://github.com/benmosher/eslint-plugin-import/compare/v2.6.0...v2.6.1
Expand Down Expand Up @@ -664,3 +681,7 @@ for info on changes for earlier releases.
[@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
27 changes: 23 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 @@ -23,6 +23,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Forbid `require()` calls with expressions ([`no-dynamic-require`])
* 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`])

[`no-unresolved`]: ./docs/rules/no-unresolved.md
[`named`]: ./docs/rules/named.md
Expand All @@ -33,8 +34,9 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-dynamic-require`]: ./docs/rules/no-dynamic-require.md
[`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

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


* Report any invalid exports, i.e. re-export of the same name ([`export`])
Expand All @@ -51,7 +53,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 @@ -64,7 +66,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 All @@ -77,7 +79,9 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Limit the maximum number of dependencies a module can have ([`max-dependencies`])
* Forbid unassigned imports ([`no-unassigned-import`])
* Forbid named default exports ([`no-named-default`])
* Forbid default exports ([`no-default-export`])
* Forbid anonymous values as default exports ([`no-anonymous-default-export`])
* Prefer named exports to be grouped together in a single export declaration ([`group-exports`])

[`first`]: ./docs/rules/first.md
[`exports-last`]: ./docs/rules/exports-last.md
Expand All @@ -91,6 +95,8 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md
[`no-named-default`]: ./docs/rules/no-named-default.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
[`group-exports`]: ./docs/rules/group-exports.md
[`no-default-export`]: ./docs/rules/no-default-export.md

## Installation

Expand Down Expand Up @@ -224,6 +230,19 @@ A list of file extensions that will be parsed as modules and inspected for
This defaults to `['.js']`, unless you are using the `react` shared config,
in which case it is specified as `['.js', '.jsx']`.

```js
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx"
]
}
}
}
```

Note that this is different from (and likely a subset of) any `import/resolver`
extensions settings, which may include `.json`, `.coffee`, etc. which will still
factor into the `no-unresolved` rule.
Expand Down
2 changes: 2 additions & 0 deletions config/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @type {Object}
*/
module.exports = {
plugins: ['import'],

rules: {
// analysis/correctness
'import/no-unresolved': 'error',
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/default.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# default
# import/default

If a default import is requested, this rule will report if there is no default
export in the imported module.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/export.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# export
# import/export

Reports funny business with exports, like repeated exports of names or defaults.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/exports-last.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# exports-last
# import/exports-last

This rule enforces that all exports are declared at the bottom of the file. This rule will report any export declarations that comes before any non-export statements.

Expand Down
75 changes: 67 additions & 8 deletions docs/rules/extensions.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
# extensions - Ensure consistent use of file extension within the import path
# import/extensions - Ensure consistent use of file extension within the import path

Some file resolve algorithms allow you to omit the file extension within the import source path. For example the `node` resolver can resolve `./foo/bar` to the absolute path `/User/someone/foo/bar.js` because the `.js` extension is resolved automatically by default. Depending on the resolver you can configure more extensions to get resolved automatically.

In order to provide a consistent use of file extensions across your code base, this rule can enforce or disallow the use of certain file extensions.

## Rule Details

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.
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 @@ -41,7 +65,7 @@ import foo from './foo.js';

import bar from './bar.json';

import Component from './Component.jsx'
import Component from './Component.jsx';

import express from 'express/index.js';
```
Expand All @@ -53,7 +77,7 @@ import foo from './foo';

import bar from './bar';

import Component from './Component'
import Component from './Component';

import express from 'express/index';

Expand All @@ -67,7 +91,7 @@ import foo from './foo';

import bar from './bar';

import Component from './Component'
import Component from './Component';

import express from 'express';
```
Expand All @@ -79,13 +103,48 @@ import foo from './foo.js';

import bar from './bar.json';

import Component from './Component.jsx'
import Component from './Component.jsx';

import express from 'express/index.js';

import * as path from 'path';
```

The following patterns are considered problems when configuration set to "ignorePackages":

```js
import foo from './foo';

import bar from './bar';

import Component from './Component';

```

The following patterns are not considered problems when configuration set to "ignorePackages":

```js
import foo from './foo.js';

import bar from './bar.json';

import Component from './Component.jsx';

import express from 'express';

```

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

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

import baz from 'foo/baz.js';

import express from 'express';

```

## When Not To Use It

If you are not concerned about a consistent usage of file extension.
2 changes: 1 addition & 1 deletion docs/rules/first.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# first
# import/first

This rule reports any imports that come after non-import
statements.
Expand Down
Loading

0 comments on commit 41c4540

Please sign in to comment.