Skip to content

Commit

Permalink
fix(matcher): fix wrongly ignored paths (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki authored Nov 23, 2023
1 parent a69a094 commit f32bb9e
Showing 1 changed file with 28 additions and 1 deletion.
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

0 comments on commit f32bb9e

Please sign in to comment.