Skip to content

Commit

Permalink
💥 update node/*-import rules to recognize dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 5, 2019
1 parent df979d3 commit b57a4f9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/visit-import.js
Expand Up @@ -37,9 +37,9 @@ module.exports = function visitImport(
return {
[[
"ExportAllDeclaration",
"ExportDefaultDeclaration",
"ExportNamedDeclaration",
"ImportDeclaration",
"ImportExpression",
]](node) {
const sourceNode = node.source
const name = sourceNode && stripImportPathParams(sourceNode.value)
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/file-extension-in-import.js
Expand Up @@ -238,5 +238,22 @@ new RuleTester({
options: ["never"],
errors: [{ messageId: "forbidExt", data: { ext: ".cjs" } }],
},

// import()
{
filename: fixture("test.js"),
code: "function f() { import('./a') }",
output: "function f() { import('./a.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "requireExt", data: { ext: ".js" } }],
},
{
filename: fixture("test.js"),
code: "function f() { import('./a.js') }",
output: "function f() { import('./a') }",
options: ["never"],
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "forbidExt", data: { ext: ".js" } }],
},
],
})
8 changes: 8 additions & 0 deletions tests/lib/rules/no-extraneous-import.js
Expand Up @@ -85,5 +85,13 @@ ruleTester.run("no-extraneous-import", rule, {
code: "import bbb from 'bbb'",
errors: ['"bbb" is extraneous.'],
},

// import()
{
filename: fixture("dependencies/a.js"),
code: "function f() { import('bbb') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"bbb" is extraneous.'],
},
],
})
8 changes: 8 additions & 0 deletions tests/lib/rules/no-missing-import.js
Expand Up @@ -210,5 +210,13 @@ ruleTester.run("no-missing-import", rule, {
code: "import a from './A.js';",
errors: ['"./A.js" is not found.'],
},

// import()
{
filename: fixture("test.js"),
code: "function f() { import('no-exist-package-0') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"no-exist-package-0" is not found.'],
},
],
})
8 changes: 8 additions & 0 deletions tests/lib/rules/no-unpublished-import.js
Expand Up @@ -244,5 +244,13 @@ ruleTester.run("no-unpublished-import", rule, {
env: { node: true },
errors: ['"../2/a.js" is not published.'],
},

// import()
{
filename: fixture("2/test.js"),
code: "function f() { import('./ignore1.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"./ignore1.js" is not published.'],
},
],
})

0 comments on commit b57a4f9

Please sign in to comment.