diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bbb880e0..25a6e3885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [Unreleased] +### Fixed +- [`order`]: Fix interpreting some external modules being interpreted as internal modules ([#793], [#794] thanks [@ephys]) ## [2.7.0] - 2017-07-06 ### Changed @@ -418,9 +420,9 @@ for info on changes for earlier releases. [`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md [`unambiguous`]: ./docs/rules/unambiguous.md [`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md - [`memo-parser`]: ./memo-parser/README.md +[#794]: https://github.com/benmosher/eslint-plugin-import/pull/794 [#843]: https://github.com/benmosher/eslint-plugin-import/pull/843 [#871]: https://github.com/benmosher/eslint-plugin-import/pull/871 [#742]: https://github.com/benmosher/eslint-plugin-import/pull/742 @@ -482,6 +484,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 +[#793]: https://github.com/benmosher/eslint-plugin-import/issues/793 [#863]: https://github.com/benmosher/eslint-plugin-import/issues/863 [#839]: https://github.com/benmosher/eslint-plugin-import/issues/839 [#686]: https://github.com/benmosher/eslint-plugin-import/issues/686 @@ -633,3 +636,4 @@ for info on changes for earlier releases. [@eelyafi]: https://github.com/eelyafi [@mastilver]: https://github.com/mastilver [@jseminck]: https://github.com/jseminck +[@ephys]: https://github.com/ephys diff --git a/package.json b/package.json index c62fbcfe7..c132f27dd 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "eslint-import-resolver-node": "file:./resolvers/node", "eslint-import-resolver-webpack": "file:./resolvers/webpack", "eslint-module-utils": "file:./utils", + "eslint-import-test-order-redirect": "file:./tests/files/order-redirect", "eslint-plugin-import": "2.x", "gulp": "^3.9.0", "gulp-babel": "6.1.2", diff --git a/src/core/importType.js b/src/core/importType.js index 905b82613..d6deaa3b6 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -19,7 +19,11 @@ export function isBuiltIn(name, settings) { function isExternalPath(path, name, settings) { const folders = (settings && settings['import/external-module-folders']) || ['node_modules'] - return !path || folders.some(folder => -1 < path.indexOf(join(folder, name))) + + // extract the part before the first / (redux-saga/effects => redux-saga) + const packageName = name.match(/([^/]+)/)[0] + + return !path || folders.some(folder => -1 < path.indexOf(join(folder, packageName))) } const externalModuleRegExp = /^\w/ diff --git a/tests/files/order-redirect/module/package.json b/tests/files/order-redirect/module/package.json new file mode 100644 index 000000000..6c4325e8e --- /dev/null +++ b/tests/files/order-redirect/module/package.json @@ -0,0 +1,5 @@ +{ + "name": "order-redirect-module", + "private": true, + "main": "../other-module/file.js" +} diff --git a/tests/files/order-redirect/other-module/file.js b/tests/files/order-redirect/other-module/file.js new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/order-redirect/package.json b/tests/files/order-redirect/package.json new file mode 100644 index 000000000..1605a2203 --- /dev/null +++ b/tests/files/order-redirect/package.json @@ -0,0 +1,5 @@ +{ + "name": "eslint-import-test-order-redirect", + "version": "1.0.0", + "private": true +} diff --git a/tests/src/rules/order.js b/tests/src/rules/order.js index c87508573..13e8008c5 100644 --- a/tests/src/rules/order.js +++ b/tests/src/rules/order.js @@ -29,6 +29,12 @@ ruleTester.run('order', rule, { import sibling, {foo3} from './foo'; import index from './';`, }), + // Importing a package which contains nothing but a package.json which resolves elsewhere + test({ + code: ` + import reduxSagaEffects from 'eslint-import-test-order-redirect/module'; + import relParent1 from '../foo';`, + }), // Multiple module of the same rank next to each other test({ code: `