diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-01-08 12:18:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 17:18:42 +0000 |
commit | e212e1fc35ddae63f457f0f2a2e95154e008941f (patch) | |
tree | 6c1f553fbc529bfcab6413049af8f32ed31d1dfd /cli/tools/lint.rs | |
parent | ee45d5bf8f2e1826b2a106b030abe891cfc0b37c (diff) |
perf: skip expanding exclude globs (#21817)
We were calling `expand_glob` on our excludes, which is very expensive
and unnecessary because we can pattern match while traversing instead.
1. Doesn't expand "exclude" globs. Instead pattern matches while walking
the directory.
2. Splits up the "include" into base paths and applicable file patterns.
This causes less pattern matching to occur because we're only pattern
matching on patterns that might match and not ones in completely
unrelated directories.
Diffstat (limited to 'cli/tools/lint.rs')
-rw-r--r-- | cli/tools/lint.rs | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index 7981fec09..a91f14ad8 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -2,7 +2,6 @@ //! This module provides file linting utilities using //! [`deno_lint`](https://github.com/denoland/deno_lint). -use crate::args::FilesConfig; use crate::args::Flags; use crate::args::LintFlags; use crate::args::LintOptions; @@ -12,7 +11,9 @@ use crate::colors; use crate::factory::CliFactory; use crate::tools::fmt::run_parallelized; use crate::util::file_watcher; +use crate::util::fs::canonicalize_path; use crate::util::fs::FileCollector; +use crate::util::glob::FilePatterns; use crate::util::path::is_script_ext; use crate::util::sync::AtomicFlag; use deno_ast::MediaType; @@ -66,21 +67,26 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { let factory = CliFactory::from_flags(flags).await?; let cli_options = factory.cli_options(); let lint_options = cli_options.resolve_lint_options(lint_flags)?; - let files = - collect_lint_files(&lint_options.files).and_then(|files| { + let files = collect_lint_files(lint_options.files.clone()).and_then( + |files| { if files.is_empty() { Err(generic_error("No target files found.")) } else { Ok(files) } - })?; + }, + )?; _ = watcher_communicator.watch_paths(files.clone()); let lint_paths = if let Some(paths) = changed_paths { // lint all files on any changed (https://github.com/denoland/deno/issues/12446) files .iter() - .any(|path| paths.contains(path)) + .any(|path| { + canonicalize_path(path) + .map(|p| paths.contains(&p)) + .unwrap_or(false) + }) .then_some(files) .unwrap_or_else(|| [].to_vec()) } else { @@ -109,13 +115,14 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { reporter_lock.lock().unwrap().close(1); success } else { - let target_files = collect_lint_files(files).and_then(|files| { - if files.is_empty() { - Err(generic_error("No target files found.")) - } else { - Ok(files) - } - })?; + let target_files = + collect_lint_files(files.clone()).and_then(|files| { + if files.is_empty() { + Err(generic_error("No target files found.")) + } else { + Ok(files) + } + })?; debug!("Found {} files", target_files.len()); lint_files(factory, lint_options, target_files).await? }; @@ -191,13 +198,12 @@ async fn lint_files( Ok(!has_error.is_raised()) } -fn collect_lint_files(files: &FilesConfig) -> Result<Vec<PathBuf>, AnyError> { - FileCollector::new(is_script_ext) +fn collect_lint_files(files: FilePatterns) -> Result<Vec<PathBuf>, AnyError> { + FileCollector::new(|path, _| is_script_ext(path)) .ignore_git_folder() .ignore_node_modules() .ignore_vendor_folder() - .add_ignore_paths(&files.exclude) - .collect_files(files.include.as_deref()) + .collect_file_patterns(files) } pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) { |