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

refactor(biome_fs): make paths absolute to correctly match against globs #5017

Merged
merged 2 commits into from
Feb 13, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
pnpm --filter @biomejs/js-api run test:ci
e2e-tests:
name: end-to-end tests
name: End-to-end tests
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ insta = "1.42.1"
natord = "1.0.9"
oxc_resolver = "4.0"
papaya = "0.1.8"
path-absolutize = { version = "3.1.1", optional = false, features = ["use_unix_paths_on_wasm"] }
proc-macro-error2 = { version = "2.0.1", default-features = false }
proc-macro2 = "1.0.86"
quickcheck = "1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bpaf = { workspace = true, features = ["bright-color"] }
camino = { workspace = true }
crossbeam = { workspace = true }
dashmap = { workspace = true }
path-absolutize = { version = "3.1.1", optional = false, features = ["use_unix_paths_on_wasm"] }
path-absolutize = { workspace = true }
quick-junit = "0.5.1"
rayon = { workspace = true }
regex = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::{
env::current_dir,
ffi::OsString,
panic::catch_unwind,
path::PathBuf,
sync::atomic::{AtomicUsize, Ordering},
thread,
time::{Duration, Instant},
Expand Down Expand Up @@ -101,7 +100,7 @@ pub(crate) fn traverse(
// contains are properly closed once the traversal finishes
let (elapsed, evaluated_paths) = traverse_inputs(
fs,
inputs,
&inputs,
&TraversalOptions {
fs,
workspace,
Expand Down Expand Up @@ -159,15 +158,15 @@ pub(crate) fn traverse(
/// run it to completion, returning the duration of the process and the evaluated paths
fn traverse_inputs(
fs: &dyn FileSystem,
inputs: Vec<OsString>,
inputs: &[OsString],
ctx: &TraversalOptions,
) -> (Duration, BTreeSet<BiomePath>) {
let start = Instant::now();
fs.traversal(Box::new(move |scope: &dyn TraversalScope| {
for input in inputs {
scope.evaluate(
ctx,
Utf8PathBuf::from_path_buf(PathBuf::from(input)).expect("Valid UTF-8 path"),
Utf8PathBuf::from_path_buf(input.into()).expect("Valid UTF-8 path"),
);
}
}));
Expand Down
1 change: 1 addition & 0 deletions crates/biome_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enumflags2 = { workspace = true, features = ["serde"] }
oxc_resolver = { workspace = true }
papaya = { workspace = true }
parking_lot = { version = "0.12.3", features = ["arc_lock"] }
path-absolutize = { workspace = true }
rayon = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
Expand Down
14 changes: 14 additions & 0 deletions crates/biome_fs/src/fs/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
use biome_diagnostics::{DiagnosticExt, Error, IoError, Severity};
use camino::{Utf8DirEntry, Utf8Path, Utf8PathBuf};
use oxc_resolver::{FsResolution, ResolveError, ResolveOptions, Resolver};
use path_absolutize::Absolutize;
use rayon::{scope, Scope};
use std::env::temp_dir;
use std::fs::FileType;
Expand Down Expand Up @@ -235,6 +236,17 @@ impl<'scope> OsTraversalScope<'scope> {

impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> {
fn evaluate(&self, ctx: &'scope dyn TraversalContext, path: Utf8PathBuf) {
// Path must be absolute in order to properly normalize them before matching against globs.
//
// FIXME: This code should be moved to the `traverse_inputs` function in `biome_cli/src/traverse.rs`.
// Unfortunately moving this code to the `traverse_inputs` function makes many tests fail.
// The issue is coming from some bugs in our test infra.
// See https://github.com/biomejs/biome/pull/5017
let path = match std::path::Path::new(&path).absolutize() {
Ok(std::borrow::Cow::Owned(absolutized)) => Utf8PathBuf::from_path_buf(absolutized)
.expect("Absolute path must be correctly parsed"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this panic won't bite us

_ => path,
};
let file_type = match path.metadata() {
Ok(meta) => meta.file_type(),
Err(err) => {
Expand Down Expand Up @@ -511,6 +523,8 @@ impl TemporaryFs {
/// Creates a file under the working directory
pub fn create_file(&mut self, name: &str, content: &str) {
let path = self.working_directory.join(name);
std::fs::create_dir_all(path.parent().expect("parent dir exists."))
.expect("Temporary directory to exist and being writable");
std::fs::write(path.as_std_path(), content)
.expect("Temporary directory to exist and being writable");
self.files.push((path, content.to_string()));
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/relative-apth-ignore-file/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": { "includes": ["**", "!file.js"] },
"linter": { "rules": { "suspicious": { "noDebugger": "error" } } }
}
1 change: 1 addition & 0 deletions e2e-tests/relative-apth-ignore-file/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger;
3 changes: 3 additions & 0 deletions e2e-tests/relative-apth-ignore-file/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -eu

cargo run --bin biome -- lint .
Loading