summaryrefslogtreecommitdiff
path: root/cli/tools/lint.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-12-07 13:10:10 -0500
committerGitHub <noreply@github.com>2022-12-07 13:10:10 -0500
commit9c1ab39e19073501618947ffa370ba59b04ec6cc (patch)
treeba729bae7d261bf38ede4179c98fb5e17928b8ea /cli/tools/lint.rs
parentf4385866f89e0abd3f5f1b0281abf00f1c562be9 (diff)
feat: ignore `node_modules` and `.git` folders when collecting files everywhere (#16862)
We currently only do this for fmt. This makes it so they're excluded by default, but you can still opt into these directories by explicitly specifying them.
Diffstat (limited to 'cli/tools/lint.rs')
-rw-r--r--cli/tools/lint.rs54
1 files changed, 31 insertions, 23 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index 2f7cd5111..1b2487e4c 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -14,7 +14,7 @@ use crate::proc_state::ProcState;
use crate::tools::fmt::run_parallelized;
use crate::util::file_watcher;
use crate::util::file_watcher::ResolutionResult;
-use crate::util::fs::collect_files;
+use crate::util::fs::FileCollector;
use crate::util::path::is_supported_ext;
use crate::util::path::specifier_to_file_path;
use deno_ast::MediaType;
@@ -143,19 +143,17 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let resolver = |changed: Option<Vec<PathBuf>>| {
let files_changed = changed.is_some();
let result =
- collect_files(&include_files, &exclude_files, is_supported_ext).map(
- |files| {
- if let Some(paths) = changed {
- files
- .iter()
- .any(|path| paths.contains(path))
- .then_some(files)
- .unwrap_or_else(|| [].to_vec())
- } else {
- files
- }
- },
- );
+ collect_lint_files(&include_files, &exclude_files).map(|files| {
+ if let Some(paths) = changed {
+ files
+ .iter()
+ .any(|path| paths.contains(path))
+ .then_some(files)
+ .unwrap_or_else(|| [].to_vec())
+ } else {
+ files
+ }
+ });
let paths_to_watch = include_files.clone();
@@ -251,15 +249,14 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
);
reporter_lock.lock().unwrap().close(1);
} else {
- let target_files =
- collect_files(&include_files, &exclude_files, is_supported_ext)
- .and_then(|files| {
- if files.is_empty() {
- Err(generic_error("No target files found."))
- } else {
- Ok(files)
- }
- })?;
+ let target_files = collect_lint_files(&include_files, &exclude_files)
+ .and_then(|files| {
+ if files.is_empty() {
+ Err(generic_error("No target files found."))
+ } else {
+ Ok(files)
+ }
+ })?;
debug!("Found {} files", target_files.len());
operation(target_files).await?;
};
@@ -272,6 +269,17 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
Ok(())
}
+fn collect_lint_files(
+ include_files: &[PathBuf],
+ exclude_files: &[PathBuf],
+) -> Result<Vec<PathBuf>, AnyError> {
+ FileCollector::new(is_supported_ext)
+ .ignore_git_folder()
+ .ignore_node_modules()
+ .add_ignore_paths(exclude_files)
+ .collect_files(include_files)
+}
+
pub fn print_rules_list(json: bool) {
let lint_rules = rules::get_recommended_rules();