diff --git a/Cargo.lock b/Cargo.lock index 054b73bf62..f59aeb2c5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -607,18 +607,18 @@ checksum = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6" [[package]] name = "dprint-core" -version = "0.12.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb2332f10c6acf94b5d469ed993cf52ed7a1369b80523fb9cb21fa10c6b6887" +checksum = "93213397182b20fc4565e6ad93cc30cb1825a276d11bcac969cd06c63006898c" dependencies = [ "serde", ] [[package]] name = "dprint-plugin-typescript" -version = "0.9.11" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ce1a0c6a94ad6b134a35e33269f970be65c7ffaeb4bf5be7ae3a1e4e36df96" +checksum = "e1e9af423272fc71c59bfbf3c34c617c3fe93d39a5232c25e0c123af984e0f1f" dependencies = [ "dprint-core", "serde", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 92fc58208f..2623513c39 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.9.11" +dprint-plugin-typescript = "0.13.0" futures = { version = "0.3.4", features = ["compat", "io-compat"] } glob = "0.3.0" http = "0.2.1" diff --git a/cli/fmt.rs b/cli/fmt.rs index 07a16983a4..acdd816cf9 100644 --- a/cli/fmt.rs +++ b/cli/fmt.rs @@ -21,15 +21,7 @@ use std::path::PathBuf; fn is_supported(path: &Path) -> bool { if let Some(ext) = path.extension() { - if ext == "tsx" || ext == "js" || ext == "jsx" { - true - } else if ext == "ts" { - // Currently dprint does not support d.ts files. - // https://github.com/dsherret/dprint/issues/100 - !path.as_os_str().to_string_lossy().ends_with(".d.ts") - } else { - false - } + ext == "ts" || ext == "tsx" || ext == "js" || ext == "jsx" } else { false } @@ -37,7 +29,7 @@ fn is_supported(path: &Path) -> bool { fn get_config() -> dprint::configuration::Configuration { use dprint::configuration::*; - ConfigurationBuilder::new().prettier().build() + ConfigurationBuilder::new().deno().build() } fn check_source_files( @@ -45,16 +37,14 @@ fn check_source_files( paths: Vec, ) -> Result<(), ErrBox> { let mut not_formatted_files = vec![]; + let formatter = dprint::Formatter::new(config); for file_path in paths { let file_path_str = file_path.to_string_lossy(); let file_contents = fs::read_to_string(&file_path)?; - let r = dprint::format_text(&file_path_str, &file_contents, &config); + let r = formatter.format_text(&file_path_str, &file_contents); match r { - Ok(None) => { - // nothing to format, pass - } - Ok(Some(formatted_text)) => { + Ok(formatted_text) => { if formatted_text != file_contents { not_formatted_files.push(file_path); } @@ -93,16 +83,14 @@ fn format_source_files( paths: Vec, ) -> Result<(), ErrBox> { let mut not_formatted_files = vec![]; + let formatter = dprint::Formatter::new(config); for file_path in paths { let file_path_str = file_path.to_string_lossy(); let file_contents = fs::read_to_string(&file_path)?; - let r = dprint::format_text(&file_path_str, &file_contents, &config); + let r = formatter.format_text(&file_path_str, &file_contents); match r { - Ok(None) => { - // nothing to format, pass - } - Ok(Some(formatted_text)) => { + Ok(formatted_text) => { if formatted_text != file_contents { println!("{}", file_path_str); fs::write(&file_path, formatted_text)?; @@ -166,11 +154,10 @@ fn format_stdin(check: bool) -> Result<(), ErrBox> { if stdin().read_to_string(&mut source).is_err() { return Err(OpError::other("Failed to read from stdin".to_string()).into()); } - let config = get_config(); + let formatter = dprint::Formatter::new(get_config()); - match dprint::format_text("_stdin.ts", &source, &config) { - Ok(None) => unreachable!(), - Ok(Some(formatted_text)) => { + match formatter.format_text("_stdin.ts", &source) { + Ok(formatted_text) => { if check { if formatted_text != source { println!("Not formatted stdin"); @@ -190,7 +177,7 @@ fn format_stdin(check: bool) -> Result<(), ErrBox> { fn test_is_supported() { assert!(!is_supported(Path::new("tests/subdir/redirects"))); assert!(!is_supported(Path::new("README.md"))); - assert!(!is_supported(Path::new("lib/typescript.d.ts"))); + assert!(is_supported(Path::new("lib/typescript.d.ts"))); assert!(is_supported(Path::new("cli/tests/001_hello.js"))); assert!(is_supported(Path::new("cli/tests/002_hello.ts"))); assert!(is_supported(Path::new("foo.jsx")));