diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2020-07-30 21:39:08 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 12:09:08 -0400 |
commit | 0da4779b178a0c97925c1ef5589d0f24a37f4501 (patch) | |
tree | 0be0e95c53ec8f2f83b05a8c60a5fbbf56fd3689 /cli/fmt.rs | |
parent | 95597fc6e2ed9975c26eae77ba68ae42ca2c331a (diff) |
feat(unstable): add "--ignore" flag to deno fmt (#6890)
Diffstat (limited to 'cli/fmt.rs')
-rw-r--r-- | cli/fmt.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs index 59239ec17..cac4e5c5f 100644 --- a/cli/fmt.rs +++ b/cli/fmt.rs @@ -27,15 +27,24 @@ const BOM_CHAR: char = '\u{FEFF}'; /// Format JavaScript/TypeScript files. /// -/// First argument supports globs, and if it is `None` +/// First argument and ignore supports globs, and if it is `None` /// then the current directory is recursively walked. -pub async fn format(args: Vec<String>, check: bool) -> Result<(), ErrBox> { +pub async fn format( + args: Vec<String>, + check: bool, + exclude: Vec<String>, +) -> Result<(), ErrBox> { if args.len() == 1 && args[0] == "-" { return format_stdin(check); } - - let target_files = collect_files(args)?; - + // 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)); + } let config = get_config(); if check { check_source_files(config, target_files).await @@ -217,9 +226,9 @@ pub fn collect_files(files: Vec<String>) -> Result<Vec<PathBuf>, ErrBox> { for arg in files { let p = PathBuf::from(arg); if p.is_dir() { - target_files.extend(files_in_subtree(p, is_supported)); + target_files.extend(files_in_subtree(p.canonicalize()?, is_supported)); } else { - target_files.push(p); + target_files.push(p.canonicalize()?); }; } } |