Skip to content

Commit 3e65a70

Browse files
Artur Tagisowljharb
authored andcommitted
[Fix] extensions/importType: Fix @/abc being treated as scoped module
Fixes #1851 Before this commit, @/abc was being wrongly detected as a scoped module. This was a problem when somebody had a webpack alias `@`. (eg. @ -> ./src) In general, scoped modules can't start with @/, I think they have to be like @/abcd.
1 parent 843055c commit 3e65a70

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
88

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

1213
## [2.22.0] - 2020-06-26
1314
### Added
@@ -725,6 +726,7 @@ for info on changes for earlier releases.
725726

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

729+
[#1854]: https://github.com/benmosher/eslint-plugin-import/issues/1854
728730
[#1841]: https://github.com/benmosher/eslint-plugin-import/issues/1841
729731
[#1836]: https://github.com/benmosher/eslint-plugin-import/pull/1836
730732
[#1835]: https://github.com/benmosher/eslint-plugin-import/pull/1835
@@ -1260,3 +1262,4 @@ for info on changes for earlier releases.
12601262
[@be5invis]: https://github.com/be5invis
12611263
[@noelebrun]: https://github.com/noelebrun
12621264
[@beatrizrezener]: https://github.com/beatrizrezener
1265+
[@3nuc]: https://github.com/3nuc

src/core/importType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function typeTest(name, settings, path) {
9393
}
9494

9595
export function isScopedModule(name) {
96-
return name.indexOf('@') === 0
96+
return name.indexOf('@') === 0 && !name.startsWith('@/')
9797
}
9898

9999
export default function resolveImportType(name, context) {

tests/src/core/importType.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22
import * as path from 'path'
33

4-
import importType, {isExternalModule} from 'core/importType'
4+
import importType, {isExternalModule, isScopedModule} from 'core/importType'
55

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

@@ -237,4 +237,9 @@ describe('importType(name)', function () {
237237
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
238238
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)
239239
})
240+
241+
it('correctly identifies scoped modules with `isScopedModule`', () => {
242+
expect(isScopedModule('@/abc')).to.equal(false)
243+
expect(isScopedModule('@a/abc')).to.equal(true)
244+
})
240245
})

tests/src/rules/extensions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,5 +444,15 @@ ruleTester.run('extensions', rule, {
444444
},
445445
],
446446
}),
447+
test({
448+
code: 'import foo from "@/ImNotAScopedModule"',
449+
options: ['always'],
450+
errors: [
451+
{
452+
message: 'Missing file extension for "@/ImNotAScopedModule"',
453+
line: 1,
454+
},
455+
],
456+
}),
447457
],
448458
})

0 commit comments

Comments
 (0)