From c20f60c289e947f94abb27ed1349ab87676ee6b3 Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 18 Mar 2023 18:22:46 +0800 Subject: [PATCH] feat(cli): add ignore_pattern to walker --- crates/oxc_cli/src/walk.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/oxc_cli/src/walk.rs b/crates/oxc_cli/src/walk.rs index a0bc201e6..edf292c61 100644 --- a/crates/oxc_cli/src/walk.rs +++ b/crates/oxc_cli/src/walk.rs @@ -1,6 +1,6 @@ use std::path::Path; -use ignore::{DirEntry, WalkBuilder}; +use ignore::{overrides::OverrideBuilder, DirEntry, WalkBuilder}; use oxc_ast::VALID_EXTENSIONS; use crate::LintOptions; @@ -10,6 +10,7 @@ pub struct Walk { } impl Walk { + /// # Panics #[must_use] pub fn new(options: &LintOptions) -> Self { let mut inner = WalkBuilder::new(&options.paths[0]); @@ -22,6 +23,16 @@ impl Walk { if !options.no_ignore { inner.add_custom_ignore_filename(&options.ignore_path); + + if !options.ignore_pattern.is_empty() { + let mut override_builder = OverrideBuilder::new(Path::new("/")); + for pattern in &options.ignore_pattern { + // TODO: check this command arg parser + override_builder.add(pattern).unwrap(); + } + let r#override = override_builder.build().unwrap(); + inner.overrides(r#override); + } } // Turning off `follow_links` because: // * following symlinks is a really slow syscall