Skip to content

Commit e6c978c

Browse files
committed
test(linter): port unicorn test cases to no-named-default
1 parent a39434a commit e6c978c

File tree

2 files changed

+177
-1
lines changed

2 files changed

+177
-1
lines changed

crates/oxc_linter/src/rules/import/no_named_default.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,47 @@ fn test() {
6464
r#"import { type default as Foo } from "./bar";"#,
6565
];
6666

67+
let unicorn_pass = vec![
68+
r#"import named from "foo";"#,
69+
r#"import "foo";"#,
70+
r#"import * as named from "foo";"#,
71+
r#"export {foo as default} from "foo";"#,
72+
r#"export * as default from "foo";"#,
73+
];
74+
6775
let fail = vec![
6876
r#"import { default as bar } from "./bar";"#,
6977
r#"import { foo, default as bar } from "./bar";"#,
7078
r#"import { "default" as bar } from "./bar";"#,
7179
];
7280

73-
Tester::new(NoNamedDefault::NAME, NoNamedDefault::PLUGIN, pass, fail).test_and_snapshot();
81+
let unicorn_fail = vec![
82+
r#"import {default as named} from "foo";"#,
83+
r#"import {default as named,} from "foo";"#,
84+
r#"import {default as named, bar} from "foo";"#,
85+
r#"import {default as named, bar,} from "foo";"#,
86+
r#"import defaultExport, {default as named} from "foo";"#,
87+
r#"import defaultExport, {default as named,} from "foo";"#,
88+
r#"import defaultExport, {default as named, bar} from "foo";"#,
89+
r#"import defaultExport, {default as named, bar,} from "foo";"#,
90+
r#"import{default as named}from"foo";"#,
91+
r#"import {default as named}from"foo";"#,
92+
r#"import{default as named} from"foo";"#,
93+
r#"import{default as named,}from"foo";"#,
94+
r#"import/*comment*/{default as named}from"foo";"#,
95+
r#"import /*comment*/{default as named}from"foo";"#,
96+
r#"import{default as named}/*comment*/from"foo";"#,
97+
r#"import defaultExport,{default as named}from "foo";"#,
98+
r#"import defaultExport, {default as named} from "foo" with {type: "json"};"#,
99+
r#"import defaultExport, {default as named} from "foo" with {type: "json"}"#,
100+
r#"import {default as named1, default as named2,} from "foo";"#,
101+
];
102+
103+
Tester::new(
104+
NoNamedDefault::NAME,
105+
NoNamedDefault::PLUGIN,
106+
pass.into_iter().chain(unicorn_pass).collect(),
107+
fail.into_iter().chain(unicorn_fail).collect(),
108+
)
109+
.test_and_snapshot();
74110
}

