From 33e4842a8ae3b4cc1814219887958944fbb707ba Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 26 Dec 2024 18:22:39 +0100 Subject: [PATCH] fix(linter): rule no-restricted-imports: improve diagnostics --- .../src/rules/eslint/no_restricted_imports.rs | 18 ++++++++++++++++++ .../eslint_no_restricted_imports.snap | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs index cc96b4f1a66bb..374fbc6429c73 100644 --- a/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs @@ -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(), @@ -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, diff --git a/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap b/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap index 7b9543a17bebf..bb9eb7a617130 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap @@ -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] 1 │ import * 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] 1 │ import * as AllowedObject from "foo/bar"; · ─────────