diff --git a/README.md b/README.md index aaa3f4c201..9c876638f5 100644 --- a/README.md +++ b/README.md @@ -402,6 +402,10 @@ settings: [`eslint_d`]: https://www.npmjs.com/package/eslint_d [`eslint-loader`]: https://www.npmjs.com/package/eslint-loader +#### `import/internal-regex` + +A regex for packages should be treated as internal. + ## SublimeLinter-eslint diff --git a/src/core/importType.js b/src/core/importType.js index b948ea2bb9..a3480ae12a 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -54,8 +54,9 @@ export function isScopedMain(name) { } function isInternalModule(name, settings, path) { + const internalScope = (settings && settings['import/internal-regex']) const matchesScopedOrExternalRegExp = scopedRegExp.test(name) || externalModuleRegExp.test(name) - return (matchesScopedOrExternalRegExp && !isExternalPath(path, name, settings)) + return (matchesScopedOrExternalRegExp && (internalScope && new RegExp(internalScope).test(name) || !isExternalPath(path, name, settings))) } function isRelativeToParent(name) { diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 07466bfa92..c85124a1f4 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -51,7 +51,7 @@ describe('importType(name)', function () { const pathContext = testContext({ 'import/resolver': { node: { paths: [pathToTestFiles] } } }) expect(importType('@importType/index', pathContext)).to.equal('internal') }) - + it("should return 'internal' for internal modules that are referenced by aliases", function () { const pathContext = testContext({ 'import/resolver': { node: { paths: [pathToTestFiles] } } }) expect(importType('@my-alias/fn', pathContext)).to.equal('internal') @@ -130,6 +130,16 @@ describe('importType(name)', function () { expect(importType('resolve', foldersContext)).to.equal('internal') }) + it("should return 'internal' for module from 'node_modules' if its name matched 'internal-regex'", function() { + const foldersContext = testContext({ 'import/internal-regex': '^@org' }) + expect(importType('@org/foobar', foldersContext)).to.equal('internal') + }) + + it("should return 'external' for module from 'node_modules' if its name did not match 'internal-regex'", function() { + const foldersContext = testContext({ 'import/internal-regex': '^@bar' }) + expect(importType('@org/foobar', foldersContext)).to.equal('external') + }) + it("should return 'external' for module from 'node_modules' if 'node_modules' contained in 'external-module-folders'", function() { const foldersContext = testContext({ 'import/external-module-folders': ['node_modules'] }) expect(importType('resolve', foldersContext)).to.equal('external')