Skip to content

Commit 3d00542

Browse files
author
spalger
committed
Merge branch 'master' of github.com:benmosher/eslint-plugin-import into implement/rule/no-reaching-in
2 parents 0509d70 + bd99bdf commit 3d00542

36 files changed

+651
-43
lines changed

Diff for: CHANGELOG.md

+38-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## [Unreleased]
7+
### Added
8+
- Added an `allow` option to [`no-nodejs-modules`] to allow exceptions ([#452], [#509]).
9+
- Added [`no-absolute-path`] rule ([#530], [#538])
10+
- [`max-dependencies`] for specifying the maximum number of dependencies (both `import` and `require`) a module can have. (see [#489], thanks [@tizmagik])
11+
- Added glob option to config for [`no-extraneous-dependencies`], after much bikeshedding. Thanks, [@knpwrs]! ([#527])
12+
13+
### Fixed
14+
- [`no-named-as-default-member`] Allow default import to have a property named "default" ([#507]+[#508], thanks [@jquense] for both!)
15+
16+
## [1.14.0] - 2016-08-22
17+
### Added
18+
- [`import/parsers` setting]: parse some dependencies (i.e. TypeScript!) with a different parser than the ESLint-configured parser. ([#503])
19+
20+
### Fixed
21+
- [`namespace`] exception for get property from `namespace` import, which are re-export from commonjs module ([#499] fixes [#416], thanks [@wKich])
722

823
## [1.13.0] - 2016-08-11
924
### Added
@@ -258,6 +273,7 @@ for info on changes for earlier releases.
258273
[`import/cache` setting]: ./README.md#importcache
259274
[`import/ignore` setting]: ./README.md#importignore
260275
[`import/extensions` setting]: ./README.md#importextensions
276+
[`import/parsers` setting]: ./README.md#importparsers
261277
[`import/core-modules` setting]: ./README.md#importcore-modules
262278
[`import/external-module-folders` setting]: ./README.md#importexternal-module-folders
263279

@@ -280,7 +296,19 @@ for info on changes for earlier releases.
280296
[`no-mutable-exports`]: ./docs/rules/no-mutable-exports.md
281297
[`prefer-default-export`]: ./docs/rules/prefer-default-export.md
282298
[`no-restricted-paths`]: ./docs/rules/no-restricted-paths.md
283-
299+
<<<<<<< HEAD
300+
[`no-absolute-path`]: ./docs/rules/no-absolute-path.md
301+
=======
302+
[`max-dependencies`]: ./docs/rules/max-dependencies.md
303+
>>>>>>> tizmagik/feature/max-dependencies
304+
305+
[#538]: https://github.com/benmosher/eslint-plugin-import/pull/538
306+
[#527]: https://github.com/benmosher/eslint-plugin-import/pull/527
307+
[#509]: https://github.com/benmosher/eslint-plugin-import/pull/509
308+
[#508]: https://github.com/benmosher/eslint-plugin-import/pull/508
309+
[#503]: https://github.com/benmosher/eslint-plugin-import/pull/503
310+
[#499]: https://github.com/benmosher/eslint-plugin-import/pull/499
311+
[#489]: https://github.com/benmosher/eslint-plugin-import/pull/489
284312
[#461]: https://github.com/benmosher/eslint-plugin-import/pull/461
285313
[#444]: https://github.com/benmosher/eslint-plugin-import/pull/444
286314
[#428]: https://github.com/benmosher/eslint-plugin-import/pull/428
@@ -317,11 +345,15 @@ for info on changes for earlier releases.
317345
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
318346
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314
319347

348+
[#530]: https://github.com/benmosher/eslint-plugin-import/issues/530
349+
[#507]: https://github.com/benmosher/eslint-plugin-import/issues/507
320350
[#478]: https://github.com/benmosher/eslint-plugin-import/issues/478
321351
[#456]: https://github.com/benmosher/eslint-plugin-import/issues/456
322352
[#453]: https://github.com/benmosher/eslint-plugin-import/issues/453
353+
[#452]: https://github.com/benmosher/eslint-plugin-import/issues/452
323354
[#441]: https://github.com/benmosher/eslint-plugin-import/issues/441
324355
[#423]: https://github.com/benmosher/eslint-plugin-import/issues/423
356+
[#416]: https://github.com/benmosher/eslint-plugin-import/issues/416
325357
[#415]: https://github.com/benmosher/eslint-plugin-import/issues/415
326358
[#386]: https://github.com/benmosher/eslint-plugin-import/issues/386
327359
[#373]: https://github.com/benmosher/eslint-plugin-import/issues/373
@@ -350,7 +382,8 @@ for info on changes for earlier releases.
350382
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
351383
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89
352384

353-
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.13.0...HEAD
385+
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.14.0...HEAD
386+
[1.14.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.13.0...v1.14.0
354387
[1.13.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.12.0...v1.13.0
355388
[1.12.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.1...v1.12.0
356389
[1.11.1]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.0...v1.11.1
@@ -408,3 +441,6 @@ for info on changes for earlier releases.
408441
[@rhettlivingston]: https://github.com/rhettlivingston
409442
[@zloirock]: https://github.com/zloirock
410443
[@rhys-vdw]: https://github.com/rhys-vdw
444+
[@wKich]: https://github.com/wKich
445+
[@tizmagik]: https://github.com/tizmagik
446+
[@knpwrs]: https://github.com/knpwrs

Diff for: README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
1919
* Ensure a default export is present, given a default import. ([`default`])
2020
* Ensure imported namespaces contain dereferenced properties as they are dereferenced. ([`namespace`])
2121
* Restrict which files can be imported in a given folder ([`no-restricted-paths`])
22+
* Forbid import of modules using absolute paths ([`no-absolute-path`])
2223

2324
[`no-unresolved`]: ./docs/rules/no-unresolved.md
2425
[`named`]: ./docs/rules/named.md
2526
[`default`]: ./docs/rules/default.md
2627
[`namespace`]: ./docs/rules/namespace.md
2728
[`no-restricted-paths`]: ./docs/rules/no-restricted-paths.md
29+
[`no-absolute-path`]: ./docs/rules/no-absolute-path.md
2830

2931
**Helpful warnings:**
3032

@@ -52,6 +54,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
5254
[`no-amd`]: ./docs/rules/no-amd.md
5355
[`no-nodejs-modules`]: ./docs/rules/no-nodejs-modules.md
5456

57+
5558
**Style guide:**
5659

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

6569
[`imports-first`]: ./docs/rules/imports-first.md
6670
[`no-duplicates`]: ./docs/rules/no-duplicates.md
@@ -69,7 +73,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
6973
[`order`]: ./docs/rules/order.md
7074
[`newline-after-import`]: ./docs/rules/newline-after-import.md
7175
[`prefer-default-export`]: ./docs/rules/prefer-default-export.md
72-
76+
[`max-dependencies`]: ./docs/rules/max-dependencies.md
7377

7478
## Installation
7579

@@ -265,6 +269,32 @@ Contribution of more such shared configs for other platforms are welcome!
265269

266270
An array of folders. Resolved modules only from those folders will be considered as "external". By default - `["node_modules"]`. Makes sense if you have configured your path or webpack to handle your internal paths differently and want to considered modules from some folders, for example `bower_components` or `jspm_modules`, as "external".
267271

272+
#### `import/parsers`
273+
274+
A map from parsers to file extension arrays. If a file extension is matched, the
275+
dependency parser will require and use the map key as the parser instead of the
276+
configured ESLint parser. This is useful if you're inter-op-ing with TypeScript
277+
directly using Webpack, for example:
278+
279+
```yaml
280+
# .eslintrc.yml
281+
settings:
282+
import/parsers:
283+
typescript-eslint-parser: [ .ts, .tsx ]
284+
```
285+
286+
In this case, [`typescript-eslint-parser`](https://github.com/eslint/typescript-eslint-parser) must be installed and require-able from
287+
the running `eslint` module's location (i.e., install it as a peer of ESLint).
288+
289+
This is currently only tested with `typescript-eslint-parser` but should theoretically
290+
work with any moderately ESTree-compliant parser.
291+
292+
It's difficult to say how well various plugin features will be supported, too,
293+
depending on how far down the rabbit hole goes. Submit an issue if you find strange
294+
behavior beyond here, but steel your heart against the likely outcome of closing
295+
with `wontfix`.
296+
297+
268298
#### `import/resolver`
269299

270300
See [resolvers](#resolvers).

Diff for: docs/rules/max-dependencies.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# max-dependencies
2+
3+
Forbid modules to have too many dependencies (`import` or `require` statements).
4+
5+
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.
6+
7+
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).
8+
9+
### Options
10+
11+
This rule takes the following option:
12+
13+
`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.
14+
15+
You can set the option like this:
16+
17+
```js
18+
"import/max-dependencies": ["error", {"max": 10}]
19+
```
20+
21+
22+
## Example
23+
24+
Given a max value of `{"max": 2}`:
25+
26+
### Fail
27+
28+
```js
29+
import a from './a'; // 1
30+
const b = require('./b'); // 2
31+
import c from './c'; // 3 - exceeds max!
32+
```
33+
34+
### Pass
35+
36+
```js
37+
import a from './a'; // 1
38+
const anotherA = require('./a'); // still 1
39+
import {x, y, z} from './foo'; // 2
40+
```
41+
42+
## When Not To Use It
43+
44+
If you don't care how many dependencies a module has.

Diff for: docs/rules/no-absolute-path.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Forbid import of modules using absolute paths
2+
3+
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.
4+
5+
## Rule Details
6+
7+
### Fail
8+
9+
```js
10+
import f from '/foo';
11+
import f from '/some/path';
12+
13+
var f = require('/foo');
14+
var f = require('/some/path');
15+
```
16+
17+
### Pass
18+
19+
```js
20+
import _ from 'lodash';
21+
import foo from 'foo';
22+
import foo from './foo';
23+
24+
var _ = require('lodash');
25+
var foo = require('foo');
26+
var foo = require('./foo');
27+
```

Diff for: docs/rules/no-extraneous-dependencies.md

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ You can set the options like this:
1919
"import/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false}]
2020
```
2121

22+
You can also use an array of globs instead of literal booleans:
23+
24+
```js
25+
"import/no-extraneous-dependencies": ["error", {"devDependencies": ['*.test.js', '*.spec.js']}]
26+
```
27+
28+
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.
2229

2330
## Rule Details
2431

Diff for: docs/rules/no-nodejs-modules.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Forbid the use of Node.js builtin modules. Can be useful for client-side web projects that do not have access to those modules.
44

5+
### Options
6+
7+
This rule supports the following options:
8+
9+
- `allow`: Array of names of allowed modules. Defaults to an empty array.
10+
511
## Rule Details
612

713
### Fail
@@ -24,6 +30,9 @@ import foo from './foo';
2430
var _ = require('lodash');
2531
var foo = require('foo');
2632
var foo = require('./foo');
33+
34+
/* eslint import/no-nodejs-modules: ["error", {"allow": ["path"]}] */
35+
import path from 'path';
2736
```
2837

2938
## When Not To Use It

Diff for: docs/rules/prefer-default-export.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# prefer-default-export
22

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

55
## Rule Details
66

@@ -9,7 +9,7 @@ The following patterns are considered warnings:
99
```javascript
1010
// bad.js
1111

12-
// There is only a single module export and its a named export.
12+
// There is only a single module export and it's a named export.
1313
export const foo = 'foo';
1414

1515
```
@@ -28,15 +28,15 @@ export default 'bar';
2828
```javascript
2929
// good2.js
3030

31-
// There is more thank one named exports in the module.
31+
// There is more than one named export in the module.
3232
export const foo = 'foo';
3333
export const bar = 'bar';
3434
```
3535

3636
```javascript
3737
// good3.js
3838

39-
// There is more thank one named exports in the module
39+
// There is more than one named export in the module
4040
const foo = 'foo';
4141
const bar = 'bar';
4242
export { foo, bar }

Diff for: package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-import",
3-
"version": "1.13.0",
3+
"version": "1.14.0",
44
"description": "Import with sanity.",
55
"main": "lib/index.js",
66
"directories": {
@@ -45,24 +45,26 @@
4545
"homepage": "https://github.com/benmosher/eslint-plugin-import",
4646
"devDependencies": {
4747
"babel-eslint": "next",
48-
"babel-plugin-istanbul": "^1.0.3",
48+
"babel-plugin-istanbul": "^2.0.1",
4949
"babel-preset-es2015": "^6.6.0",
5050
"babel-preset-es2015-loose": "^7.0.0",
5151
"babel-register": "6.9.0",
5252
"chai": "^3.4.0",
5353
"coveralls": "^2.11.4",
5454
"cross-env": "^2.0.0",
5555
"eslint": "2.x",
56-
"eslint-plugin-import": "next",
5756
"eslint-import-resolver-node": "file:./resolvers/node",
5857
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
58+
"eslint-plugin-import": "next",
5959
"gulp": "^3.9.0",
6060
"gulp-babel": "6.1.2",
6161
"istanbul": "^0.4.0",
6262
"mocha": "^2.2.1",
6363
"nyc": "^7.0.0",
6464
"redux": "^3.0.4",
65-
"rimraf": "2.5.2"
65+
"rimraf": "2.5.2",
66+
"typescript": "^1.8.10",
67+
"typescript-eslint-parser": "^0.2.0"
6668
},
6769
"peerDependencies": {
6870
"eslint": "2.x - 3.x"
@@ -71,7 +73,7 @@
7173
"builtin-modules": "^1.1.1",
7274
"contains-path": "^0.1.0",
7375
"debug": "^2.2.0",
74-
"doctrine": "1.2.x",
76+
"doctrine": "1.3.x",
7577
"es6-map": "^0.1.3",
7678
"es6-set": "^0.1.4",
7779
"eslint-import-resolver-node": "^0.2.0",

Diff for: resolvers/node/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this resolver will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

6+
## v0.2.3 - 2016-08-20
7+
### Added
8+
- debug logging (use `DEBUG=eslint-plugin-import:resolver:node eslint [...]`)
9+
610
## v0.2.2 - 2016-07-14
711
### Fixed
812
- Node resolver no longer declares the import plugin as a `peerDependency`. See [#437]

Diff for: resolvers/node/index.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ var resolve = require('resolve')
22
, path = require('path')
33
, assign = require('object-assign')
44

5+
var log = require('debug')('eslint-plugin-import:resolver:node')
6+
57
exports.interfaceVersion = 2
68

79
exports.resolve = function (source, file, config) {
8-
if (resolve.isCore(source)) return { found: true, path: null }
10+
log('Resolving:', source, 'from:', file)
11+
var resolvedPath
12+
13+
if (resolve.isCore(source)) {
14+
log('resolved to core')
15+
return { found: true, path: null }
16+
}
17+
918
try {
10-
return { found: true, path: resolve.sync(source, opts(file, config)) }
19+
resolvedPath = resolve.sync(source, opts(file, config))
20+
log('Resolved to:', resolvedPath)
21+
return { found: true, path: resolvedPath }
1122
} catch (err) {
23+
log('resolve threw error:', err)
1224
return { found: false }
1325
}
1426
}

0 commit comments

Comments
 (0)