Skip to content

Commit

Permalink
refactor(biome_fs): make paths absolute to correctly match against globs
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Feb 13, 2025
1 parent 258e709 commit f228d10
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 7 deletions.
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
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
LINT_ERROR, PARSE_ERROR,
};
use biome_console::{markup, BufferConsole, LogLevel, MarkupBuf};
use biome_fs::{ErrorEntry, FileSystemExt, MemoryFileSystem, OsFileSystem};
use biome_fs::{ErrorEntry, FileSystemExt, MemoryFileSystem, OsFileSystem, TemporaryFs};
use bpaf::Args;
use camino::{Utf8Path, Utf8PathBuf};
use std::env::temp_dir;
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
9 changes: 9 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,12 @@ impl<'scope> OsTraversalScope<'scope> {

impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> {
fn evaluate(&self, ctx: &'scope dyn TraversalContext, path: Utf8PathBuf) {
dbg!(&path);
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"),
_ => path,
};
let file_type = match path.metadata() {
Ok(meta) => meta.file_type(),
Err(err) => {
Expand Down Expand Up @@ -511,6 +518,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("paarent 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 .

0 comments on commit f228d10

Please sign in to comment.