Skip to content

Commit

Permalink
Remove settings argument from isExternalModule and isExternalModuleMain
Browse files Browse the repository at this point in the history
  • Loading branch information
ombene committed Dec 23, 2021
1 parent 105545b commit 670b096
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
14 changes: 6 additions & 8 deletions src/core/importType.js
Expand Up @@ -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/;
Expand Down Expand Up @@ -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'; }
Expand Down
1 change: 0 additions & 1 deletion src/rules/extensions.js
Expand Up @@ -159,7 +159,6 @@ module.exports = {
// determine if this is a module
const isPackage = isExternalModule(
importPath,
context.settings,
resolve(importPath, context),
context,
) || isScoped(importPath);
Expand Down
1 change: 0 additions & 1 deletion src/rules/no-cycle.js
Expand Up @@ -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,
);
Expand Down
20 changes: 10 additions & 10 deletions tests/src/core/importType.js
Expand Up @@ -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`', () => {
Expand Down

0 comments on commit 670b096

Please sign in to comment.