summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/fmt.rs60
-rw-r--r--cli/tools/lint.rs37
2 files changed, 56 insertions, 41 deletions
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 9ac9557cd..2cc276c5b 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -81,25 +81,36 @@ pub async fn format(
let resolver = |changed: Option<Vec<PathBuf>>| {
let files_changed = changed.is_some();
- let result =
- collect_files(&include_files, &exclude_files, is_supported_ext_fmt).map(
- |files| {
- let collected_files = if let Some(paths) = changed {
- files
- .into_iter()
- .filter(|path| paths.contains(path))
- .collect::<Vec<_>>()
+
+ let collect_files =
+ collect_files(&include_files, &exclude_files, is_supported_ext_fmt);
+
+ let (result, should_refmt) = match collect_files {
+ Ok(value) => {
+ if let Some(paths) = changed {
+ let refmt_files = value
+ .clone()
+ .into_iter()
+ .filter(|path| paths.contains(path))
+ .collect::<Vec<_>>();
+
+ let should_refmt = !refmt_files.is_empty();
+
+ if check {
+ (Ok((value, fmt_options.clone())), Some(should_refmt))
} else {
- files
- };
- (collected_files, fmt_options.clone())
- },
- );
+ (Ok((refmt_files, fmt_options.clone())), Some(should_refmt))
+ }
+ } else {
+ (Ok((value, fmt_options.clone())), None)
+ }
+ }
+ Err(e) => (Err(e), None),
+ };
+
let paths_to_watch = include_files.clone();
async move {
- if (files_changed || !watch)
- && matches!(result, Ok((ref files, _)) if files.is_empty())
- {
+ if files_changed && matches!(should_refmt, Some(false)) {
ResolutionResult::Ignore
} else {
ResolutionResult::Restart {
@@ -121,13 +132,16 @@ pub async fn format(
if watch {
file_watcher::watch_func(resolver, operation, "Fmt").await?;
} else {
- let (files, fmt_options) =
- if let ResolutionResult::Restart { result, .. } = resolver(None).await {
- result?
- } else {
- return Err(generic_error("No target files found."));
- };
- operation((files, fmt_options)).await?;
+ let files =
+ collect_files(&include_files, &exclude_files, is_supported_ext_fmt)
+ .and_then(|files| {
+ if files.is_empty() {
+ Err(generic_error("No target files found."))
+ } else {
+ Ok(files)
+ }
+ })?;
+ operation((files, fmt_options.clone())).await?;
}
Ok(())
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index 6948d2a1f..1f85e8b02 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -105,26 +105,27 @@ pub async fn lint(
let resolver = |changed: Option<Vec<PathBuf>>| {
let files_changed = changed.is_some();
- let result = collect_files(
- &*include_files.clone(),
- &*exclude_files.clone(),
- is_supported_ext,
- )
- .map(|files| {
- if let Some(paths) = changed {
- files
- .into_iter()
- .filter(|path| paths.contains(path))
- .collect::<Vec<_>>()
- } else {
- files
+ let collect_files =
+ collect_files(&include_files, &exclude_files, is_supported_ext);
+
+ let paths_to_watch = include_files.clone();
+
+ let (result, should_relint) = match collect_files {
+ Ok(value) => {
+ if let Some(paths) = changed {
+ (
+ Ok(value.clone()),
+ Some(value.iter().any(|path| paths.contains(path))),
+ )
+ } else {
+ (Ok(value), None)
+ }
}
- });
- let paths_to_watch = args.clone();
+ Err(e) => (Err(e), None),
+ };
+
async move {
- if (files_changed || !watch)
- && matches!(result, Ok(ref files) if files.is_empty())
- {
+ if files_changed && matches!(should_relint, Some(false)) {
ResolutionResult::Ignore
} else {
ResolutionResult::Restart {