Skip to content

Commit 7a330f5

Browse files
ephysljharb
authored andcommitted
order: Fix interpreting some external modules being interpreted as internal modules
Fixes import-js#793.
1 parent 359a200 commit 7a330f5

File tree

7 files changed

+26
-1
lines changed

7 files changed

+26
-1
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66
## [Unreleased]
77

88
- Add [`group-exports`] rule: style-guide rule to report use of multiple named exports ([#721], thanks [@robertrossmann])
9+
- [`order`]: Fix interpreting some external modules being interpreted as internal modules ([#793], [#794] thanks [@ephys])
910

1011
## [2.8.0] - 2017-10-18
1112
### Added
@@ -443,6 +444,7 @@ for info on changes for earlier releases.
443444
[#858]: https://github.com/benmosher/eslint-plugin-import/pull/858
444445
[#843]: https://github.com/benmosher/eslint-plugin-import/pull/843
445446
[#871]: https://github.com/benmosher/eslint-plugin-import/pull/871
447+
[#794]: https://github.com/benmosher/eslint-plugin-import/pull/794
446448
[#744]: https://github.com/benmosher/eslint-plugin-import/pull/744
447449
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
448450
[#737]: https://github.com/benmosher/eslint-plugin-import/pull/737
@@ -514,6 +516,7 @@ for info on changes for earlier releases.
514516
[#720]: https://github.com/benmosher/eslint-plugin-import/issues/720
515517
[#686]: https://github.com/benmosher/eslint-plugin-import/issues/686
516518
[#671]: https://github.com/benmosher/eslint-plugin-import/issues/671
519+
[#793]: https://github.com/benmosher/eslint-plugin-import/issues/793
517520
[#660]: https://github.com/benmosher/eslint-plugin-import/issues/660
518521
[#653]: https://github.com/benmosher/eslint-plugin-import/issues/653
519522
[#627]: https://github.com/benmosher/eslint-plugin-import/issues/627
@@ -670,3 +673,4 @@ for info on changes for earlier releases.
670673
[@rosswarren]: https://github.com/rosswarren
671674
[@alexgorbatchev]: https://github.com/alexgorbatchev
672675
[@robertrossmann]: https://github.com/robertrossmann
676+
[@ephys]: https://github.com/ephys

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"eslint-import-resolver-node": "file:./resolvers/node",
6161
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
6262
"eslint-module-utils": "file:./utils",
63+
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
6364
"eslint-plugin-import": "2.x",
6465
"eslint-plugin-typescript": "^0.8.1",
6566
"gulp": "^3.9.0",

Diff for: src/core/importType.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export function isBuiltIn(name, settings) {
2929

3030
function isExternalPath(path, name, settings) {
3131
const folders = (settings && settings['import/external-module-folders']) || ['node_modules']
32-
return !path || folders.some(folder => -1 < path.indexOf(join(folder, name)))
32+
33+
// extract the part before the first / (redux-saga/effects => redux-saga)
34+
const packageName = name.match(/([^\/]+)/)[0]
35+
36+
return !path || folders.some(folder => -1 < path.indexOf(join(folder, packageName)))
3337
}
3438

3539
const externalModuleRegExp = /^\w/

Diff for: tests/files/order-redirect/module/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "order-redirect-module",
3+
"private": true,
4+
"main": "../other-module/file.js"
5+
}

Diff for: tests/files/order-redirect/other-module/file.js

Whitespace-only changes.

Diff for: tests/files/order-redirect/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "eslint-import-test-order-redirect",
3+
"version": "1.0.0",
4+
"private": true
5+
}

Diff for: tests/src/rules/order.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ ruleTester.run('order', rule, {
2929
import sibling, {foo3} from './foo';
3030
import index from './';`,
3131
}),
32+
// Importing a package which contains nothing but a package.json which resolves elsewhere
33+
test({
34+
code: `
35+
import reduxSagaEffects from 'eslint-import-test-order-redirect/module';
36+
import relParent1 from '../foo';`,
37+
}),
3238
// Multiple module of the same rank next to each other
3339
test({
3440
code: `

0 commit comments

Comments
 (0)