Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	src/index.js
  • Loading branch information
benmosher committed Sep 15, 2016
2 parents d5af34e + 2b471c7 commit ef1745a
Show file tree
Hide file tree
Showing 36 changed files with 764 additions and 29 deletions.
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased] v1
### Added
- New rule [`no-internal-modules`]: restrict deep package imports to specific folders. ([#485], thanks [@spalger]!)

## [1.15.0] - 2016-09-12
### Added
- Added an `allow` option to [`no-nodejs-modules`] to allow exceptions ([#452], [#509]).
- Added [`no-absolute-path`] rule ([#530], [#538])
- [`max-dependencies`] for specifying the maximum number of dependencies (both `import` and `require`) a module can have. (see [#489], thanks [@tizmagik])
- Added glob option to config for [`no-extraneous-dependencies`], after much bikeshedding. Thanks, [@knpwrs]! ([#527])

### Fixed
- [`no-named-as-default-member`] Allow default import to have a property named "default" ([#507], thanks [@jquense])
- [`no-named-as-default-member`] Allow default import to have a property named "default" ([#507]+[#508], thanks [@jquense] for both!)

## [1.14.0] - 2016-08-22
### Added
Expand Down Expand Up @@ -311,10 +318,18 @@ for info on changes for earlier releases.
[`no-mutable-exports`]: ./docs/rules/no-mutable-exports.md
[`prefer-default-export`]: ./docs/rules/prefer-default-export.md
[`no-restricted-paths`]: ./docs/rules/no-restricted-paths.md
[`no-absolute-path`]: ./docs/rules/no-absolute-path.md
[`max-dependencies`]: ./docs/rules/max-dependencies.md
[`no-internal-modules`]: ./docs/rules/no-internal-modules.md

[#538]: https://github.com/benmosher/eslint-plugin-import/pull/538
[#527]: https://github.com/benmosher/eslint-plugin-import/pull/527
[#509]: https://github.com/benmosher/eslint-plugin-import/pull/509
[#508]: https://github.com/benmosher/eslint-plugin-import/pull/508
[#503]: https://github.com/benmosher/eslint-plugin-import/pull/503
[#499]: https://github.com/benmosher/eslint-plugin-import/pull/499
[#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
[#444]: https://github.com/benmosher/eslint-plugin-import/pull/444
[#428]: https://github.com/benmosher/eslint-plugin-import/pull/428
Expand Down Expand Up @@ -351,6 +366,7 @@ for info on changes for earlier releases.
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314

[#530]: https://github.com/benmosher/eslint-plugin-import/issues/530
[#507]: https://github.com/benmosher/eslint-plugin-import/issues/507
[#478]: https://github.com/benmosher/eslint-plugin-import/issues/478
[#456]: https://github.com/benmosher/eslint-plugin-import/issues/456
Expand Down Expand Up @@ -390,7 +406,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/v1.14.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.15.0...HEAD
[1.15.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.14.0...v1.15.0
[1.14.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.13.0...v1.14.0
[1.13.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.12.0...v1.13.0
[1.12.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.1...v1.12.0
Expand Down Expand Up @@ -450,3 +467,6 @@ for info on changes for earlier releases.
[@zloirock]: https://github.com/zloirock
[@rhys-vdw]: https://github.com/rhys-vdw
[@wKich]: https://github.com/wKich
[@tizmagik]: https://github.com/tizmagik
[@knpwrs]: https://github.com/knpwrs
[@spalger]: https://github.com/spalger
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Ensure a default export is present, given a default import. ([`default`])
* Ensure imported namespaces contain dereferenced properties as they are dereferenced. ([`namespace`])
* Restrict which files can be imported in a given folder ([`no-restricted-paths`])
* Forbid import of modules using absolute paths ([`no-absolute-path`])

[`no-unresolved`]: ./docs/rules/no-unresolved.md
[`named`]: ./docs/rules/named.md
[`default`]: ./docs/rules/default.md
[`namespace`]: ./docs/rules/namespace.md
[`no-restricted-paths`]: ./docs/rules/no-restricted-paths.md
[`no-absolute-path`]: ./docs/rules/no-absolute-path.md

**Helpful warnings:**

Expand Down Expand Up @@ -55,6 +57,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-amd`]: ./docs/rules/no-amd.md
[`no-nodejs-modules`]: ./docs/rules/no-nodejs-modules.md


**Style guide:**

* Ensure all imports appear before other statements ([`first`])
Expand All @@ -64,6 +67,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Enforce a convention in module import order ([`order`])
* Enforce a newline after import statements ([`newline-after-import`])
* Prefer a default export if module exports a single name ([`prefer-default-export`])
* Limit the maximum number of dependencies a module can have. ([`max-dependencies`])

[`first`]: ./docs/rules/first.md
[`no-duplicates`]: ./docs/rules/no-duplicates.md
Expand All @@ -72,7 +76,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`order`]: ./docs/rules/order.md
[`newline-after-import`]: ./docs/rules/newline-after-import.md
[`prefer-default-export`]: ./docs/rules/prefer-default-export.md

[`max-dependencies`]: ./docs/rules/max-dependencies.md

## Installation

Expand Down
44 changes: 44 additions & 0 deletions docs/rules/max-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# max-dependencies

Forbid modules to have too many dependencies (`import` or `require` statements).

This is a useful rule because a module with too many dependencies is a code smell, and usually indicates the module is doing too much and/or should be broken up into smaller modules.

Importing multiple named exports from a single module will only count once (e.g. `import {x, y, z} from './foo'` will only count as a single dependency).

### Options

This rule takes the following option:

`max`: The maximum number of dependencies allowed. Anything over will trigger the rule. **Default is 10** if the rule is enabled and no `max` is specified.

You can set the option like this:

```js
"import/max-dependencies": ["error", {"max": 10}]
```


## Example

Given a max value of `{"max": 2}`:

### Fail

```js
import a from './a'; // 1
const b = require('./b'); // 2
import c from './c'; // 3 - exceeds max!
```

### Pass

```js
import a from './a'; // 1
const anotherA = require('./a'); // still 1
import {x, y, z} from './foo'; // 2
```

## When Not To Use It

If you don't care how many dependencies a module has.
27 changes: 27 additions & 0 deletions docs/rules/no-absolute-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Forbid import of modules using absolute paths

Node.js allows the import of modules using an absolute path such as `/home/xyz/file.js`. That is a bad practice as it ties the code using it to your computer, and therefore makes it unusable in packages distributed on `npm` for instance.

## Rule Details

### Fail

```js
import f from '/foo';
import f from '/some/path';

var f = require('/foo');
var f = require('/some/path');
```

### Pass

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

var _ = require('lodash');
var foo = require('foo');
var foo = require('./foo');
```
7 changes: 7 additions & 0 deletions docs/rules/no-extraneous-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ You can set the options like this:
"import/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false}]
```

You can also use an array of globs instead of literal booleans:

```js
"import/no-extraneous-dependencies": ["error", {"devDependencies": ['**/*.test.js', '**/*.spec.js']}]
```

When using an array of globs, the setting will be activated if the name of the file being linted matches a single glob in the array.

## Rule Details

Expand Down
64 changes: 64 additions & 0 deletions docs/rules/no-internal-modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# no-internal-modules

Use this rule to prevent importing the submodules of other modules.

## Rule Details

This rule has one option, `allow` which is an array of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns that whitelist paths and import statements that can be imported with reaching.

### Examples

Given the following folder structure:

```
my-project
├── actions
│ └── getUser.js
│ └── updateUser.js
├── reducer
│ └── index.js
│ └── user.js
├── redux
│ └── index.js
│ └── configureStore.js
└── app
│ └── index.js
│ └── settings.js
└── entry.js
```

And the .eslintrc file:
```
{
...
"rules": {
"import/no-internal-modules": [ "error", {
"allow": [ "**/actions/*", "source-map-support/*" ]
} ]
}
}
```

The following patterns are considered problems:

```js
/**
* in my-project/entry.js
*/

import { settings } from './app/index'; // Reaching to "./app/index" is not allowed
import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed
import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed
```

The following patterns are NOT considered problems:

```js
/**
* in my-project/entry.js
*/

import 'source-map-support/register';
import { settings } from '../app';
import getUser from '../actions/getUser';
```
8 changes: 5 additions & 3 deletions docs/rules/no-named-as-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import foo from './foo.js';
import bar from './foo.js';
```

For [ES7], this also prevents exporting the default from a referenced module as a name within than module, for the same reasons:
For post-ES2015 `export` extensions, this also prevents exporting the default from a referenced module as a name within than module, for the same reasons:

```js
// valid:
Expand All @@ -39,6 +39,8 @@ export bar from './foo.js';

## Further Reading

- Lee Byron's [ES7] export proposal
- ECMAScript Proposal: [export ns from]
- ECMAScript Proposal: [export default from]

[ES7]: https://github.com/leebyron/ecmascript-more-export-from
[export ns from]: https://github.com/leebyron/ecmascript-export-ns-from
[export default from]: https://github.com/leebyron/ecmascript-export-default-from
8 changes: 4 additions & 4 deletions docs/rules/prefer-default-export.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# prefer-default-export

When there is only a single export from a module prefer using default export over named export.
When there is only a single export from a module, prefer using default export over named export.

## Rule Details

Expand All @@ -9,7 +9,7 @@ The following patterns are considered warnings:
```javascript
// bad.js

// There is only a single module export and its a named export.
// There is only a single module export and it's a named export.
export const foo = 'foo';

```
Expand All @@ -28,15 +28,15 @@ export default 'bar';
```javascript
// good2.js

// There is more thank one named exports in the module.
// There is more than one named export in the module.
export const foo = 'foo';
export const bar = 'bar';
```

```javascript
// good3.js

// There is more thank one named exports in the module
// There is more than one named export in the module
const foo = 'foo';
const bar = 'bar';
export { foo, bar }
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "1.14.0",
"version": "1.15.0",
"description": "Import with sanity.",
"engines": {
"node": ">=4"
Expand Down Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"babel-eslint": "next",
"babel-preset-es2015-argon": "latest",
"babel-plugin-istanbul": "^1.0.3",
"babel-plugin-istanbul": "^2.0.1",
"babel-register": "6.9.0",
"chai": "^3.4.0",
"coveralls": "^2.11.4",
Expand All @@ -69,7 +69,7 @@
"redux": "^3.0.4",
"rimraf": "2.5.2",
"typescript": "^1.8.10",
"typescript-eslint-parser": "^0.1.1"
"typescript-eslint-parser": "^0.3.0"
},
"peerDependencies": {
"eslint": "2.x - 3.x"
Expand All @@ -78,14 +78,15 @@
"builtin-modules": "^1.1.1",
"contains-path": "^0.1.0",
"debug": "^2.2.0",
"doctrine": "1.3.0",
"doctrine": "1.3.x",
"es6-map": "^0.1.3",
"es6-set": "^0.1.4",
"eslint-import-resolver-node": "^0.2.0",
"lodash.cond": "^4.3.0",
"lodash.endswith": "^4.0.1",
"lodash.find": "^4.3.0",
"lodash.findindex": "^4.3.0",
"minimatch": "^3.0.3",
"pkg-up": "^1.0.0"
},
"nyc": {
Expand Down
2 changes: 0 additions & 2 deletions resolvers/webpack/.npmignore

This file was deleted.

7 changes: 7 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.6.0 - 2016-09-13
### Added
- support for config-as-function ([#533], thanks [@grahamb])

## 0.5.1 - 2016-08-11
### Fixed
- don't throw and die if no webpack config is found
Expand Down Expand Up @@ -58,6 +63,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- `interpret` configs (such as `.babel.js`).
Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]).

[#533]: https://github.com/benmosher/eslint-plugin-import/pull/533
[#413]: https://github.com/benmosher/eslint-plugin-import/pull/413
[#377]: https://github.com/benmosher/eslint-plugin-import/pull/377
[#363]: https://github.com/benmosher/eslint-plugin-import/pull/363
Expand All @@ -82,3 +88,4 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[@Satyam]: https://github.com/Satyam
[@Rogeres]: https://github.com/Rogeres
[@Kovensky]: https://github.com/Kovensky
[@grahamb]: https://github.com/grahamb
Loading

0 comments on commit ef1745a

Please sign in to comment.