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

Fix @/abc being treated as scoped module #1854

Merged
merged 1 commit into from Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

### Fixed
- [`default`]/TypeScript: avoid crash on `export =` with a MemberExpression ([#1841], thanks [@ljharb])
- [`extensions`]/importType: Fix @/abc being treated as scoped module ([#1854], thanks [@3nuc])

## [2.22.0] - 2020-06-26
### Added
Expand Down Expand Up @@ -725,6 +726,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
[#1841]: https://github.com/benmosher/eslint-plugin-import/issues/1841
[#1836]: https://github.com/benmosher/eslint-plugin-import/pull/1836
[#1835]: https://github.com/benmosher/eslint-plugin-import/pull/1835
Expand Down Expand Up @@ -1260,3 +1262,4 @@ for info on changes for earlier releases.
[@be5invis]: https://github.com/be5invis
[@noelebrun]: https://github.com/noelebrun
[@beatrizrezener]: https://github.com/beatrizrezener
[@3nuc]: https://github.com/3nuc
2 changes: 1 addition & 1 deletion src/core/importType.js
Expand Up @@ -93,7 +93,7 @@ function typeTest(name, settings, path) {
}

export function isScopedModule(name) {
return name.indexOf('@') === 0
return name.indexOf('@') === 0 && !name.startsWith('@/')
}

export default function resolveImportType(name, context) {
Expand Down
7 changes: 6 additions & 1 deletion tests/src/core/importType.js
@@ -1,7 +1,7 @@
import { expect } from 'chai'
import * as path from 'path'

import importType, {isExternalModule} from 'core/importType'
import importType, {isExternalModule, isScopedModule} from 'core/importType'

import { testContext, testFilePath } from '../utils'

Expand Down Expand Up @@ -237,4 +237,9 @@ describe('importType(name)', function () {
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)
})

it('correctly identifies scoped modules with `isScopedModule`', () => {
expect(isScopedModule('@/abc')).to.equal(false)
expect(isScopedModule('@a/abc')).to.equal(true)
})
})
10 changes: 10 additions & 0 deletions tests/src/rules/extensions.js
Expand Up @@ -444,5 +444,15 @@ ruleTester.run('extensions', rule, {
},
],
}),
test({
code: 'import foo from "@/ImNotAScopedModule"',
options: ['always'],
errors: [
{
message: 'Missing file extension for "@/ImNotAScopedModule"',
line: 1,
},
],
}),
],
})