Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(matcher): fix wrongly ignored paths #859

Merged
merged 1 commit into from
Nov 23, 2023
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
29 changes: 28 additions & 1 deletion crates/biome_service/src/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ impl Matcher {
// Here we cover cases where the user specifies single files inside the patterns.
// The pattern library doesn't support single files, we here we just do a check
// on contains
source_as_string.map_or(false, |source| source.contains(pattern.as_str()))
//
// Given the pattern `out`:
// - `out/index.html` -> matches
// - `out/` -> matches
// - `layout.tsx` -> does not match
// - `routes/foo.ts` -> does not match
source
.ancestors()
.any(|ancestor| ancestor.ends_with(pattern.as_str()))
};

if matches {
Expand Down Expand Up @@ -132,6 +140,25 @@ mod test {
assert!(result);
}

#[test]
fn matches_path_for_single_file_or_directory_name() {
let dir = "inv";
let valid_test_dir = "valid/";
let mut ignore = Matcher::new(MatchOptions::default());
ignore.add_pattern(dir).unwrap();
ignore.add_pattern(valid_test_dir).unwrap();

let path = env::current_dir().unwrap().join("tests").join("invalid");
let result = ignore.matches_path(path.as_path());

assert!(!result);

let path = env::current_dir().unwrap().join("tests").join("valid");
let result = ignore.matches_path(path.as_path());

assert!(result);
}

#[test]
fn matches_single_path() {
let dir = "workspace.rs";
Expand Down