0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

upgrade: dprint 0.9.5 (#4491)

This commit is contained in:
Ryan Dahl 2020-03-25 17:24:26 -04:00 committed by GitHub
parent 5d7bcf86fd
commit fd432e2346
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 39 deletions

13
Cargo.lock generated
View file

@ -552,24 +552,25 @@ checksum = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6"
[[package]] [[package]]
name = "dprint-core" name = "dprint-core"
version = "0.11.0" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d1aa8ea00ca5fb5a92278a6596b14b0f8336c3d0b6c6cbde4b46817dcd2ed0" checksum = "8fb2332f10c6acf94b5d469ed993cf52ed7a1369b80523fb9cb21fa10c6b6887"
dependencies = [ dependencies = [
"serde", "serde",
] ]
[[package]] [[package]]
name = "dprint-plugin-typescript" name = "dprint-plugin-typescript"
version = "0.8.1" version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dcf2ac362cb71dac70767cd23fba63063fb47bdb84ccef8b42ba03e17c0451d" checksum = "b40a2ed665c9cb3192b689bcfc6934a1dbe16009e363c84b6db19ce1c36ef274"
dependencies = [ dependencies = [
"dprint-core", "dprint-core",
"serde", "serde",
"swc_common", "swc_common",
"swc_ecma_ast", "swc_ecma_ast",
"swc_ecma_parser", "swc_ecma_parser",
"swc_ecma_parser_macros",
] ]
[[package]] [[package]]
@ -2207,9 +2208,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_parser" name = "swc_ecma_parser"
version = "0.21.5" version = "0.21.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9519ab89ac37f65eb7d58f892f89aaa4dc64979b660a029025dbb9ee2a2b2903" checksum = "701e681b7783c5b9d3df9e18592494ca3cba7a2fa8fc98d4d4f423ae993df155"
dependencies = [ dependencies = [
"either", "either",
"enum_kind", "enum_kind",

View file

@ -33,7 +33,7 @@ byteorder = "1.3.4"
clap = "2.33.0" clap = "2.33.0"
dirs = "2.0.2" dirs = "2.0.2"
dlopen = "0.1.8" 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"] } futures = { version = "0.3.4", features = ["compat", "io-compat"] }
glob = "0.3.0" glob = "0.3.0"
http = "0.2.0" http = "0.2.0"

View file

@ -37,15 +37,23 @@ fn is_supported(path: &Path) -> bool {
fn get_config() -> dprint::configuration::Configuration { fn get_config() -> dprint::configuration::Configuration {
use dprint::configuration::*; use dprint::configuration::*;
ConfigurationBuilder::new() ConfigurationBuilder::new().prettier().build()
.line_width(80) }
.indent_width(2)
.next_control_flow_position(NextControlFlowPosition::SameLine) // TODO(ry) dprint seems to panic unnecessarally sometimes. Until it matures
.binary_expression_operator_position(OperatorPosition::SameLine) // we'll use a catch_unwind to avoid passing it on to our users.
.brace_position(BracePosition::SameLine) // default is NextLineIfHanging fn format_text_ignore_panic(
.comment_line_force_space_after_slashes(false) file_path_str: &str,
.construct_signature_space_after_new_keyword(true) file_contents: &str,
.build() 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( fn check_source_files(
@ -57,7 +65,7 @@ fn check_source_files(
for file_path in paths { for file_path in paths {
let file_path_str = file_path.to_string_lossy(); let file_path_str = file_path.to_string_lossy();
let file_contents = fs::read_to_string(&file_path).unwrap(); 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) => { Ok(None) => {
// nothing to format, pass // nothing to format, pass
} }
@ -101,12 +109,8 @@ fn format_source_files(
for file_path in paths { for file_path in paths {
let file_path_str = file_path.to_string_lossy(); let file_path_str = file_path.to_string_lossy();
let file_contents = fs::read_to_string(&file_path)?; let file_contents = fs::read_to_string(&file_path)?;
// TODO(ry) dprint seems to panic unnecessarally sometimes. Until it matures let dprint_result =
// we'll use a catch_unwind to avoid passing it on to our users. format_text_ignore_panic(&file_path_str, &file_contents, &config);
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 { match dprint_result {
Ok(None) => { Ok(None) => {
// nothing to format, pass // nothing to format, pass
@ -123,9 +127,6 @@ fn format_source_files(
eprintln!(" {}", e); eprintln!(" {}", e);
} }
} }
} else {
eprintln!("dprint panic {}", file_path_str);
}
} }
let f = if not_formatted_files.len() == 1 { let f = if not_formatted_files.len() == 1 {