Skip to content

Commit b57a4f9

Browse files
committedSep 5, 2019
💥 update node/*-import rules to recognize dynamic imports
1 parent df979d3 commit b57a4f9

5 files changed

+42
-1
lines changed
 

‎lib/util/visit-import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ module.exports = function visitImport(
3737
return {
3838
[[
3939
"ExportAllDeclaration",
40-
"ExportDefaultDeclaration",
4140
"ExportNamedDeclaration",
4241
"ImportDeclaration",
42+
"ImportExpression",
4343
]](node) {
4444
const sourceNode = node.source
4545
const name = sourceNode && stripImportPathParams(sourceNode.value)

‎tests/lib/rules/file-extension-in-import.js

+17
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,22 @@ new RuleTester({
238238
options: ["never"],
239239
errors: [{ messageId: "forbidExt", data: { ext: ".cjs" } }],
240240
},
241+
242+
// import()
243+
{
244+
filename: fixture("test.js"),
245+
code: "function f() { import('./a') }",
246+
output: "function f() { import('./a.js') }",
247+
parserOptions: { ecmaVersion: 2020 },
248+
errors: [{ messageId: "requireExt", data: { ext: ".js" } }],
249+
},
250+
{
251+
filename: fixture("test.js"),
252+
code: "function f() { import('./a.js') }",
253+
output: "function f() { import('./a') }",
254+
options: ["never"],
255+
parserOptions: { ecmaVersion: 2020 },
256+
errors: [{ messageId: "forbidExt", data: { ext: ".js" } }],
257+
},
241258
],
242259
})

‎tests/lib/rules/no-extraneous-import.js

+8
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ ruleTester.run("no-extraneous-import", rule, {
8585
code: "import bbb from 'bbb'",
8686
errors: ['"bbb" is extraneous.'],
8787
},
88+
89+
// import()
90+
{
91+
filename: fixture("dependencies/a.js"),
92+
code: "function f() { import('bbb') }",
93+
parserOptions: { ecmaVersion: 2020 },
94+
errors: ['"bbb" is extraneous.'],
95+
},
8896
],
8997
})

‎tests/lib/rules/no-missing-import.js

+8
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,13 @@ ruleTester.run("no-missing-import", rule, {
210210
code: "import a from './A.js';",
211211
errors: ['"./A.js" is not found.'],
212212
},
213+
214+
// import()
215+
{
216+
filename: fixture("test.js"),
217+
code: "function f() { import('no-exist-package-0') }",
218+
parserOptions: { ecmaVersion: 2020 },
219+
errors: ['"no-exist-package-0" is not found.'],
220+
},
213221
],
214222
})

‎tests/lib/rules/no-unpublished-import.js

+8
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,13 @@ ruleTester.run("no-unpublished-import", rule, {
244244
env: { node: true },
245245
errors: ['"../2/a.js" is not published.'],
246246
},
247+
248+
// import()
249+
{
250+
filename: fixture("2/test.js"),
251+
code: "function f() { import('./ignore1.js') }",
252+
parserOptions: { ecmaVersion: 2020 },
253+
errors: ['"./ignore1.js" is not published.'],
254+
},
247255
],
248256
})

0 commit comments

Comments
 (0)
Please sign in to comment.