Skip to content

Commit a08c2d3

Browse files
committed
fix(linter/no-restricted-imports): apply regex pattern checks to side-effect imports
fixes #19956
1 parent 7f3d735 commit a08c2d3

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,15 @@ impl NoRestrictedImports {
10411041
}
10421042
GlobResult::None => {}
10431043
}
1044+
1045+
if pattern.get_regex_result(source) {
1046+
ctx.diagnostic(get_diagnostic_from_import_name_result_pattern(
1047+
spans[0],
1048+
source,
1049+
&ImportNameResult::GeneralDisallowed,
1050+
pattern,
1051+
));
1052+
}
10441053
}
10451054
if !whitelist_found && let Some(err) = err {
10461055
ctx.diagnostic(err);
@@ -3073,6 +3082,12 @@ fn test() {
30733082
serde_json::json!([{ "patterns": [{ "group": ["foo"], "message": "foo is forbidden, use bar instead" }] }]),
30743083
),
30753084
),
3085+
(
3086+
r"import 'foo'",
3087+
Some(
3088+
serde_json::json!([{ "patterns": [{ "regex": "foo", "message": "foo is forbidden, use bar instead" }] }]),
3089+
),
3090+
),
30763091
];
30773092

30783093
let fail_typescript = vec![

crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,13 @@ source: crates/oxc_linter/src/tester.rs
823823
╰────
824824
help: foo is forbidden, use bar instead
825825

826+
eslint(no-restricted-imports): 'foo' import is restricted from being used by a pattern.
827+
╭─[no_restricted_imports.tsx:1:1]
828+
1import 'foo'
829+
· ────────────
830+
╰────
831+
help: foo is forbidden, use bar instead
832+
826833
eslint(no-restricted-imports): 'import1' import is restricted from being used.
827834
╭─[no_restricted_imports.tsx:1:1]
828835
1import foo from 'import1';

0 commit comments

Comments
 (0)