Skip to content

Commit d6db8fc

Browse files
fix: scoped import support
1 parent 75d537b commit d6db8fc

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/rules/prefer-alias.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export default {
3333
ImportDeclaration: node => {
3434
const importPath = node.source.value
3535
const hasAlias =
36-
aliases |> keys |> some(alias => importPath |> startsWith(alias))
36+
aliases
37+
|> keys
38+
|> some(alias => importPath |> startsWith(`${alias}/`))
3739
const resolvedImport = resolvePath(importPath, path, {
3840
alias: aliases,
3941
})

src/rules/prefer-alias.spec.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const runTest = config => () => {
3535
}
3636

3737
export default {
38-
'external import': {
38+
external: {
3939
code: endent`
4040
import foo from 'foo'
4141
`,
4242
},
43-
'parent import': {
43+
parent: {
4444
code: endent`
4545
import foo from '../foo/bar'
4646
`,
@@ -58,7 +58,7 @@ export default {
5858
"Unexpected parent import '../../foo'. No matching alias found to fix the issue",
5959
],
6060
},
61-
'alias parent import': {
61+
'alias parent': {
6262
files: {
6363
'foo.js': '',
6464
},
@@ -67,7 +67,7 @@ export default {
6767
`,
6868
filename: 'sub/index.js',
6969
},
70-
'alias subpath import': {
70+
'alias subpath': {
7171
files: {
7272
'foo.js': '',
7373
},
@@ -79,4 +79,12 @@ export default {
7979
],
8080
output: "import foo from './foo'",
8181
},
82+
scoped: {
83+
files: {
84+
'foo.js': '',
85+
},
86+
code: endent`
87+
import foo from '@foo/bar'
88+
`,
89+
},
8290
} |> mapValues(runTest)

0 commit comments

Comments
 (0)