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(glob): correctly handle relative patterns #2620

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- Relative glob patterns are now correctly handled ([#2421](https://github.com/biomejs/biome/issues/2421)).

Biome relies on an internal fork of the [glob crate](https://crates.io/crates/glob).
This crate converts relative glob patterns into recursive glob patterns.
This means that `./file' is equivalent to `./**/file'.

This is surprising behavior and has been reported as a bug by our users.
Biome no longer converts relative glob patterns to recursive glob patterns.

Contributed by @Conaclos

### Configuration

### Editors
Expand Down
8 changes: 3 additions & 5 deletions crates/biome_service/src/matcher/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ impl Pattern {
// eg. "./test" or ".\test"
let is_relative = matches!(chars.get(..2), Some(['.', sep]) if path::is_separator(*sep));
if is_relative {
// If a pattern starts with a relative prefix, strip it from the
// pattern and replace it with a "**" sequence
// If a pattern starts with a relative prefix, strip it from the pattern
i += 2;
tokens.push(AnyRecursiveSequence);
} else {
// A pattern is absolute if it starts with a path separator, eg. "/home" or "\\?\C:\Users"
let mut is_absolute = chars.first().map_or(false, |c| path::is_separator(*c));
Expand Down Expand Up @@ -862,11 +860,11 @@ mod test {

#[test]
fn test_pattern_relative() {
assert!(Pattern::new("./b").unwrap().matches_path(Path::new("a/b")));
assert!(!Pattern::new("./b").unwrap().matches_path(Path::new("a/b")));
assert!(Pattern::new("b").unwrap().matches_path(Path::new("a/b")));

if cfg!(windows) {
assert!(Pattern::new(".\\b")
assert!(!Pattern::new(".\\b")
.unwrap()
.matches_path(Path::new("a\\b")));
assert!(Pattern::new("b").unwrap().matches_path(Path::new("a\\b")));
Expand Down
Loading