mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 05:04:48 +00:00
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.
This commit is contained in:
parent
f4385866f8
commit
9c1ab39e19
4 changed files with 215 additions and 111 deletions
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue