Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: import-js/eslint-plugin-import
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.15.0
Choose a base ref
...
head repository: import-js/eslint-plugin-import
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.16.0
Choose a head ref

Commits on Aug 29, 2016

  1. Support webpack configs that export a function

    Webpack 2 supports webpack configuration files that export a function (see https://webpack.github.io/docs/roadmap.html). This commit adds support for this by testing if the `require`ed config is a function, and if so, executing it.
    grahamb committed Aug 29, 2016
    Copy the full SHA
    896f984 View commit details

Commits on Sep 12, 2016

  1. Copy the full SHA
    daf38ac View commit details

Commits on Sep 13, 2016

  1. Merge tag 'v1.15.0' into release

    Tag v1.15.0
    benmosher committed Sep 13, 2016
    Copy the full SHA
    2e4e449 View commit details
  2. Copy the full SHA
    320d5d7 View commit details
  3. resolvers/webpack/v0.6.0

    benmosher committed Sep 13, 2016
    Copy the full SHA
    d7ac357 View commit details
  4. Copy the full SHA
    ee49b74 View commit details

Commits on Sep 14, 2016

  1. Copy the full SHA
    01f1852 View commit details
  2. Copy the full SHA
    c07c057 View commit details
  3. Update obsoleted reference

    preco21 authored Sep 14, 2016
    Copy the full SHA
    49cf441 View commit details

Commits on Sep 15, 2016

  1. Copy the full SHA
    935f8a9 View commit details
  2. Merge pull request #561 from preco21/patch-1

    docs: Update obsoleted reference
    benmosher authored Sep 15, 2016
    Copy the full SHA
    32b5494 View commit details
  3. Implement new rule: no-internal-modules (#485)

    * Implement new rule: no-reaching-inside
    
    * normalize path segments all path segments to '/'
    
    * point to minimatch/glob docs to define glob syntax
    
    * refactor no-reaching-inside, allow now points to importable modules/files
    
    * add test to verify that "no-reaching/allow" can limit the depth of matches
    
    * code style improvements
    
    * rename to no-internal-modules
    
    * remove extra test executor
    spalger authored and benmosher committed Sep 15, 2016
    Copy the full SHA
    c57beae View commit details
  4. changelog note for #485

    benmosher committed Sep 15, 2016
    Copy the full SHA
    2b471c7 View commit details
  5. Copy the full SHA
    e087ec4 View commit details

Commits on Sep 16, 2016

  1. Copy the full SHA
    f507ff3 View commit details
  2. Copy the full SHA
    515d159 View commit details

Commits on Sep 17, 2016

  1. Fix #564: Fix tests not running due to Espree bump (#565)

    * Fix #564: Fix tests not running due to Espree bump
    
    * updated malformed test
    
    also, the most trivial of line formatting changes
    jfmengels authored and benmosher committed Sep 17, 2016
    Copy the full SHA
    12bf6da View commit details

Commits on Sep 20, 2016

  1. Copy the full SHA
    c45fdc3 View commit details
  2. Copy the full SHA
    b6ac532 View commit details
  3. Copy the full SHA
    24c04b7 View commit details
  4. changelog note for #545

    benmosher committed Sep 20, 2016
    Copy the full SHA
    0f527d2 View commit details

Commits on Sep 22, 2016

  1. Copy the full SHA
    2524c09 View commit details
  2. bump to v1.16.0

    benmosher committed Sep 22, 2016
    Copy the full SHA
    2946d4b View commit details
  3. Changlog fixes

    jfmengels committed Sep 22, 2016
    Copy the full SHA
    af062f1 View commit details
Showing with 616 additions and 40 deletions.
  1. +25 −2 CHANGELOG.md
  2. +2 −0 README.md
  3. +3 −1 docs/rules/extensions.md
  4. +24 −0 docs/rules/no-dynamic-require.md
  5. +1 −1 docs/rules/no-extraneous-dependencies.md
  6. +64 −0 docs/rules/no-internal-modules.md
  7. +5 −3 docs/rules/no-named-as-default.md
  8. +4 −3 package.json
  9. +0 −1 resolvers/node/.npmignore
  10. +6 −0 resolvers/node/CHANGELOG.md
  11. +1 −0 resolvers/node/package.json
  12. +0 −2 resolvers/webpack/.npmignore
  13. +7 −0 resolvers/webpack/CHANGELOG.md
  14. +6 −1 resolvers/webpack/index.js
  15. +5 −1 resolvers/webpack/package.json
  16. +36 −0 resolvers/webpack/test/files/webpack.function.config.js
  17. +9 −0 resolvers/webpack/test/root.js
  18. +2 −0 src/index.js
  19. +1 −1 src/rules/default.js
  20. +44 −22 src/rules/extensions.js
  21. +25 −0 src/rules/no-dynamic-require.js
  22. +92 −0 src/rules/no-internal-modules.js
  23. +3 −0 src/rules/no-named-as-default.js
  24. +1 −0 tests/files/default-export-from-ignored.js
  25. +1 −0 tests/files/default-export-from-named.js
  26. +1 −0 tests/files/default-export-from.js
  27. 0 tests/files/internal-modules/api/service/index.js
  28. 0 tests/files/internal-modules/plugins/plugin.js
  29. 0 tests/files/internal-modules/plugins/plugin2/app/index.js
  30. 0 tests/files/internal-modules/plugins/plugin2/index.js
  31. 0 tests/files/internal-modules/plugins/plugin2/internal.js
  32. +1 −0 tests/files/node_modules/jquery/dist/jquery.js
  33. +1 −0 tests/files/package.json
  34. +21 −0 tests/src/rules/default.js
  35. +4 −2 tests/src/rules/export.js
  36. +53 −0 tests/src/rules/extensions.js
  37. +49 −0 tests/src/rules/no-dynamic-require.js
  38. +115 −0 tests/src/rules/no-internal-modules.js
  39. +4 −0 tests/src/rules/no-named-as-default.js
27 changes: 25 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,16 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## [Unreleased]


## [1.16.0] - 2016-09-22
### Added
- Added [`no-dynamic-require`] rule: forbid `require()` calls with expressions. ([#567], [#568])
- Added [`no-internal-modules`] rule: restrict deep package imports to specific folders. ([#485], thanks [@spalger]!)
- [`extensions`]: allow override of a chosen default with options object ([#555], thanks [@ljharb]!)

### Fixed
- [`no-named-as-default`] no longer false-positives on `export default from '...'` ([#566], thanks [@preco21])
- [`default`]: allow re-export of values from ignored files as default ([#545], thanks [@skyrpex])

## [1.15.0] - 2016-09-12
### Added
- Added an `allow` option to [`no-nodejs-modules`] to allow exceptions ([#452], [#509]).
@@ -14,7 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- 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]+[#508], thanks [@jquense] for both!)
- [`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
@@ -286,6 +296,7 @@ for info on changes for earlier releases.
[`no-amd`]: ./docs/rules/no-amd.md
[`namespace`]: ./docs/rules/namespace.md
[`no-namespace`]: ./docs/rules/no-namespace.md
[`no-named-as-default`]: ./docs/rules/no-named-as-default.md
[`no-named-as-default-member`]: ./docs/rules/no-named-as-default-member.md
[`no-extraneous-dependencies`]: ./docs/rules/no-extraneous-dependencies.md
[`extensions`]: ./docs/rules/extensions.md
@@ -301,14 +312,19 @@ for info on changes for earlier releases.
[`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
[`no-dynamic-require`]: ./docs/rules/no-dynamic-require.md

[#568]: https://github.com/benmosher/eslint-plugin-import/pull/568
[#555]: https://github.com/benmosher/eslint-plugin-import/pull/555
[#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
@@ -345,6 +361,9 @@ 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

[#567]: https://github.com/benmosher/eslint-plugin-import/issues/567
[#566]: https://github.com/benmosher/eslint-plugin-import/issues/566
[#545]: https://github.com/benmosher/eslint-plugin-import/issues/545
[#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
@@ -382,7 +401,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.15.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.16.0...HEAD
[1.16.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.15.0...v1.16.0
[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
@@ -445,3 +465,6 @@ for info on changes for earlier releases.
[@wKich]: https://github.com/wKich
[@tizmagik]: https://github.com/tizmagik
[@knpwrs]: https://github.com/knpwrs
[@spalger]: https://github.com/spalger
[@preco21]: https://github.com/preco21
[@skyrpex]: https://github.com/skyrpex
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -20,13 +20,15 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* 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`])
* Forbid `require()` calls with expressions ([`no-dynamic-require`])

[`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
[`no-dynamic-require`]: ./docs/rules/no-dynamic-require.md

**Helpful warnings:**

4 changes: 3 additions & 1 deletion docs/rules/extensions.md
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@ In order to provide a consistent use of file extensions across your code base, t

## Rule Details

This rule has one option which could be either a string or an object. If it is `"never"` (the default value) the rule forbids the use for any extension. If `"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.

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.

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".

### Exception

When disallowing the use of certain extensions this rule makes an exception and allows the use of extension when the file would not be resolvable without extension.
24 changes: 24 additions & 0 deletions docs/rules/no-dynamic-require.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Forbid `require()` calls with expressions

The `require` method from CommonJS is used to import modules from different files. Unlike the ES6 `import` syntax, it can be given expressions that will be resolved at runtime. While this is sometimes necessary and useful, in most cases it isn't. Using expressions (for instance, concatenating a path and variable) as the argument makes it harder for tools to do static code analysis, or to find where in the codebase a module is used.

This rule checks every call to `require()` that uses expressions for the module name argument.

## Rule Details

### Fail

```js
require(name);
require('../' + name);
require(`../${name}`);
require(name());
```

### Pass

```js
require('../name');
require('../name' + name);
require(`../name`);
```
2 changes: 1 addition & 1 deletion docs/rules/no-extraneous-dependencies.md
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ You can set the options like this:
You can also use an array of globs instead of literal booleans:

```js
"import/no-extraneous-dependencies": ["error", {"devDependencies": ['*.test.js', '*.spec.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.
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
@@ -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:
@@ -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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "1.15.0",
"version": "1.16.0",
"description": "Import with sanity.",
"main": "lib/index.js",
"directories": {
@@ -60,11 +60,11 @@
"gulp-babel": "6.1.2",
"istanbul": "^0.4.0",
"mocha": "^2.2.1",
"nyc": "^7.0.0",
"nyc": "^8.3.0",
"redux": "^3.0.4",
"rimraf": "2.5.2",
"typescript": "^1.8.10",
"typescript-eslint-parser": "^0.2.0"
"typescript-eslint-parser": "^0.3.0"
},
"peerDependencies": {
"eslint": "2.x - 3.x"
@@ -77,6 +77,7 @@
"es6-map": "^0.1.3",
"es6-set": "^0.1.4",
"eslint-import-resolver-node": "^0.2.0",
"has": "^1.0.1",
"lodash.cond": "^4.3.0",
"lodash.endswith": "^4.0.1",
"lodash.find": "^4.3.0",
1 change: 0 additions & 1 deletion resolvers/node/.npmignore

This file was deleted.

6 changes: 6 additions & 0 deletions resolvers/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ All notable changes to this resolver will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased
### Fixed
- use `files` in `package.json` to ship only `index.js` ([#531], thanks for noticing [@lukeapage])

## v0.2.3 - 2016-08-20
### Added
- debug logging (use `DEBUG=eslint-plugin-import:resolver:node eslint [...]`)
@@ -22,6 +26,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

[#438]: https://github.com/benmosher/eslint-plugin-import/pull/438

[#531]: https://github.com/benmosher/eslint-plugin-import/issues/531
[#437]: https://github.com/benmosher/eslint-plugin-import/issues/437

[@jasonkarns]: https://github.com/jasonkarns
[@lukeapage]: https://github.com/lukeapage
1 change: 1 addition & 0 deletions resolvers/node/package.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"version": "0.2.3",
"description": "Node default behavior import resolution plugin for eslint-plugin-import.",
"main": "index.js",
"files": ["index.js"],
"scripts": {
"test": "nyc mocha"
},
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
@@ -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
@@ -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
@@ -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
7 changes: 6 additions & 1 deletion resolvers/webpack/index.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ var findRoot = require('find-root')
, assign = require('object-assign')
, resolve = require('resolve')
, semver = require('semver')
, has = require('has')

var log = require('debug')('eslint-plugin-import:resolver:webpack')

@@ -68,6 +69,10 @@ exports.resolve = function (source, file, settings) {
webpackConfig = {}
}

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

if (webpackConfig && webpackConfig.default) {
log('Using ES6 module "default" key instead of module.exports.')
webpackConfig = webpackConfig.default
@@ -261,7 +266,7 @@ function findExternal(source, externals, context) {

// else, vanilla object
for (var key in externals) {
if (!externals.hasOwnProperty(key)) continue
if (!has(externals, key)) continue
if (source === key) return true
}
return false
6 changes: 5 additions & 1 deletion resolvers/webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "eslint-import-resolver-webpack",
"version": "0.5.1",
"version": "0.6.0",
"description": "Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.",
"main": "index.js",
"scripts": {
"test": "nyc mocha -t 5s",
"report": "nyc report --reporter=html"
},
"files": [
"index.js",
"config.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/benmosher/eslint-plugin-import.git"
Loading