Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports that are resolvable should not be reported as builtins #1007

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export function isAbsolute(name) {
return name.indexOf('/') === 0
}

export function isBuiltIn(name, settings) {
export function isBuiltIn(name, settings, path) {
const base = baseModule(name)
const extras = (settings && settings['import/core-modules']) || []
return builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1
const isInternal = isInternalModule(name, settings, path)
return !isInternal && (builtinModules.indexOf(base) !== -1 || extras.indexOf(base) > -1)
}

function isExternalPath(path, name, settings) {
Expand Down
Empty file added tests/files/constants/foo.js
Empty file.
5 changes: 5 additions & 0 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ describe('importType(name)', function () {
expect(importType('importType', pathContext)).to.equal('internal')
})

it("should return 'internal' for files resolved outside of node_modules that share a name with a builtin", function () {
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } })
expect(importType('constants/foo', pathContext)).to.equal('internal')
})

it("should return 'parent' for internal modules that go through the parent", function() {
expect(importType('../foo', context)).to.equal('parent')
expect(importType('../../foo', context)).to.equal('parent')
Expand Down