From 724f1e33b07c4cd3d3a1f2cc6859ab837eda6b85 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 24 Nov 2023 03:48:42 +0900 Subject: [PATCH] fix wrongly ignored paths --- crates/biome_service/src/matcher/mod.rs | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/biome_service/src/matcher/mod.rs b/crates/biome_service/src/matcher/mod.rs index 28e6df7b32c1..5243b3fc3d7e 100644 --- a/crates/biome_service/src/matcher/mod.rs +++ b/crates/biome_service/src/matcher/mod.rs @@ -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 { @@ -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";