diff --git a/Cargo.lock b/Cargo.lock index 96a6ebc..467f8eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,11 +21,26 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +[[package]] +name = "console" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc80946b3480f421c2f17ed1cb841753a371c7c5104f51d507e13f532c856aa" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "regex", + "terminal_size", + "unicode-width", + "winapi", +] + [[package]] name = "dprint-core" -version = "0.35.0" +version = "0.35.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87368d637be4fedbddd60e41958e227af4d7d32127b9a5a6cb05b0053b525f94" +checksum = "a0edf9f35fbd32eb53b7e047cb1da4208c70e9c3643a733478fd7c99d98009b3" dependencies = [ "bumpalo", "fnv", @@ -34,9 +49,13 @@ dependencies = [ [[package]] name = "dprint-development" -version = "0.2.2" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "417ed417346ddd21939fd451061d93d13e9df53c97dc15a2c71faa9c9881710e" +checksum = "377641799781b450e47a820f4a821395fb852ffe4d97eebf64f95d3160625737" +dependencies = [ + "console", + "similar", +] [[package]] name = "dprint-plugin-markdown" @@ -50,6 +69,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "fnv" version = "1.0.7" @@ -68,6 +93,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "libc" +version = "0.2.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" + [[package]] name = "memchr" version = "2.3.3" @@ -105,9 +136,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.9" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ "aho-corasick", "memchr", @@ -117,9 +148,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "ryu" @@ -158,6 +189,12 @@ dependencies = [ "serde", ] +[[package]] +name = "similar" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3eda43b31c5a15bbdaadef2c32354240b1d4b551b944b3a021838b3bafff996" + [[package]] name = "syn" version = "1.0.58" @@ -169,6 +206,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "terminal_size" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "thread_local" version = "1.0.1" @@ -187,6 +234,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -198,3 +251,25 @@ name = "version_check" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 03462d0..6f3ae64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,11 +23,11 @@ panic = "abort" wasm = ["serde_json", "dprint-core/wasm"] [dependencies] -dprint-core = { version = "0.35.0", features = ["formatting"] } +dprint-core = { version = "0.35.2", features = ["formatting"] } pulldown-cmark = { version = "0.8.0", default-features = false } serde = { version = "1.0.88", features = ["derive"] } serde_json = { version = "1.0", optional = true } regex = "1" [dev-dependencies] -dprint-development = "0.2.2" +dprint-development = "0.2.6" diff --git a/src/configuration/builder.rs b/src/configuration/builder.rs index 4f6760a..a84309a 100644 --- a/src/configuration/builder.rs +++ b/src/configuration/builder.rs @@ -15,7 +15,7 @@ use super::*; /// .build(); /// ``` pub struct ConfigurationBuilder { - config: ConfigKeyMap, + pub(super) config: ConfigKeyMap, global_config: Option, } @@ -92,6 +92,13 @@ impl ConfigurationBuilder { self.insert("ignoreEndDirective", value.to_string().into()) } + pub fn deno(&mut self) -> &mut Self { + self.text_wrap(TextWrap::Always) + .ignore_directive("deno-fmt-ignore") + .ignore_start_directive("deno-fmt-ignore-start") + .ignore_end_directive("deno-fmt-ignore-end") + } + #[cfg(test)] pub(super) fn get_inner_config(&self) -> ConfigKeyMap { self.config.clone() diff --git a/src/configuration/resolve_config.rs b/src/configuration/resolve_config.rs index 05ae4a2..f91ef27 100644 --- a/src/configuration/resolve_config.rs +++ b/src/configuration/resolve_config.rs @@ -1,4 +1,5 @@ use dprint_core::configuration::*; +use super::builder::ConfigurationBuilder; use super::Configuration; use super::types::*; @@ -28,6 +29,10 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration) let mut diagnostics = Vec::new(); let mut config = config; + if get_value(&mut config, "deno", false, &mut diagnostics) { + fill_deno_config(&mut config); + } + let resolved_config = Configuration { line_width: get_value(&mut config, "lineWidth", global_config.line_width.unwrap_or(80), &mut diagnostics), new_line_kind: get_value(&mut config, "newLineKind", global_config.new_line_kind.unwrap_or(DEFAULT_GLOBAL_CONFIGURATION.new_line_kind), &mut diagnostics), @@ -51,3 +56,11 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration) diagnostics, } } + +fn fill_deno_config(config: &mut ConfigKeyMap) { + for (key, value) in ConfigurationBuilder::new().deno().config.iter() { + if !config.contains_key(key) { + config.insert(key.clone(), value.clone()); + } + } +} diff --git a/tests/specs/General/Deno_All.txt b/tests/specs/General/Deno_All.txt new file mode 100644 index 0000000..431ef59 --- /dev/null +++ b/tests/specs/General/Deno_All.txt @@ -0,0 +1,39 @@ +~~ deno: true ~~ +!! should format according to deno config !! +testing this out by going very far over the line and more testing and testing testing + + +testing this out by going very far over the line and more testing and testing testing + +testing this out by going very far over the line and more testing and testing testing + + + +testing this out by going very far over the line and more testing and testing testing + +testing this out by going very far over the line and more testing and testing testing + + + +testing this out by going very far over the line and more testing and testing testing + +[expect] +testing this out by going very far over the line and more testing and testing +testing + + +testing this out by going very far over the line and more testing and testing testing + +testing this out by going very far over the line and more testing and testing +testing + + + +testing this out by going very far over the line and more testing and testing testing + +testing this out by going very far over the line and more testing and testing testing + + + +testing this out by going very far over the line and more testing and testing +testing