diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-06-10 23:29:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 23:29:48 +0200 |
commit | e4e332abbbe0dbdb44305a261f9965ba89e7767b (patch) | |
tree | 6bdbeb2c6d1039adf34f7366e467e105e91ab63d /cli/fmt.rs | |
parent | e53a1b14968099df06624a4dc4d4ab810d1ce443 (diff) |
feat(lint): use default globs, upgrade to v0.1.9 (#6222)
This commit:
* added default file globs so "deno lint" can be run
without arguments (just like "deno fmt")
* added test for globs in "deno lint"
* upgrade "deno_lint" crate to v0.1.9
Diffstat (limited to 'cli/fmt.rs')
-rw-r--r-- | cli/fmt.rs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs index 0d7a909bc..229039606 100644 --- a/cli/fmt.rs +++ b/cli/fmt.rs @@ -34,23 +34,8 @@ pub async fn format(args: Vec<String>, check: bool) -> Result<(), ErrBox> { return format_stdin(check); } - let mut target_files: Vec<PathBuf> = vec![]; + let target_files = collect_files(args)?; - if args.is_empty() { - target_files.extend(files_in_subtree( - std::env::current_dir().unwrap(), - is_supported, - )); - } else { - for arg in args { - let p = PathBuf::from(arg); - if p.is_dir() { - target_files.extend(files_in_subtree(p, is_supported)); - } else { - target_files.push(p); - }; - } - } let config = get_config(); if check { check_source_files(config, target_files).await @@ -222,6 +207,26 @@ fn is_supported(path: &Path) -> bool { } } +pub fn collect_files(files: Vec<String>) -> Result<Vec<PathBuf>, ErrBox> { + let mut target_files: Vec<PathBuf> = vec![]; + + if files.is_empty() { + target_files + .extend(files_in_subtree(std::env::current_dir()?, is_supported)); + } else { + for arg in files { + let p = PathBuf::from(arg); + if p.is_dir() { + target_files.extend(files_in_subtree(p, is_supported)); + } else { + target_files.push(p); + }; + } + } + + Ok(target_files) +} + fn get_config() -> dprint::configuration::Configuration { use dprint::configuration::*; ConfigurationBuilder::new().deno().build() |