Skip to content

Commit 7c54ea1

Browse files
committedApr 4, 2025·
fix(linter): rule no-restricted-imports allow combination of paths and patterns (#10224)
related #10194
1 parent 6174129 commit 7c54ea1

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed
 

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

+23-20
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,9 @@ impl Rule for NoRestrictedImports {
910910
Value::Object(obj) => {
911911
if let Some(paths_value) = obj.get("paths") {
912912
add_configuration_path_from_object(&mut paths, paths_value);
913-
} else if let Some(patterns_value) = obj.get("patterns") {
913+
}
914+
915+
if let Some(patterns_value) = obj.get("patterns") {
914916
add_configuration_patterns_from_object(
915917
&mut patterns,
916918
patterns_value,
@@ -931,7 +933,8 @@ impl Rule for NoRestrictedImports {
931933
Value::Object(obj) => {
932934
if let Some(paths_value) = obj.get("paths") {
933935
add_configuration_path_from_object(&mut paths, paths_value);
934-
} else if let Some(patterns_value) = obj.get("patterns") {
936+
}
937+
if let Some(patterns_value) = obj.get("patterns") {
935938
add_configuration_patterns_from_object(&mut patterns, patterns_value);
936939
} else if let Ok(path) =
937940
serde_json::from_value::<RestrictedPath>(serde_json::Value::Object(obj.clone()))
@@ -3017,24 +3020,24 @@ fn test() {
30173020
"export { foo } from 'import1';",
30183021
Some(serde_json::json!([{ "paths": ["import1", "import2"] }])),
30193022
),
3020-
// (
3021-
// "import foo from 'import1/private/foo';",
3022-
// Some(serde_json::json!([
3023-
// {
3024-
// "paths": ["import1", "import2"],
3025-
// "patterns": ["import1/private/*", "import2/*", "!import2/good"],
3026-
// },
3027-
// ])),
3028-
// ),
3029-
// (
3030-
// "export { foo } from 'import1/private/foo';",
3031-
// Some(serde_json::json!([
3032-
// {
3033-
// "paths": ["import1", "import2"],
3034-
// "patterns": ["import1/private/*", "import2/*", "!import2/good"],
3035-
// },
3036-
// ])),
3037-
// ),
3023+
(
3024+
"import foo from 'import1/private/foo';",
3025+
Some(serde_json::json!([
3026+
{
3027+
"paths": ["import1", "import2"],
3028+
"patterns": ["import1/private/*", "import2/*", "!import2/good"],
3029+
},
3030+
])),
3031+
),
3032+
(
3033+
"export { foo } from 'import1/private/foo';",
3034+
Some(serde_json::json!([
3035+
{
3036+
"paths": ["import1", "import2"],
3037+
"patterns": ["import1/private/*", "import2/*", "!import2/good"],
3038+
},
3039+
])),
3040+
),
30383041
(
30393042
"import foo from 'import-foo';",
30403043
Some(serde_json::json!([

‎crates/oxc_linter/src/snapshots/eslint_no_restricted_imports.snap

+12
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,18 @@ source: crates/oxc_linter/src/tester.rs
817817
· ──────────────────────────────
818818
╰────
819819

820+
eslint(no-restricted-imports): 'import1/private/foo' import is restricted from being used by a pattern.
821+
╭─[no_restricted_imports.tsx:1:1]
822+
1import foo from 'import1/private/foo';
823+
· ──────────────────────────────────────
824+
╰────
825+
826+
eslint(no-restricted-imports): 'import1/private/foo' import is restricted from being used by a pattern.
827+
╭─[no_restricted_imports.tsx:1:1]
828+
1export { foo } from 'import1/private/foo';
829+
· ──────────────────────────────────────────
830+
╰────
831+
820832
eslint(no-restricted-imports): 'import-foo' import is restricted from being used.
821833
╭─[no_restricted_imports.tsx:1:1]
822834
1import foo from 'import-foo';

0 commit comments

Comments
 (0)
Please sign in to comment.