crates/oxc_linter/src/snapshots/import_no_named_default.snap

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,143 @@ source: crates/oxc_linter/src/tester.rs
2121
· ─────────
2222
╰────
2323
help: Forbid named default exports.
24+
25+
eslint-plugin-import(no-named-default): Replace default import with named import.
26+
╭─[no_named_default.tsx:1:9]
27+
1import {default as named} from "foo";
28+
· ───────
29+
╰────
30+
help: Forbid named default exports.
31+
32+
eslint-plugin-import(no-named-default): Replace default import with named import.
33+
╭─[no_named_default.tsx:1:9]
34+
1import {default as named,} from "foo";
35+
· ───────
36+
╰────
37+
help: Forbid named default exports.
38+
39+
eslint-plugin-import(no-named-default): Replace default import with named import.
40+
╭─[no_named_default.tsx:1:9]
41+
1import {default as named, bar} from "foo";
42+
· ───────
43+
╰────
44+
help: Forbid named default exports.
45+
46+
eslint-plugin-import(no-named-default): Replace default import with named import.
47+
╭─[no_named_default.tsx:1:9]
48+
1import {default as named, bar,} from "foo";
49+
· ───────
50+
╰────
51+
help: Forbid named default exports.
52+
53+
eslint-plugin-import(no-named-default): Replace default import with named import.
54+
╭─[no_named_default.tsx:1:24]
55+
1import defaultExport, {default as named} from "foo";
56+
· ───────
57+
╰────
58+
help: Forbid named default exports.
59+
60+
eslint-plugin-import(no-named-default): Replace default import with named import.
61+
╭─[no_named_default.tsx:1:24]
62+
1import defaultExport, {default as named,} from "foo";
63+
· ───────
64+
╰────
65+
help: Forbid named default exports.
66+
67+
eslint-plugin-import(no-named-default): Replace default import with named import.
68+
╭─[no_named_default.tsx:1:24]
69+
1import defaultExport, {default as named, bar} from "foo";
70+
· ───────
71+
╰────
72+
help: Forbid named default exports.
73+
74+
eslint-plugin-import(no-named-default): Replace default import with named import.
75+
╭─[no_named_default.tsx:1:24]
76+
1import defaultExport, {default as named, bar,} from "foo";
77+
· ───────
78+
╰────
79+
help: Forbid named default exports.
80+
81+
eslint-plugin-import(no-named-default): Replace default import with named import.
82+
╭─[no_named_default.tsx:1:8]
83+
1import{default as named}from"foo";
84+
· ───────
85+
╰────
86+
help: Forbid named default exports.
87+
88+
eslint-plugin-import(no-named-default): Replace default import with named import.
89+
╭─[no_named_default.tsx:1:9]
90+
1import {default as named}from"foo";
91+
· ───────
92+
╰────
93+
help: Forbid named default exports.
94+
95+
eslint-plugin-import(no-named-default): Replace default import with named import.
96+
╭─[no_named_default.tsx:1:8]
97+
1import{default as named} from"foo";
98+
· ───────
99+
╰────
100+
help: Forbid named default exports.
101+
102+
eslint-plugin-import(no-named-default): Replace default import with named import.
103+
╭─[no_named_default.tsx:1:8]
104+
1import{default as named,}from"foo";
105+
· ───────
106+
╰────
107+
help: Forbid named default exports.
108+
109+
eslint-plugin-import(no-named-default): Replace default import with named import.
110+
╭─[no_named_default.tsx:1:19]
111+
1import/*comment*/{default as named}from"foo";
112+
· ───────
113+
╰────
114+
help: Forbid named default exports.
115+
116+
eslint-plugin-import(no-named-default): Replace default import with named import.
117+
╭─[no_named_default.tsx:1:20]
118+
1import /*comment*/{default as named}from"foo";
119+
· ───────
120+
╰────
121+
help: Forbid named default exports.
122+
123+
eslint-plugin-import(no-named-default): Replace default import with named import.
124+
╭─[no_named_default.tsx:1:8]
125+
1import{default as named}/*comment*/from"foo";
126+
· ───────
127+
╰────
128+
help: Forbid named default exports.
129+
130+
eslint-plugin-import(no-named-default): Replace default import with named import.
131+
╭─[no_named_default.tsx:1:23]
132+
1import defaultExport,{default as named}from "foo";
133+
· ───────
134+
╰────
135+
help: Forbid named default exports.
136+
137+
eslint-plugin-import(no-named-default): Replace default import with named import.
138+
╭─[no_named_default.tsx:1:24]
139+
1import defaultExport, {default as named} from "foo" with {type: "json"};
140+
· ───────
141+
╰────
142+
help: Forbid named default exports.
143+
144+
eslint-plugin-import(no-named-default): Replace default import with named import.
145+
╭─[no_named_default.tsx:1:24]
146+
1import defaultExport, {default as named} from "foo" with {type: "json"}
147+
· ───────
148+
╰────
149+
help: Forbid named default exports.
150+
151+
eslint-plugin-import(no-named-default): Replace default import with named import.
152+
╭─[no_named_default.tsx:1:9]
153+
1import {default as named1, default as named2,} from "foo";
154+
· ───────
155+
╰────
156+
help: Forbid named default exports.
157+
158+
eslint-plugin-import(no-named-default): Replace default import with named import.
159+
╭─[no_named_default.tsx:1:28]
160+
1import {default as named1, default as named2,} from "foo";
161+
· ───────
162+
╰────
163+
help: Forbid named default exports.

0 commit comments

Comments
 (0)