From b5761d8caba586807e719adf8d6c5546126ab51b Mon Sep 17 00:00:00 2001 From: XantreGodlike Date: Thu, 11 Jan 2024 14:49:49 +0100 Subject: [PATCH] added tests with default and named in the same moment --- .../fixtures/import/named-and-default-export.js | 3 +++ .../rules/import/no_named_as_default_member.rs | 3 +++ .../src/snapshots/no_named_as_default_member.snap | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 crates/oxc_linter/fixtures/import/named-and-default-export.js diff --git a/crates/oxc_linter/fixtures/import/named-and-default-export.js b/crates/oxc_linter/fixtures/import/named-and-default-export.js new file mode 100644 index 00000000000000..92356e1a899ca3 --- /dev/null +++ b/crates/oxc_linter/fixtures/import/named-and-default-export.js @@ -0,0 +1,3 @@ +export default {}; + +export const foo = 10 diff --git a/crates/oxc_linter/src/rules/import/no_named_as_default_member.rs b/crates/oxc_linter/src/rules/import/no_named_as_default_member.rs index 544988db14fe2f..c05b23b96a3937 100644 --- a/crates/oxc_linter/src/rules/import/no_named_as_default_member.rs +++ b/crates/oxc_linter/src/rules/import/no_named_as_default_member.rs @@ -147,6 +147,8 @@ fn test() { r#"import baz, {a} from "./named-exports""#, r#"import baz from "./named-exports"; const jjj = bar.jjj"#, r#"import {a} from "./named-exports"; const baz = a.baz"#, + r#"import baz from "./default_export_default_property"; const d = baz.default;"#, + r#"import baz, {foo} from "./named-and-default-export"; const d = baz.default;"#, ]; let fail = vec![ @@ -154,6 +156,7 @@ fn test() { r#"import baz from "./named-exports"; const a = baz["a"];"#, r#"import baz from "./named-exports"; baz.a();"#, r#"import baz, { bar } from "./named-exports"; const {a} = baz"#, + r#"import baz from "./named-and-default-export"; const {foo: _foo} = baz"#, ]; Tester::new_without_config(NoNamedAsDefaultMember::NAME, pass, fail) diff --git a/crates/oxc_linter/src/snapshots/no_named_as_default_member.snap b/crates/oxc_linter/src/snapshots/no_named_as_default_member.snap index c006b377a00de4..9c9b6d8f74b727 100644 --- a/crates/oxc_linter/src/snapshots/no_named_as_default_member.snap +++ b/crates/oxc_linter/src/snapshots/no_named_as_default_member.snap @@ -3,32 +3,39 @@ source: crates/oxc_linter/src/tester.rs assertion_line: 154 expression: no_named_as_default_member --- - ⚠ eslint-plugin-import(no-named-as-default-member): `"baz"` also has a named export `"a"` + ⚠ eslint-plugin-import(no-named-as-default-member): "baz" also has a named export "a" ╭─[index.js:1:1] 1 │ import baz from "./named-exports"; const a = baz.a; · ───── ╰──── help: Check if you meant to write `import {a} from "./named-exports"` - ⚠ eslint-plugin-import(no-named-as-default-member): `"baz"` also has a named export `"a"` + ⚠ eslint-plugin-import(no-named-as-default-member): "baz" also has a named export "a" ╭─[index.js:1:1] 1 │ import baz from "./named-exports"; const a = baz["a"]; · ──────── ╰──── help: Check if you meant to write `import {a} from "./named-exports"` - ⚠ eslint-plugin-import(no-named-as-default-member): `"baz"` also has a named export `"a"` + ⚠ eslint-plugin-import(no-named-as-default-member): "baz" also has a named export "a" ╭─[index.js:1:1] 1 │ import baz from "./named-exports"; baz.a(); · ───── ╰──── help: Check if you meant to write `import {a} from "./named-exports"` - ⚠ eslint-plugin-import(no-named-as-default-member): `"baz"` also has a named export `"a"` + ⚠ eslint-plugin-import(no-named-as-default-member): "baz" also has a named export "a" ╭─[index.js:1:1] 1 │ import baz, { bar } from "./named-exports"; const {a} = baz · ───────── ╰──── help: Check if you meant to write `import {a} from "./named-exports"` + ⚠ eslint-plugin-import(no-named-as-default-member): "baz" also has a named export "foo" + ╭─[index.js:1:1] + 1 │ import baz from "./named-and-default-export"; const {foo: _foo} = baz + · ───────────────── + ╰──── + help: Check if you meant to write `import {foo} from "./named-and-default-export"` +