summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2020-09-08 05:58:17 -0400
committerGitHub <noreply@github.com>2020-09-08 11:58:17 +0200
commitab7f93caf15b30b6570f994c6448710fca000429 (patch)
treec8a0bfbffdaddcada6cd40f35ebb3aff1f3d160e
parent1d0f1ed446acd2db7c052503570c9249e7b841e9 (diff)
upgrade: dprint-plugin-typescript 0.31.0 (#7381)
-rw-r--r--Cargo.lock4
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/fmt.rs24
3 files changed, 14 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 63f6c50e3..158b397f1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -569,9 +569,9 @@ dependencies = [
[[package]]
name = "dprint-plugin-typescript"
-version = "0.30.3"
+version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa33c3669a2b89c6a8809d34648422262907b2f7cc15d51fe53c860f5161626b"
+checksum = "ab0711bfaae1add9468220fb775addcf50b3bdbe5a85c1266f5d324206131080"
dependencies = [
"dprint-core",
"serde",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 224373053..b95cf1ddb 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -40,7 +40,7 @@ clap = "2.33.2"
dissimilar = "1.0.2"
dlopen = "0.1.8"
encoding_rs = "0.8.23"
-dprint-plugin-typescript = "0.30.3"
+dprint-plugin-typescript = "0.31.0"
futures = "0.3.5"
filetime = "0.2.12"
http = "0.2.1"
diff --git a/cli/fmt.rs b/cli/fmt.rs
index b81573294..0a9727f7a 100644
--- a/cli/fmt.rs
+++ b/cli/fmt.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
//! This module provides file formating utilities using
-//! [`dprint`](https://github.com/dsherret/dprint).
+//! [`dprint-plugin-typescript`](https://github.com/dsherret/dprint-plugin-typescript).
//!
//! At the moment it is only consumed using CLI but in
//! the future it can be easily extended to provide
@@ -58,7 +58,6 @@ async fn check_source_files(
paths: Vec<PathBuf>,
) -> Result<(), ErrBox> {
let not_formatted_files_count = Arc::new(AtomicUsize::new(0));
- let formatter = Arc::new(dprint::Formatter::new(config));
// prevent threads outputting at the same time
let output_lock = Arc::new(Mutex::new(0));
@@ -67,11 +66,11 @@ async fn check_source_files(
let not_formatted_files_count = not_formatted_files_count.clone();
move |file_path| {
let file_text = read_file_contents(&file_path)?.text;
- let r = formatter.format_text(&file_path, &file_text);
+ let r = dprint::format_text(&file_path, &file_text, &config);
match r {
Ok(formatted_text) => {
if formatted_text != file_text {
- not_formatted_files_count.fetch_add(1, Ordering::SeqCst);
+ not_formatted_files_count.fetch_add(1, Ordering::Relaxed);
let _g = output_lock.lock().unwrap();
match diff(&file_text, &formatted_text) {
Ok(diff) => {
@@ -105,7 +104,7 @@ async fn check_source_files(
.await?;
let not_formatted_files_count =
- not_formatted_files_count.load(Ordering::SeqCst);
+ not_formatted_files_count.load(Ordering::Relaxed);
if not_formatted_files_count == 0 {
Ok(())
} else {
@@ -122,14 +121,13 @@ async fn format_source_files(
paths: Vec<PathBuf>,
) -> Result<(), ErrBox> {
let 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
run_parallelized(paths, {
let formatted_files_count = formatted_files_count.clone();
move |file_path| {
let file_contents = read_file_contents(&file_path)?;
- let r = formatter.format_text(&file_path, &file_contents.text);
+ let r = dprint::format_text(&file_path, &file_contents.text, &config);
match r {
Ok(formatted_text) => {
if formatted_text != file_contents.text {
@@ -140,7 +138,7 @@ async fn format_source_files(
text: formatted_text,
},
)?;
- formatted_files_count.fetch_add(1, Ordering::SeqCst);
+ formatted_files_count.fetch_add(1, Ordering::Relaxed);
let _g = output_lock.lock().unwrap();
println!("{}", file_path.to_string_lossy());
}
@@ -156,7 +154,7 @@ async fn format_source_files(
})
.await?;
- let formatted_files_count = formatted_files_count.load(Ordering::SeqCst);
+ let formatted_files_count = formatted_files_count.load(Ordering::Relaxed);
debug!(
"Formatted {} {}",
formatted_files_count,
@@ -173,10 +171,10 @@ fn format_stdin(check: bool) -> Result<(), ErrBox> {
if stdin().read_to_string(&mut source).is_err() {
return Err(ErrBox::error("Failed to read from stdin"));
}
- let formatter = dprint::Formatter::new(get_config());
+ let config = get_config();
// dprint will fallback to jsx parsing if parsing this as a .ts file doesn't work
- match formatter.format_text(&PathBuf::from("_stdin.ts"), &source) {
+ match dprint::format_text(&PathBuf::from("_stdin.ts"), &source, &config) {
Ok(formatted_text) => {
if check {
if formatted_text != source {
@@ -245,7 +243,7 @@ struct FileContents {
had_bom: bool,
}
-fn read_file_contents(file_path: &PathBuf) -> Result<FileContents, ErrBox> {
+fn read_file_contents(file_path: &Path) -> Result<FileContents, ErrBox> {
let file_bytes = fs::read(&file_path)?;
let charset = text_encoding::detect_charset(&file_bytes);
let file_text = text_encoding::convert_to_utf8(&file_bytes, charset)?;
@@ -261,7 +259,7 @@ fn read_file_contents(file_path: &PathBuf) -> Result<FileContents, ErrBox> {
}
fn write_file_contents(
- file_path: &PathBuf,
+ file_path: &Path,
file_contents: FileContents,
) -> Result<(), ErrBox> {
let file_text = if file_contents.had_bom {