mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
upgrade: dprint 0.9.5 (#4491)
This commit is contained in:
parent
5d7bcf86fd
commit
fd432e2346
3 changed files with 41 additions and 39 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -552,24 +552,25 @@ checksum = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6"
|
|||
|
||||
[[package]]
|
||||
name = "dprint-core"
|
||||
version = "0.11.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d1aa8ea00ca5fb5a92278a6596b14b0f8336c3d0b6c6cbde4b46817dcd2ed0"
|
||||
checksum = "8fb2332f10c6acf94b5d469ed993cf52ed7a1369b80523fb9cb21fa10c6b6887"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dprint-plugin-typescript"
|
||||
version = "0.8.1"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dcf2ac362cb71dac70767cd23fba63063fb47bdb84ccef8b42ba03e17c0451d"
|
||||
checksum = "b40a2ed665c9cb3192b689bcfc6934a1dbe16009e363c84b6db19ce1c36ef274"
|
||||
dependencies = [
|
||||
"dprint-core",
|
||||
"serde",
|
||||
"swc_common",
|
||||
"swc_ecma_ast",
|
||||
"swc_ecma_parser",
|
||||
"swc_ecma_parser_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2207,9 +2208,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "swc_ecma_parser"
|
||||
version = "0.21.5"
|
||||
version = "0.21.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9519ab89ac37f65eb7d58f892f89aaa4dc64979b660a029025dbb9ee2a2b2903"
|
||||
checksum = "701e681b7783c5b9d3df9e18592494ca3cba7a2fa8fc98d4d4f423ae993df155"
|
||||
dependencies = [
|
||||
"either",
|
||||
"enum_kind",
|
||||
|
|
|
@ -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"
|
||||
|
|
65
cli/fmt.rs
65
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue