diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 2 | ||||
-rw-r--r-- | cli/fmt.rs | 65 |
2 files changed, 34 insertions, 33 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c7a2fbf75..1a7a8db8c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -33,7 +33,7 @@ byteorder = "1.3.4" clap = "2.33.0" dirs = "2.0.2" dlopen = "0.1.8" -dprint-plugin-typescript = "0.8.1" +dprint-plugin-typescript = "0.9.5" futures = { version = "0.3.4", features = ["compat", "io-compat"] } glob = "0.3.0" http = "0.2.0" diff --git a/cli/fmt.rs b/cli/fmt.rs index 8d2f982df..edfc27730 100644 --- a/cli/fmt.rs +++ b/cli/fmt.rs @@ -37,15 +37,23 @@ fn is_supported(path: &Path) -> bool { fn get_config() -> dprint::configuration::Configuration { use dprint::configuration::*; - ConfigurationBuilder::new() - .line_width(80) - .indent_width(2) - .next_control_flow_position(NextControlFlowPosition::SameLine) - .binary_expression_operator_position(OperatorPosition::SameLine) - .brace_position(BracePosition::SameLine) // default is NextLineIfHanging - .comment_line_force_space_after_slashes(false) - .construct_signature_space_after_new_keyword(true) - .build() + ConfigurationBuilder::new().prettier().build() +} + +// TODO(ry) dprint seems to panic unnecessarally sometimes. Until it matures +// we'll use a catch_unwind to avoid passing it on to our users. +fn format_text_ignore_panic( + file_path_str: &str, + file_contents: &str, + config: &dprint::configuration::Configuration, +) -> Result<Option<String>, String> { + let catch_result = std::panic::catch_unwind(|| { + dprint::format_text(file_path_str, file_contents, config) + }); + match catch_result { + Ok(dprint_result) => dprint_result, + Err(e) => Err(format!("dprint panic '{}' {:?}", file_path_str, e)), + } } fn check_source_files( @@ -57,7 +65,7 @@ fn check_source_files( for file_path in paths { let file_path_str = file_path.to_string_lossy(); let file_contents = fs::read_to_string(&file_path).unwrap(); - match dprint::format_text(&file_path_str, &file_contents, &config) { + match format_text_ignore_panic(&file_path_str, &file_contents, &config) { Ok(None) => { // nothing to format, pass } @@ -101,30 +109,23 @@ fn format_source_files( for file_path in paths { let file_path_str = file_path.to_string_lossy(); let file_contents = fs::read_to_string(&file_path)?; - // TODO(ry) dprint seems to panic unnecessarally sometimes. Until it matures - // we'll use a catch_unwind to avoid passing it on to our users. - let catch_unwind_result = std::panic::catch_unwind(|| { - dprint::format_text(&file_path_str, &file_contents, &config) - }); - if let Ok(dprint_result) = catch_unwind_result { - match dprint_result { - Ok(None) => { - // nothing to format, pass - } - Ok(Some(formatted_text)) => { - if formatted_text != file_contents { - println!("{}", file_path_str); - fs::write(&file_path, formatted_text)?; - not_formatted_files.push(file_path); - } - } - Err(e) => { - eprintln!("Error formatting: {}", &file_path_str); - eprintln!(" {}", e); + let dprint_result = + format_text_ignore_panic(&file_path_str, &file_contents, &config); + match dprint_result { + Ok(None) => { + // nothing to format, pass + } + Ok(Some(formatted_text)) => { + if formatted_text != file_contents { + println!("{}", file_path_str); + fs::write(&file_path, formatted_text)?; + not_formatted_files.push(file_path); } } - } else { - eprintln!("dprint panic {}", file_path_str); + Err(e) => { + eprintln!("Error formatting: {}", &file_path_str); + eprintln!(" {}", e); + } } } |