summaryrefslogtreecommitdiff
path: root/cli/fmt.rs
diff options
context:
space:
mode:
authorFilippo Rossi <Qu4k@users.noreply.github.com>2020-05-23 15:22:08 +0200
committerRyan Dahl <ry@tinyclouds.org>2020-06-06 09:07:59 -0400
commit78333f0ab3614e8dbd3dfdc95e9dbb53f80ffe5d (patch)
tree5f943c8b6353d354aa0180eefc185daa984803f1 /cli/fmt.rs
parent8a4533eb75ff505f8aa16c206af1ca13f0e6c166 (diff)
Add diff for "deno fmt --check" (#5599)
Diffstat (limited to 'cli/fmt.rs')
-rw-r--r--cli/fmt.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs
index 5d1becffa..0d7a909bc 100644
--- a/cli/fmt.rs
+++ b/cli/fmt.rs
@@ -7,6 +7,8 @@
//! the future it can be easily extended to provide
//! the same functions as ops available in JS runtime.
+use crate::colors;
+use crate::diff::diff;
use crate::fs::files_in_subtree;
use crate::op_error::OpError;
use deno_core::ErrBox;
@@ -63,7 +65,9 @@ async fn check_source_files(
) -> Result<(), ErrBox> {
let not_formatted_files_count = Arc::new(AtomicUsize::new(0));
let formatter = Arc::new(dprint::Formatter::new(config));
- let output_lock = Arc::new(Mutex::new(0)); // prevent threads outputting at the same time
+
+ // prevent threads outputting at the same time
+ let output_lock = Arc::new(Mutex::new(0));
run_parallelized(paths, {
let not_formatted_files_count = not_formatted_files_count.clone();
@@ -74,6 +78,25 @@ async fn check_source_files(
Ok(formatted_text) => {
if formatted_text != file_text {
not_formatted_files_count.fetch_add(1, Ordering::SeqCst);
+ let _g = output_lock.lock().unwrap();
+ match diff(&file_text, &formatted_text) {
+ Ok(diff) => {
+ println!();
+ println!(
+ "{} {}:",
+ colors::bold("from".to_string()),
+ file_path.display().to_string()
+ );
+ println!("{}", diff);
+ }
+ Err(e) => {
+ eprintln!(
+ "Error generating diff: {}",
+ file_path.to_string_lossy()
+ );
+ eprintln!(" {}", e);
+ }
+ }
}
}
Err(e) => {