Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use globset::GlobBuilder;
use cow_utils::CowUtils as _;
use lazy_regex::Regex;
use oxc_ast::{
AstKind,
Expand Down Expand Up @@ -869,22 +869,20 @@ impl RestrictedPattern {
None => (false, raw_pat.as_str()),
};

// roughly based on https://github.com/BurntSushi/ripgrep/blob/6dfaec03e830892e787686917509c17860456db1/crates/ignore/src/gitignore.rs#L436-L516
let mut pat = pat.to_string();

if !pat.starts_with('/') && !pat.chars().any(|c| c == '/') && (!pat.starts_with("**")) {
pat = format!("**/{pat}");
}
// roughly based on https://github.com/BurntSushi/ripgrep/blob/6dfaec03/crates/ignore/src/gitignore.rs#L436-L516
let pat = if pat.contains('/') {
Cow::Borrowed(pat)
} else {
Cow::Owned(format!("**/{pat}"))
};

let Ok(glob) = GlobBuilder::new(&pat)
.case_insensitive(case_insensitive)
.build()
.map(|g| g.compile_matcher())
else {
continue;
let (pat, name) = if case_insensitive {
(pat.cow_to_ascii_lowercase(), name.cow_to_ascii_lowercase())
} else {
(pat, name.into())
};

if glob.is_match(name) {
if fast_glob::glob_match(pat.as_ref(), name.as_ref()) {
decision = if negated { GlobResult::Whitelist } else { GlobResult::Found };
}
}
Expand Down
Loading