diff --git a/crates/oxc_linter/src/rules/import/no_named_default.rs b/crates/oxc_linter/src/rules/import/no_named_default.rs index 259d89cf335af..4363c86cebffe 100644 --- a/crates/oxc_linter/src/rules/import/no_named_default.rs +++ b/crates/oxc_linter/src/rules/import/no_named_default.rs @@ -64,11 +64,47 @@ fn test() { r#"import { type default as Foo } from "./bar";"#, ]; + let unicorn_pass = vec![ + r#"import named from "foo";"#, + r#"import "foo";"#, + r#"import * as named from "foo";"#, + r#"export {foo as default} from "foo";"#, + r#"export * as default from "foo";"#, + ]; + let fail = vec![ r#"import { default as bar } from "./bar";"#, r#"import { foo, default as bar } from "./bar";"#, r#"import { "default" as bar } from "./bar";"#, ]; - Tester::new(NoNamedDefault::NAME, NoNamedDefault::PLUGIN, pass, fail).test_and_snapshot(); + let unicorn_fail = vec![ + r#"import {default as named} from "foo";"#, + r#"import {default as named,} from "foo";"#, + r#"import {default as named, bar} from "foo";"#, + r#"import {default as named, bar,} from "foo";"#, + r#"import defaultExport, {default as named} from "foo";"#, + r#"import defaultExport, {default as named,} from "foo";"#, + r#"import defaultExport, {default as named, bar} from "foo";"#, + r#"import defaultExport, {default as named, bar,} from "foo";"#, + r#"import{default as named}from"foo";"#, + r#"import {default as named}from"foo";"#, + r#"import{default as named} from"foo";"#, + r#"import{default as named,}from"foo";"#, + r#"import/*comment*/{default as named}from"foo";"#, + r#"import /*comment*/{default as named}from"foo";"#, + r#"import{default as named}/*comment*/from"foo";"#, + r#"import defaultExport,{default as named}from "foo";"#, + r#"import defaultExport, {default as named} from "foo" with {type: "json"};"#, + r#"import defaultExport, {default as named} from "foo" with {type: "json"}"#, + r#"import {default as named1, default as named2,} from "foo";"#, + ]; + + Tester::new( + NoNamedDefault::NAME, + NoNamedDefault::PLUGIN, + pass.into_iter().chain(unicorn_pass).collect(), + fail.into_iter().chain(unicorn_fail).collect(), + ) + .test_and_snapshot(); } diff --git a/crates/oxc_linter/src/snapshots/import_no_named_default.snap b/crates/oxc_linter/src/snapshots/import_no_named_default.snap index 8e3b595b8007a..caf87d3eedb6d 100644 --- a/crates/oxc_linter/src/snapshots/import_no_named_default.snap +++ b/crates/oxc_linter/src/snapshots/import_no_named_default.snap @@ -21,3 +21,143 @@ source: crates/oxc_linter/src/tester.rs · ───────── ╰──── help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named, bar} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named, bar,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named, bar} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named, bar,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:8] + 1 │ import{default as named}from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named}from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:8] + 1 │ import{default as named} from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:8] + 1 │ import{default as named,}from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:19] + 1 │ import/*comment*/{default as named}from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:20] + 1 │ import /*comment*/{default as named}from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:8] + 1 │ import{default as named}/*comment*/from"foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:23] + 1 │ import defaultExport,{default as named}from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named} from "foo" with {type: "json"}; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:24] + 1 │ import defaultExport, {default as named} from "foo" with {type: "json"} + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:9] + 1 │ import {default as named1, default as named2,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports. + + ⚠ eslint-plugin-import(no-named-default): Replace default import with named import. + ╭─[no_named_default.tsx:1:28] + 1 │ import {default as named1, default as named2,} from "foo"; + · ─────── + ╰──── + help: Forbid named default exports.