Skip to content

Commit

Permalink
Fix: ignore unmergable imports when checking no-duplicate-imports (fixes
Browse files Browse the repository at this point in the history
 eslint#13180) & Fix: Ignore re-export all in no-duplicate-imports (fixes eslint#12760)
  • Loading branch information
boutahlilsoufiane committed May 27, 2021
1 parent f97848b commit d515f8d
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions tests/lib/rules/no-duplicate-imports.js
Expand Up @@ -16,7 +16,7 @@ const rule = require("../../../lib/rules/no-duplicate-imports"),
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } });
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 12, sourceType: "module" } });

ruleTester.run("no-duplicate-imports", rule, {
valid: [
Expand All @@ -26,6 +26,8 @@ ruleTester.run("no-duplicate-imports", rule, {
"import * as Foobar from \"async\";",
"import \"foo\"",
"import os from \"os\";\nexport { something } from \"os\";",
"import * as bar from \"os\";\nimport { baz } from \"os\";",
"import foo, * as bar from \"os\";\nimport { baz } from \"os\";",
{
code: "import os from \"os\";\nexport { hello } from \"hello\";",
options: [{ includeExports: true }]
Expand All @@ -45,6 +47,14 @@ ruleTester.run("no-duplicate-imports", rule, {
{
code: "import { merge } from \"lodash-es\";\nexport { merge as lodashMerge }",
options: [{ includeExports: true }]
},
{
code: "import os from \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }]
},
{
code: "export { something } from \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }]
}
],
invalid: [
Expand All @@ -53,11 +63,22 @@ ruleTester.run("no-duplicate-imports", rule, {
errors: [{ messageId: "import", data: { module: "fs" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import { find } from \"lodash-es\";",
code: "import { merge } from \"lodash-es\";\nimport { find } from \"lodash-es\";",
errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import _ from \"lodash-es\";",
code: "import { merge } from \"lodash-es\";\nimport _ from \"lodash-es\";",
errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "import os from \"os\";\nimport { something } from \"os\";\nimport * as foobar from \"os\";",
errors: [
{ messageId: "import", data: { module: "os" }, type: "ImportDeclaration" },
{ messageId: "import", data: { module: "os" }, type: "ImportDeclaration" }
]
},
{
code: "import * as modns from \"lodash-es\";\nimport { merge } from \"lodash-es\";\nimport { baz } from \"lodash-es\";",
errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
Expand All @@ -66,7 +87,7 @@ ruleTester.run("no-duplicate-imports", rule, {
errors: [{ messageId: "export", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\"; export { os as foobar } from \"os\";\nexport { something } from \"os\";",
code: "import os from \"os\";\nexport { os as foobar } from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
errors: [
{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" },
Expand All @@ -80,7 +101,17 @@ ruleTester.run("no-duplicate-imports", rule, {
errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\";\nexport * from \"os\";",
code: "import * as modns from \"mod\";\nexport * as modns from \"mod\";",
options: [{ includeExports: true }],
errors: [{ messageId: "exportAs", data: { module: "mod" }, type: "ExportAllDeclaration" }]
},
{
code: "export * from \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }],
errors: [{ messageId: "export", data: { module: "os" }, type: "ExportAllDeclaration" }]
},
{
code: "import \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }],
errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportAllDeclaration" }]
}
Expand Down

0 comments on commit d515f8d

Please sign in to comment.