From 4e05e66d7cb3aa8731e6cb57c0f09ca2faec1f3d Mon Sep 17 00:00:00 2001 From: "Alexander S." Date: Fri, 10 Jan 2025 03:03:43 +0100 Subject: [PATCH] refactor(linter): remove glob for windows (#8390) The current implementations does not work. Under linux it tells me 0 files, under windows: ``` > oxc-vscode@0.15.5 lint C:\dev\oxc\editors\vscode > npx oxlint --config=oxlint.json --tsconfig=tsconfig.json client/*.js Finished in 5ms on 5 files with 101 rules using 24 threads. Found 0 warnings and 0 errors. ``` I do not think this glob is needed. we are using `ignore` in our `Walker`, which should already covering the use case. --------- Co-authored-by: Sysix Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- Cargo.lock | 7 ------- Cargo.toml | 1 - apps/oxlint/Cargo.toml | 1 - apps/oxlint/src/command/lint.rs | 24 +----------------------- apps/oxlint/src/command/mod.rs | 25 ------------------------- apps/oxlint/src/lint.rs | 4 ---- 6 files changed, 1 insertion(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59aeb93a12208..7016a372ad4b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -709,12 +709,6 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" -[[package]] -name = "glob" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" - [[package]] name = "globset" version = "0.4.15" @@ -2134,7 +2128,6 @@ name = "oxlint" version = "0.15.5" dependencies = [ "bpaf", - "glob", "ignore", "jemallocator", "mimalloc", diff --git a/Cargo.toml b/Cargo.toml index a6882d92f8cb3..222deabb4ddcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,7 +150,6 @@ env_logger = { version = "0.11.5", default-features = false } fast-glob = "0.4.0" flate2 = "1.0.35" futures = "0.3.31" -glob = "0.3.1" globset = "0.4.15" handlebars = "6.2.0" hashbrown = "0.15.2" diff --git a/apps/oxlint/Cargo.toml b/apps/oxlint/Cargo.toml index 676ebf59fe45a..e49afd6666293 100644 --- a/apps/oxlint/Cargo.toml +++ b/apps/oxlint/Cargo.toml @@ -36,7 +36,6 @@ oxc_linter = { workspace = true } oxc_span = { workspace = true } bpaf = { workspace = true, features = ["autocomplete", "bright-color", "derive"] } -glob = { workspace = true } ignore = { workspace = true, features = ["simd-accel"] } miette = { workspace = true } rayon = { workspace = true } diff --git a/apps/oxlint/src/command/lint.rs b/apps/oxlint/src/command/lint.rs index 68ba5eb017891..a02ca8f609db0 100644 --- a/apps/oxlint/src/command/lint.rs +++ b/apps/oxlint/src/command/lint.rs @@ -4,7 +4,6 @@ use bpaf::Bpaf; use oxc_linter::{AllowWarnDeny, FixKind, LintPlugins}; use super::{ - expand_glob, ignore::{ignore_options, IgnoreOptions}, misc_options, validate_paths, MiscOptions, PATHS_ERROR_MESSAGE, VERSION, }; @@ -41,7 +40,7 @@ pub struct LintCommand { pub misc_options: MiscOptions, /// Single file, single path or list of paths - #[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE), map(expand_glob))] + #[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE))] pub paths: Vec, } @@ -480,27 +479,6 @@ mod lint_options { assert_eq!(options.paths, [file_foo, file_bar, file_baz]); } - #[cfg(target_os = "windows")] - #[test] - #[allow(clippy::similar_names)] - fn wildcard_expansion() { - let temp_dir = tempfile::tempdir().expect("Could not create a temp dir"); - let file_foo = temp_dir.path().join("foo.js"); - File::create(&file_foo).expect("Could not create foo.js temp file"); - let file_bar = temp_dir.path().join("bar.js"); - File::create(&file_bar).expect("Could not create bar.js temp file"); - let file_baz = temp_dir.path().join("baz"); - File::create(&file_baz).expect("Could not create baz temp file"); - - let js_files_wildcard = temp_dir.path().join("*.js"); - let options = get_lint_options( - js_files_wildcard.to_str().expect("could not get js files wildcard path"), - ); - assert!(options.paths.contains(&file_foo)); - assert!(options.paths.contains(&file_bar)); - assert!(!options.paths.contains(&file_baz)); - } - #[test] fn no_parent_path() { match lint_command().run_inner(&["../parent_dir"]) { diff --git a/apps/oxlint/src/command/mod.rs b/apps/oxlint/src/command/mod.rs index 1252a2e187578..a2e1733f8211f 100644 --- a/apps/oxlint/src/command/mod.rs +++ b/apps/oxlint/src/command/mod.rs @@ -43,31 +43,6 @@ fn validate_paths(paths: &Vec) -> bool { const PATHS_ERROR_MESSAGE: &str = "PATH must not contain \"..\""; -#[cfg(target_os = "windows")] -#[allow(clippy::needless_pass_by_value)] -fn expand_glob(paths: Vec) -> Vec { - let match_options = glob::MatchOptions { - case_sensitive: true, - require_literal_separator: false, - require_literal_leading_dot: false, - }; - - paths - .iter() - .filter_map(|path| path.to_str()) - .filter_map(|path| glob::glob_with(path, match_options).ok()) - .flatten() - .filter_map(Result::ok) - .collect() -} - -#[cfg(not(target_os = "windows"))] -#[allow(clippy::needless_pass_by_value)] -fn expand_glob(paths: Vec) -> Vec { - // no-op on any os other than windows, since they expand globs - paths -} - #[cfg(test)] mod misc_options { use super::{lint::lint_command, MiscOptions}; diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 48091425846a5..8ea5c15f7bbc6 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -365,8 +365,6 @@ mod test { assert_eq!(result.number_of_errors, 0); } - // exclude because we are working with Glob, which only supports the current working directory - #[cfg(all(test, not(target_os = "windows")))] #[test] fn cwd() { let args = &["debugger.js"]; @@ -395,8 +393,6 @@ mod test { assert_eq!(result.number_of_errors, 0); } - // ToDo: lints all files under windows - #[cfg(all(test, not(target_os = "windows")))] #[test] fn wrong_extension() { let args = &["foo.asdf"];