Skip to content

Commit

Permalink
order: Fix interpreting some external modules being interpreted as …
Browse files Browse the repository at this point in the history
…internal modules

Fixes #793.
  • Loading branch information
ephys authored and ljharb committed Apr 6, 2017
1 parent 359a200 commit 7a330f5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## [Unreleased]

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

## [2.8.0] - 2017-10-18
### Added
Expand Down Expand Up @@ -443,6 +444,7 @@ for info on changes for earlier releases.
[#858]: https://github.com/benmosher/eslint-plugin-import/pull/858
[#843]: https://github.com/benmosher/eslint-plugin-import/pull/843
[#871]: https://github.com/benmosher/eslint-plugin-import/pull/871
[#794]: https://github.com/benmosher/eslint-plugin-import/pull/794
[#744]: https://github.com/benmosher/eslint-plugin-import/pull/744
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
[#737]: https://github.com/benmosher/eslint-plugin-import/pull/737
Expand Down Expand Up @@ -514,6 +516,7 @@ for info on changes for earlier releases.
[#720]: https://github.com/benmosher/eslint-plugin-import/issues/720
[#686]: https://github.com/benmosher/eslint-plugin-import/issues/686
[#671]: https://github.com/benmosher/eslint-plugin-import/issues/671
[#793]: https://github.com/benmosher/eslint-plugin-import/issues/793
[#660]: https://github.com/benmosher/eslint-plugin-import/issues/660
[#653]: https://github.com/benmosher/eslint-plugin-import/issues/653
[#627]: https://github.com/benmosher/eslint-plugin-import/issues/627
Expand Down Expand Up @@ -670,3 +673,4 @@ for info on changes for earlier releases.
[@rosswarren]: https://github.com/rosswarren
[@alexgorbatchev]: https://github.com/alexgorbatchev
[@robertrossmann]: https://github.com/robertrossmann
[@ephys]: https://github.com/ephys
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"eslint-plugin-typescript": "^0.8.1",
"gulp": "^3.9.0",
Expand Down
6 changes: 5 additions & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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/
Expand Down
5 changes: 5 additions & 0 deletions tests/files/order-redirect/module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "order-redirect-module",
"private": true,
"main": "../other-module/file.js"
}
Empty file.
5 changes: 5 additions & 0 deletions tests/files/order-redirect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "eslint-import-test-order-redirect",
"version": "1.0.0",
"private": true
}
6 changes: 6 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down

0 comments on commit 7a330f5

Please sign in to comment.