Skip to content

Commit

Permalink
fix(linter): rule no-restricted-imports: improve diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Dec 26, 2024
1 parent a029467 commit 33e4842
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,15 @@ impl NoRestrictedImports {
source,
allowed_import_names.join(", ").as_str(),
)
} else if let Some(allow_import_name_pattern) =
&pattern.allow_import_name_pattern
{
diagnostic_everything_with_allowed_import_name_pattern(
entry.module_request.span(),
pattern.message.clone(),
source,
allow_import_name_pattern.as_str(),
)
} else {
diagnostic_pattern(
entry.module_request.span(),
Expand Down Expand Up @@ -894,6 +903,15 @@ impl NoRestrictedImports {
import_names.join(", ").as_str(),
source,
)
} else if let Some(allow_import_name_pattern) =
&pattern.allow_import_name_pattern
{
diagnostic_everything_with_allowed_import_name_pattern(
span,
pattern.message.clone(),
source,
allow_import_name_pattern.as_str(),
)
} else if let Some(allowed_import_names) = &pattern.allow_import_names {
diagnostic_everything_with_allowed_import_name(
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,13 @@ snapshot_kind: text
╰────
help: Only "AllowedObject" is allowed to be imported from "foo".

eslint(no-restricted-imports): 'foo/bar' import is restricted from being used by a pattern.
eslint(no-restricted-imports): * import is invalid because only imports that match the pattern '^Allow' from 'foo/bar' are allowed.
╭─[no_restricted_imports.tsx:1:32]
1import * as AllowedObject from "foo/bar";
· ─────────
╰────

eslint(no-restricted-imports): 'foo/bar' import is restricted from being used by a pattern.
eslint(no-restricted-imports): * import is invalid because only imports that match the pattern '^Allow' from 'foo/bar' are allowed.
╭─[no_restricted_imports.tsx:1:32]
1import * as AllowedObject from "foo/bar";
· ─────────
Expand Down

0 comments on commit 33e4842

Please sign in to comment.