Skip to content

Commit

Permalink
error message improved
Browse files Browse the repository at this point in the history
  • Loading branch information
XantreDev committed Jan 22, 2024
1 parent f692bb0 commit 817e621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions crates/oxc_linter/src/rules/import/no_named_as_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use oxc_syntax::module_record::ImportImportName;
use crate::{context::LintContext, rule::Rule};

#[derive(Debug, Error, Diagnostic)]
#[error("eslint-plugin-import(no-named-as-default): Using exported name {1:?} as identifier for default export.")]
#[error("eslint-plugin-import(no-named-as-default): Module {2:?} has named export {1:?}. Using default import as {1:?} can be confusing")]
#[diagnostic(severity(warning), help("Use another name for default import to avoid confusion"))]
struct NoNamedAsDefaultDiagnostic(#[label] pub Span, String);
struct NoNamedAsDefaultDiagnostic(#[label] pub Span, String, String);

/// <https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default-member.md>
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -63,7 +63,11 @@ impl Rule for NoNamedAsDefault {
};

if remote_module_record_ref.exported_bindings.contains_key(import_name) {
ctx.diagnostic(NoNamedAsDefaultDiagnostic(import_span, import_name.to_string()));
ctx.diagnostic(NoNamedAsDefaultDiagnostic(
import_span,
import_name.to_string(),
import_entry.module_request.name().to_string(),
));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/snapshots/no_named_as_default.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ source: crates/oxc_linter/src/tester.rs
assertion_line: 143
expression: no_named_as_default
---
eslint-plugin-import(no-named-as-default): Using exported name "foo" as identifier for default export.
eslint-plugin-import(no-named-as-default): Module "./bar" has named export "foo". Using default import as "foo" can be confusing
╭─[index.js:1:1]
1import foo from "./bar";
· ───
╰────
help: Use another name for default import to avoid confusion

eslint-plugin-import(no-named-as-default): Using exported name "foo" as identifier for default export.
eslint-plugin-import(no-named-as-default): Module "./bar" has named export "foo". Using default import as "foo" can be confusing
╭─[index.js:1:1]
1import foo, { foo as bar } from "./bar";
· ───
╰────
help: Use another name for default import to avoid confusion

eslint-plugin-import(no-named-as-default): Using exported name "foo" as identifier for default export.
eslint-plugin-import(no-named-as-default): Module "./export-default-string-and-named" has named export "foo". Using default import as "foo" can be confusing
╭─[index.js:1:1]
1import foo from "./export-default-string-and-named"
· ───
╰────
help: Use another name for default import to avoid confusion

eslint-plugin-import(no-named-as-default): Using exported name "foo" as identifier for default export.
eslint-plugin-import(no-named-as-default): Module "./export-default-string-and-named" has named export "foo". Using default import as "foo" can be confusing
╭─[index.js:1:1]
1import foo, { foo as bar } from "./export-default-string-and-named"
· ───
Expand Down

0 comments on commit 817e621

Please sign in to comment.