diff --git a/src/core/importType.js b/src/core/importType.js index ef67b28cca..81e632fd43 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -30,15 +30,12 @@ export function isBuiltIn(name, settings, path) { return isCoreModule(base) || extras.indexOf(base) > -1; } -export function isExternalModule(name, settings, path, context) { - if (arguments.length < 4) { - throw new TypeError('isExternalModule: name, settings, path, and context are all required'); - } - return (isModule(name) || isScoped(name)) && typeTest(name, context, path, settings) === 'external'; +export function isExternalModule(name, path, context) { + return (isModule(name) || isScoped(name)) && typeTest(name, context, path) === 'external'; } -export function isExternalModuleMain(name, settings, path, context) { - return isModuleMain(name) && typeTest(name, context, path, settings) === 'external'; +export function isExternalModuleMain(name, path, context) { + return isModuleMain(name) && typeTest(name, context, path) === 'external'; } const moduleRegExp = /^\w/; @@ -106,7 +103,8 @@ function isExternalLookingName(name) { return isModule(name) || isScoped(name); } -function typeTest(name, context, path, settings = context.settings) { +function typeTest(name, context, path ) { + const { settings } = context; if (isInternalRegexMatch(name, settings)) { return 'internal'; } if (isAbsolute(name, settings, path)) { return 'absolute'; } if (isBuiltIn(name, settings, path)) { return 'builtin'; } diff --git a/src/rules/extensions.js b/src/rules/extensions.js index 677a0a0959..8596cbfd0f 100644 --- a/src/rules/extensions.js +++ b/src/rules/extensions.js @@ -159,7 +159,6 @@ module.exports = { // determine if this is a module const isPackage = isExternalModule( importPath, - context.settings, resolve(importPath, context), context, ) || isScoped(importPath); diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index cefa41f99d..e61c3be26c 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -44,7 +44,6 @@ module.exports = { const maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity; const ignoreModule = (name) => options.ignoreExternal && isExternalModule( name, - context.settings, resolve(name, context), context, ); diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index a73d47f242..937f193033 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -245,20 +245,20 @@ describe('importType(name)', function () { it('`isExternalModule` works with windows directory separator', function () { const context = testContext(); - expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true); - expect(isExternalModule('@foo/bar', {}, 'E:\\path\\to\\node_modules\\@foo\\bar', context)).to.equal(true); - expect(isExternalModule('foo', { - 'import/external-module-folders': ['E:\\path\\to\\node_modules'], - }, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true); + expect(isExternalModule('foo', 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true); + expect(isExternalModule('@foo/bar', 'E:\\path\\to\\node_modules\\@foo\\bar', context)).to.equal(true); + expect(isExternalModule('foo', 'E:\\path\\to\\node_modules\\foo', testContext({ + settings: { 'import/external-module-folders': ['E:\\path\\to\\node_modules'] }, + }))).to.equal(true); }); it('`isExternalModule` works with unix directory separator', function () { const context = testContext(); - expect(isExternalModule('foo', {}, '/path/to/node_modules/foo', context)).to.equal(true); - expect(isExternalModule('@foo/bar', {}, '/path/to/node_modules/@foo/bar', context)).to.equal(true); - expect(isExternalModule('foo', { - 'import/external-module-folders': ['/path/to/node_modules'], - }, '/path/to/node_modules/foo', context)).to.equal(true); + expect(isExternalModule('foo', '/path/to/node_modules/foo', context)).to.equal(true); + expect(isExternalModule('@foo/bar', '/path/to/node_modules/@foo/bar', context)).to.equal(true); + expect(isExternalModule('foo', '/path/to/node_modules/foo', testContext({ + settings: { 'import/external-module-folders': ['/path/to/node_modules'] }, + }))).to.equal(true); }); it('correctly identifies scoped modules with `isScoped`', () => {