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