diff --git a/Cargo.lock b/Cargo.lock index 531d9b18ca402..b8ccdda96a7ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2271,6 +2271,7 @@ name = "oxlint" version = "0.15.8" dependencies = [ "bpaf", + "cow-utils", "ignore", "insta", "jemallocator", diff --git a/apps/oxlint/Cargo.toml b/apps/oxlint/Cargo.toml index 19bc43ea2be6a..fbe2544ec89bb 100644 --- a/apps/oxlint/Cargo.toml +++ b/apps/oxlint/Cargo.toml @@ -36,6 +36,7 @@ oxc_linter = { workspace = true } oxc_span = { workspace = true } bpaf = { workspace = true, features = ["autocomplete", "bright-color", "derive"] } +cow-utils = { workspace = true } ignore = { workspace = true, features = ["simd-accel"] } miette = { workspace = true } rayon = { workspace = true } diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 4ed57ca79c3ac..1f7649b52c5fb 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -5,6 +5,7 @@ use std::{ time::Instant, }; +use cow_utils::CowUtils; use ignore::gitignore::Gitignore; use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler}; use oxc_linter::{ @@ -209,7 +210,8 @@ impl Runner for LintRunner { } else { let path = if path.is_relative() { options.cwd().join(path) } else { path.clone() }; stdout.write_all(format!( - "The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.\n", + "The tsconfig file {:?} does not exist, Please provide a valid tsconfig file.\n", + path.to_string_lossy().cow_replace('\\', "/") ).as_bytes()).or_else(Self::check_for_writer_error).unwrap(); stdout.flush().unwrap(); diff --git a/apps/oxlint/src/tester.rs b/apps/oxlint/src/tester.rs index 6ebae30de1452..b4a252b23400f 100644 --- a/apps/oxlint/src/tester.rs +++ b/apps/oxlint/src/tester.rs @@ -3,6 +3,8 @@ use crate::cli::{lint_command, LintRunner}; #[cfg(test)] use crate::runner::Runner; #[cfg(test)] +use cow_utils::CowUtils; +#[cfg(test)] use regex::Regex; #[cfg(test)] use std::{env, path::PathBuf}; @@ -78,10 +80,8 @@ impl Tester { // do not output the current working directory, each machine has a different one let cwd_string = current_cwd.to_str().unwrap(); - #[allow(clippy::disallowed_methods)] - let cwd_string = cwd_string.replace('\\', "/"); - #[allow(clippy::disallowed_methods)] - let output_string = output_string.replace(&cwd_string, ""); + let cwd_string = cwd_string.cow_replace('\\', "/").to_string(); // for windows + let output_string = output_string.cow_replace(&cwd_string, ""); let full_args_list = multiple_args.iter().map(|args| args.join(" ")).collect::>().join(" "); @@ -90,8 +90,7 @@ impl Tester { // windows can not handle filenames with * // allow replace instead of cow_replace. It only test - #[allow(clippy::disallowed_methods)] - let snapshot_file_name = snapshot_file_name.replace('*', "_"); + let snapshot_file_name = snapshot_file_name.cow_replace('*', "_").to_string(); settings.bind(|| { insta::assert_snapshot!(snapshot_file_name, output_string); });