Skip to content

Commit 9b6def1

Browse files
committed
[new] order: add internal-regex setting for marking packages as internal
1 parent 5e143b2 commit 9b6def1

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ settings:
402402
[`eslint_d`]: https://www.npmjs.com/package/eslint_d
403403
[`eslint-loader`]: https://www.npmjs.com/package/eslint-loader
404404

405+
#### `import/internal-regex`
406+
407+
A regex for packages should be treated as internal.
408+
405409

406410
## SublimeLinter-eslint
407411

src/core/importType.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export function isScopedMain(name) {
5454
}
5555

5656
function isInternalModule(name, settings, path) {
57+
const internalScope = (settings && settings['import/internal-regex'])
5758
const matchesScopedOrExternalRegExp = scopedRegExp.test(name) || externalModuleRegExp.test(name)
58-
return (matchesScopedOrExternalRegExp && !isExternalPath(path, name, settings))
59+
return (matchesScopedOrExternalRegExp && (internalScope && new RegExp(internalScope).test(name) || !isExternalPath(path, name, settings)))
5960
}
6061

6162
function isRelativeToParent(name) {

tests/src/core/importType.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('importType(name)', function () {
5151
const pathContext = testContext({ 'import/resolver': { node: { paths: [pathToTestFiles] } } })
5252
expect(importType('@importType/index', pathContext)).to.equal('internal')
5353
})
54-
54+
5555
it("should return 'internal' for internal modules that are referenced by aliases", function () {
5656
const pathContext = testContext({ 'import/resolver': { node: { paths: [pathToTestFiles] } } })
5757
expect(importType('@my-alias/fn', pathContext)).to.equal('internal')
@@ -130,6 +130,16 @@ describe('importType(name)', function () {
130130
expect(importType('resolve', foldersContext)).to.equal('internal')
131131
})
132132

133+
it("should return 'internal' for module from 'node_modules' if its name matched 'internal-regex'", function() {
134+
const foldersContext = testContext({ 'import/internal-regex': '^@org' })
135+
expect(importType('@org/foobar', foldersContext)).to.equal('internal')
136+
})
137+
138+
it("should return 'external' for module from 'node_modules' if its name did not match 'internal-regex'", function() {
139+
const foldersContext = testContext({ 'import/internal-regex': '^@bar' })
140+
expect(importType('@org/foobar', foldersContext)).to.equal('external')
141+
})
142+
133143
it("should return 'external' for module from 'node_modules' if 'node_modules' contained in 'external-module-folders'", function() {
134144
const foldersContext = testContext({ 'import/external-module-folders': ['node_modules'] })
135145
expect(importType('resolve', foldersContext)).to.equal('external')

0 commit comments

Comments
 (0)