forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-duplicate-imports.js
89 lines (83 loc) · 3.66 KB
/
no-duplicate-imports.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @fileoverview Tests for no-duplicate-imports.
* @author Simen Bekkhus
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-duplicate-imports"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } });
ruleTester.run("no-duplicate-imports", rule, {
valid: [
"import * as Lodash from \"lodash-es\";import { merge } from \"lodash-es\";;",
"import os from \"os\";\nimport fs from \"fs\";",
"import { merge } from \"lodash-es\";",
"import _, { merge } from \"lodash-es\";",
"import * as Foobar from \"async\";",
"import \"foo\"",
"import os from \"os\";\nexport { something } from \"os\";",
{
code: "import os from \"os\";\nexport { hello } from \"hello\";",
options: [{ includeExports: true }]
},
{
code: "import os from \"os\";\nexport * from \"hello\";",
options: [{ includeExports: true }]
},
{
code: "import os from \"os\";\nexport { hello as hi } from \"hello\";",
options: [{ includeExports: true }]
},
{
code: "import os from \"os\";\nexport default function(){};",
options: [{ includeExports: true }]
},
{
code: "import { merge } from \"lodash-es\";\nexport { merge as lodashMerge }",
options: [{ includeExports: true }]
}
],
invalid: [
{
code: "import \"fs\";\nimport \"fs\"",
errors: [{ messageId: "import", data: { module: "fs" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import { find } from \"lodash-es\";",
errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import _ from \"lodash-es\";",
errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "export { os } from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
errors: [{ messageId: "export", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\"; export { os as foobar } from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
errors: [
{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" },
{ messageId: "export", data: { module: "os" }, type: "ExportNamedDeclaration" },
{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" }
]
},
{
code: "import os from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }],
errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportAllDeclaration" }]
}
]
});