summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/fmt.rs52
-rw-r--r--cli/lint.rs8
2 files changed, 33 insertions, 27 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs
index a932fbc95..8f1350973 100644
--- a/cli/fmt.rs
+++ b/cli/fmt.rs
@@ -9,8 +9,6 @@
use crate::colors;
use crate::diff::diff;
-use crate::fs::canonicalize_path;
-use crate::fs::files_in_subtree;
use crate::text_encoding;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@@ -25,6 +23,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
+use walkdir::WalkDir;
const BOM_CHAR: char = '\u{FEFF}';
@@ -40,14 +39,8 @@ pub async fn format(
if args.len() == 1 && args[0].to_string_lossy() == "-" {
return format_stdin(check);
}
- // collect all files provided.
- let mut target_files = collect_files(args)?;
- if !exclude.is_empty() {
- // collect all files to be ignored
- // and retain only files that should be formatted.
- let ignore_files = collect_files(exclude)?;
- target_files.retain(|f| !ignore_files.contains(&f));
- }
+ // collect the files that are to be formatted
+ let target_files = collect_files(args, exclude)?;
let config = get_config();
if check {
check_source_files(config, target_files).await
@@ -234,22 +227,41 @@ fn is_supported(path: &Path) -> bool {
pub fn collect_files(
files: Vec<PathBuf>,
+ mut ignore: Vec<PathBuf>,
) -> Result<Vec<PathBuf>, std::io::Error> {
let mut target_files: Vec<PathBuf> = vec![];
+ // retain only the paths which exist and ignore the rest
+ ignore.retain(|i| i.exists());
+
if files.is_empty() {
- target_files.extend(files_in_subtree(
- canonicalize_path(&std::env::current_dir()?)?,
- is_supported,
- ));
+ for entry in WalkDir::new(std::env::current_dir()?)
+ .into_iter()
+ .filter_entry(|e| {
+ !ignore.iter().any(|i| {
+ e.path()
+ .canonicalize()
+ .unwrap()
+ .starts_with(i.canonicalize().unwrap())
+ })
+ })
+ {
+ let entry_clone = entry?.clone();
+ if is_supported(entry_clone.path()) {
+ target_files.push(entry_clone.path().canonicalize()?)
+ }
+ }
} else {
for file in files {
- if file.is_dir() {
- target_files
- .extend(files_in_subtree(canonicalize_path(&file)?, is_supported));
- } else {
- target_files.push(canonicalize_path(&file)?);
- };
+ for entry in WalkDir::new(file)
+ .into_iter()
+ .filter_entry(|e| !ignore.iter().any(|i| e.path().starts_with(i)))
+ {
+ let entry_clone = entry?.clone();
+ if is_supported(entry_clone.path()) {
+ target_files.push(entry_clone.into_path().canonicalize()?)
+ }
+ }
}
}
diff --git a/cli/lint.rs b/cli/lint.rs
index ff63b693c..ff156f785 100644
--- a/cli/lint.rs
+++ b/cli/lint.rs
@@ -47,13 +47,7 @@ pub async fn lint_files(
if args.len() == 1 && args[0].to_string_lossy() == "-" {
return lint_stdin(json);
}
- let mut target_files = collect_files(args)?;
- if !ignore.is_empty() {
- // collect all files to be ignored
- // and retain only files that should be linted.
- let ignore_files = collect_files(ignore)?;
- target_files.retain(|f| !ignore_files.contains(&f));
- }
+ let target_files = collect_files(args, ignore)?;
debug!("Found {} files", target_files.len());
let target_files_len = target_files.len();