Skip to content

Commit

Permalink
fix(linter): rule: no-restricted-imports support option patterns with…
Browse files Browse the repository at this point in the history
… group key
  • Loading branch information
Sysix committed Dec 20, 2024
1 parent 5f8d010 commit 5a0036c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl NoRestrictedImports {
continue;
}

let mut builder = GitignoreBuilder::new("/");
let mut builder = GitignoreBuilder::new("");
let _ = builder.case_insensitive(!pattern.case_sensitive.unwrap_or(false));

for group in &pattern.group {
Expand All @@ -356,7 +356,7 @@ impl NoRestrictedImports {
let source = entry.module_request.name();
let span = entry.module_request.span();

let matched = gitignore.matched(source, true);
let matched = gitignore.matched(source, false);
// println!("{:?}", matched);

if matched.is_whitelist() {
Expand Down Expand Up @@ -840,10 +840,10 @@ fn test() {
// r#"import withPatterns from "foo/bar";"#,
// Some(serde_json::json!([{ "patterns": ["foo"] }])),
// ),
// (
// r#"import withPatterns from "foo/bar";"#,
// Some(serde_json::json!([{ "patterns": ["bar"] }])),
// ),
(
r#"import withPatterns from "foo/bar";"#,
Some(serde_json::json!([{ "patterns": ["bar"] }])),
),
(
r#"import withPatterns from "foo/baz";"#,
Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ snapshot_kind: text
╰────
help: Remove the import statement.

eslint(no-restricted-imports): 'foo/bar' import is restricted from being used.
╭─[no_restricted_imports.tsx:1:26]
1import withPatterns from "foo/bar";
· ─────────
╰────
help: Remove the import statement.

eslint(no-restricted-imports): foo is forbidden, use foo/bar instead
╭─[no_restricted_imports.tsx:1:26]
1import withPatterns from "foo/baz";
Expand Down

0 comments on commit 5a0036c

Please sign in to comment.