From 38a6b0bc107af2aad4f9a09909e3426185fbb6e8 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 8 Jun 2026 15:01:05 -0400 Subject: [PATCH 1/3] refactor: update to dprint-core 0.68 --- Cargo.lock | 378 ++++++++++++++++++++++++++++++++----- Cargo.toml | 8 +- src/generation/generate.rs | 93 ++++----- src/wasm_plugin.rs | 57 +++--- tests/test.rs | 9 +- 5 files changed, 419 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b68896..01dadbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,53 +2,138 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "bitflags" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +dependencies = [ + "allocator-api2", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "console" -version = "0.15.8" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87" dependencies = [ "encode_unicode", - "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "deno_terminal" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3ba8041ae7319b3ca6a64c399df4112badcbbe0868b4517637647614bede4be" +dependencies = [ + "once_cell", + "termcolor", ] [[package]] name = "dprint-core" -version = "0.65.0" +version = "0.68.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b569f4e3085ae957ecc37588e6b2227791b72745434eae966db29e122ba27f0d" +checksum = "8698cce2d4defd77683dd360c67351643523c4f87ad177b6574978d0f05e4836" dependencies = [ - "anyhow", "bumpalo", + "hashbrown 0.15.5", "indexmap", "rustc-hash", "serde", + "serde_json", + "thiserror", "unicode-width", ] +[[package]] +name = "dprint-core-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1675ad2b358481f3cc46202040d64ac7a36c4ade414a696df32e0e45421a6e9f" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "dprint-development" -version = "0.9.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e2502cba4299d334fc11a8a3357eb459f378dc285d7fbbb365c595a0ce48c73" +checksum = "90b3b095f94733262261bfeb860a6550e1d656dd108240c43004bd0f1b419837" dependencies = [ - "anyhow", "console", + "file_test_runner", "serde_json", "similar", ] @@ -57,8 +142,8 @@ dependencies = [ name = "dprint-plugin-dockerfile" version = "0.3.4" dependencies = [ - "anyhow", "dprint-core", + "dprint-core-macros", "dprint-development", "monch", "serde", @@ -66,11 +151,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + [[package]] name = "encode_unicode" -version = "0.3.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "equivalent" @@ -78,21 +169,54 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "file_test_runner" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aab2ea62262e650557af93e48bfb0ffbcf3b6d86af4b9fea1aa00f93821b69a9" +dependencies = [ + "anyhow", + "crossbeam-channel", + "deno_terminal", + "parking_lot", + "rayon", + "regex", + "thiserror", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "indexmap" -version = "2.1.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.17.1", "serde", + "serde_core", ] [[package]] @@ -101,24 +225,62 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" + [[package]] name = "monch" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bcc6ad3b93f756f2532d29f7c7291b8d246a2c460a99a3611327bb726830014" +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -137,55 +299,142 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" [[package]] -name = "ryu" -version = "1.0.5" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "indexmap", "itoa", - "ryu", + "memchr", "serde", + "serde_core", + "zmij", ] [[package]] name = "similar" -version = "2.4.0" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "syn" @@ -198,6 +447,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "2.0.18" @@ -215,7 +473,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -226,9 +484,24 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "winapi-util" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" @@ -239,6 +512,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.52.0" @@ -295,3 +577,9 @@ name = "windows_x86_64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 8bcb117..89dd2eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,17 +21,17 @@ overflow-checks = false panic = "abort" [features] -wasm = ["anyhow", "serde_json", "dprint-core/wasm"] +wasm = ["serde_json", "dprint-core/wasm"] tracing = ["dprint-core/tracing"] [dependencies] -anyhow = { version = "1.0.62", optional = true } -dprint-core = { version = "0.65.0", features = ["formatting"] } +dprint-core = { version = "0.68.1", features = ["formatting"], default-features = false } +dprint-core-macros = "0.1.0" monch = "0.6.0" serde = { version = "1.0.144", features = ["derive"] } serde_json = { version = "1.0", optional = true } thiserror = "2" [dev-dependencies] -dprint-development = "0.9.5" +dprint-development = "0.11.0" serde_json = { version = "1.0" } diff --git a/src/generation/generate.rs b/src/generation/generate.rs index f616841..8c5f4e7 100644 --- a/src/generation/generate.rs +++ b/src/generation/generate.rs @@ -1,6 +1,7 @@ use dprint_core::formatting::ir_helpers::SingleLineOptions; use dprint_core::formatting::ir_helpers::gen_from_raw_string; use dprint_core::formatting::*; +use dprint_core_macros::sc; use super::context::Context; use super::helpers::*; @@ -66,11 +67,11 @@ fn gen_node<'a>(node: Node<'a>, context: &mut Context<'a>) -> PrintItems { fn gen_arg_instruction<'a>(node: &'a ArgInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("ARG "); + items.push_sc(sc!("ARG ")); items.extend(gen_node((&node.name).into(), context)); if let Some(value) = &node.value { - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node(value.into(), context)); } @@ -79,7 +80,7 @@ fn gen_arg_instruction<'a>(node: &'a ArgInstruction, context: &mut Context<'a>) fn gen_cmd_instruction<'a>(node: &'a CmdInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("CMD "); + items.push_sc(sc!("CMD ")); items.extend(match &node.expr { ShellOrExecExpr::Exec(node) => gen_node(node.into(), context), ShellOrExecExpr::Shell(node) => gen_node(node.into(), context), @@ -89,14 +90,14 @@ fn gen_cmd_instruction<'a>(node: &'a CmdInstruction, context: &mut Context<'a>) fn gen_copy_instruction<'a>(node: &'a CopyInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - let prefix_str = "COPY "; - items.push_str(prefix_str); + let prefix = sc!("COPY "); + items.push_sc(prefix); match &node.args { CopyArgs::Exec(array) => { for flag in &node.flags { items.extend(gen_node(flag.into(), context)); - items.push_str(" "); + items.push_sc(sc!(" ")); } items.extend(gen_node(array.into(), context)); } @@ -111,12 +112,12 @@ fn gen_copy_instruction<'a>(node: &'a CopyInstruction, context: &mut Context<'a> if nodes.iter().any(|node| node.is_comment()) { // preserve comments by breaking onto multiple lines, aligned with the arguments - items.extend(gen_multi_line_items(nodes, prefix_str.chars().count() as u32, context)); + items.extend(gen_multi_line_items(nodes, prefix.text.chars().count() as u32, context)); } else { // keep everything on a single line for (i, node) in nodes.into_iter().enumerate() { if i > 0 { - items.push_str(" "); + items.push_sc(sc!(" ")); } items.extend(gen_node(node, context)); } @@ -128,7 +129,7 @@ fn gen_copy_instruction<'a>(node: &'a CopyInstruction, context: &mut Context<'a> fn gen_entrypoint_instruction<'a>(node: &'a EntrypointInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("ENTRYPOINT "); + items.push_sc(sc!("ENTRYPOINT ")); items.extend(match &node.expr { ShellOrExecExpr::Exec(node) => gen_node(node.into(), context), ShellOrExecExpr::Shell(node) => gen_node(node.into(), context), @@ -139,30 +140,30 @@ fn gen_entrypoint_instruction<'a>(node: &'a EntrypointInstruction, context: &mut fn gen_env_instruction<'a>(node: &'a EnvInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); let nodes = context.gen_nodes_with_comments(node.span.start, node.span.end, false, node.vars.iter().map(|i| i.into())); - let prefix_str = "ENV "; - items.push_str(prefix_str); - items.extend(gen_multi_line_items(nodes, prefix_str.chars().count() as u32, context)); + let prefix = sc!("ENV "); + items.push_sc(prefix); + items.extend(gen_multi_line_items(nodes, prefix.text.chars().count() as u32, context)); items } fn gen_env_var<'a>(node: &'a EnvVar, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); items.extend(gen_node((&node.key).into(), context)); - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node((&node.value).into(), context)); items } fn gen_from_instruction<'a>(node: &'a FromInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("FROM "); + items.push_sc(sc!("FROM ")); for flag in &node.flags { items.extend(gen_node(flag.into(), context)); - items.push_str(" "); + items.push_sc(sc!(" ")); } items.extend(gen_node((&node.image).into(), context)); if let Some(alias) = &node.alias { - items.push_str(" AS "); + items.push_sc(sc!(" AS ")); items.extend(gen_node(alias.into(), context)); } items @@ -170,27 +171,27 @@ fn gen_from_instruction<'a>(node: &'a FromInstruction, context: &mut Context<'a> fn gen_from_flag<'a>(node: &'a FromFlag, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("--"); + items.push_sc(sc!("--")); items.extend(gen_node((&node.name).into(), context)); - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node((&node.value).into(), context)); items } fn gen_label_instruction<'a>(node: &'a LabelInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - let prefix_str = "LABEL "; - items.push_str(prefix_str); + let prefix = sc!("LABEL "); + items.push_sc(prefix); // route through gen_nodes_with_comments so comments between labels are kept let nodes = context.gen_nodes_with_comments(node.span.start, node.span.end, false, node.labels.iter().map(|l| l.into())); - items.extend(gen_multi_line_items(nodes, prefix_str.chars().count() as u32, context)); + items.extend(gen_multi_line_items(nodes, prefix.text.chars().count() as u32, context)); items } fn gen_label<'a>(node: &'a Label, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); items.extend(gen_node((&node.name).into(), context)); - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node((&node.value).into(), context)); items } @@ -219,7 +220,7 @@ fn gen_multi_line_items<'a>(nodes: Vec>, indent_width: u32, context: &m if i < count - 1 && !is_comment { node_items.push_condition(conditions::if_true("endLineText", is_multiline.create_resolver(), { let mut items = PrintItems::new(); - items.push_str(space_continuation); + items.push_sc(space_continuation); items })); } @@ -260,7 +261,7 @@ fn gen_multi_line_items<'a>(nodes: Vec>, indent_width: u32, context: &m fn gen_misc_instruction<'a>(node: &'a MiscInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); items.extend(gen_node((&node.instruction).into(), context)); - items.push_str(" "); + items.push_sc(sc!(" ")); items.extend(gen_node((&node.arguments).into(), context)); items } @@ -268,7 +269,7 @@ fn gen_misc_instruction<'a>(node: &'a MiscInstruction, context: &mut Context<'a> fn gen_run_instruction<'a>(node: &'a RunInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("RUN "); + items.push_sc(sc!("RUN ")); items.extend(match &node.expr { ShellOrExecExpr::Exec(node) => gen_node(node.into(), context), ShellOrExecExpr::Shell(node) => gen_node(node.into(), context), @@ -279,7 +280,7 @@ fn gen_run_instruction<'a>(node: &'a RunInstruction, context: &mut Context<'a>) fn gen_shell_instruction<'a>(node: &'a ShellInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("SHELL "); + items.push_sc(sc!("SHELL ")); items.extend(match &node.expr { ShellOrExecExpr::Exec(node) => gen_node(node.into(), context), ShellOrExecExpr::Shell(node) => gen_node(node.into(), context), @@ -289,24 +290,24 @@ fn gen_shell_instruction<'a>(node: &'a ShellInstruction, context: &mut Context<' fn gen_onbuild_instruction<'a>(node: &'a OnbuildInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("ONBUILD "); + items.push_sc(sc!("ONBUILD ")); items.extend(gen_node((&*node.instruction).into(), context)); items } fn gen_healthcheck_instruction<'a>(node: &'a HealthcheckInstruction, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("HEALTHCHECK "); + items.push_sc(sc!("HEALTHCHECK ")); for flag in &node.flags { - items.push_str("--"); + items.push_sc(sc!("--")); items.extend(gen_node((&flag.name).into(), context)); - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node((&flag.value).into(), context)); - items.push_str(" "); + items.push_sc(sc!(" ")); } match &node.cmd { Some(instruction) => items.extend(gen_node((&**instruction).into(), context)), - None => items.push_str("NONE"), + None => items.push_sc(sc!("NONE")), } items } @@ -323,25 +324,25 @@ fn gen_heredoc_instruction<'a>(node: &'a HeredocInstruction, context: &mut Conte fn gen_string_array<'a>(node: &'a StringArray, context: &mut Context<'a>) -> PrintItems { let mut items = PrintItems::new(); - items.push_str("["); + items.push_sc(sc!("[")); for (i, element) in node.elements.iter().enumerate() { items.extend(gen_node(element.into(), context)); if i < node.elements.len() - 1 { - items.push_str(", "); + items.push_sc(sc!(", ")); } } - items.push_str("]"); + items.push_sc(sc!("]")); items } /// The line-continuation marker for the file's escape character. -fn continuation(escape: char) -> &'static str { - if escape == '`' { "`" } else { "\\" } +fn continuation(escape: char) -> &'static StringContainer { + if escape == '`' { sc!("`") } else { sc!("\\") } } /// The line-continuation marker preceded by a separating space. -fn space_continuation(escape: char) -> &'static str { - if escape == '`' { " `" } else { " \\" } +fn space_continuation(escape: char) -> &'static StringContainer { + if escape == '`' { sc!(" `") } else { sc!(" \\") } } fn gen_breakable_string<'a>(node: &'a BreakableString, context: &mut Context<'a>) -> PrintItems { @@ -363,13 +364,13 @@ fn gen_breakable_string<'a>(node: &'a BreakableString, context: &mut Context<'a> let space_continuation = space_continuation(context.escape()); if use_quotes { - items.push_str("\""); + items.push_sc(sc!("\"")); } // when the breakable starts with a comment (e.g. `RUN \` followed by a // comment line), emit the line continuation so the comment stays attached to // the instruction instead of being dropped or turning the rest into a comment if matches!(node.components.first(), Some(BreakableStringComponent::Comment(_))) { - items.push_str(continuation); + items.push_sc(continuation); items.push_signal(Signal::NewLine); } for (i, component) in node.components.iter().enumerate() { @@ -389,16 +390,16 @@ fn gen_breakable_string<'a>(node: &'a BreakableString, context: &mut Context<'a> // part of the (kept) string content, so don't add a separator space let ends_in_quote = context.collapse_shell_ws && context.shell_quote.is_some(); if !use_quotes && !ends_in_quote && text.content.ends_with(" ") { - items.push_str(space_continuation); + items.push_sc(space_continuation); } else { - items.push_str(continuation); + items.push_sc(continuation); } } items.push_signal(Signal::NewLine); } } if use_quotes { - items.push_str("\""); + items.push_sc(sc!("\"")); } context.gen_string_content = previous_gen_string_content; @@ -537,9 +538,9 @@ fn collapse_shell_whitespace(text: &str, drop_leading: bool, quote: &mut Option< fn gen_copy_flag<'a>(node: &'a CopyFlag, context: &mut Context<'a>) -> PrintItems { // ex: --from=foo let mut items = PrintItems::new(); - items.push_str("--"); + items.push_sc(sc!("--")); items.extend(gen_node((&node.name).into(), context)); - items.push_str("="); + items.push_sc(sc!("=")); items.extend(gen_node((&node.value).into(), context)); items } diff --git a/src/wasm_plugin.rs b/src/wasm_plugin.rs index 7406f59..98eab40 100644 --- a/src/wasm_plugin.rs +++ b/src/wasm_plugin.rs @@ -1,13 +1,16 @@ use dprint_core::configuration::ConfigKeyMap; use dprint_core::configuration::GlobalConfiguration; -use dprint_core::configuration::ResolveConfigurationResult; use dprint_core::generate_plugin_code; +use dprint_core::plugins::CheckConfigUpdatesMessage; +use dprint_core::plugins::ConfigChange; use dprint_core::plugins::FileMatchingInfo; +use dprint_core::plugins::FormatError; use dprint_core::plugins::FormatResult; use dprint_core::plugins::PluginInfo; +use dprint_core::plugins::PluginResolveConfigurationResult; +use dprint_core::plugins::SyncFormatRequest; +use dprint_core::plugins::SyncHostFormatRequest; use dprint_core::plugins::SyncPluginHandler; -use dprint_core::plugins::SyncPluginInfo; -use std::path::Path; use super::configuration::Configuration; use super::configuration::resolve_config; @@ -15,21 +18,11 @@ use super::configuration::resolve_config; struct DockerfilePluginHandler; impl SyncPluginHandler for DockerfilePluginHandler { - fn resolve_config(&mut self, config: ConfigKeyMap, global_config: &GlobalConfiguration) -> ResolveConfigurationResult { - resolve_config(config, global_config) - } - - fn plugin_info(&mut self) -> SyncPluginInfo { - let version = env!("CARGO_PKG_VERSION").to_string(); - SyncPluginInfo { - info: PluginInfo { - name: env!("CARGO_PKG_NAME").to_string(), - version: version.clone(), - config_key: "dockerfile".to_string(), - help_url: "https://dprint.dev/plugins/dockerfile".to_string(), - config_schema_url: format!("https://plugins.dprint.dev/dprint/dprint-plugin-dockerfile/{}/schema.json", version), - update_url: Some("https://plugins.dprint.dev/dprint/dprint-plugin-dockerfile/latest.json".to_string()), - }, + fn resolve_config(&mut self, config: ConfigKeyMap, global_config: &GlobalConfiguration) -> PluginResolveConfigurationResult { + let result = resolve_config(config, global_config); + PluginResolveConfigurationResult { + config: result.config, + diagnostics: result.diagnostics, file_matching: FileMatchingInfo { file_extensions: vec!["dockerfile".to_string()], file_names: vec!["Dockerfile".to_string()], @@ -37,19 +30,29 @@ impl SyncPluginHandler for DockerfilePluginHandler { } } + fn plugin_info(&mut self) -> PluginInfo { + let version = env!("CARGO_PKG_VERSION").to_string(); + PluginInfo { + name: env!("CARGO_PKG_NAME").to_string(), + version: version.clone(), + config_key: "dockerfile".to_string(), + help_url: "https://dprint.dev/plugins/dockerfile".to_string(), + config_schema_url: format!("https://plugins.dprint.dev/dprint/dprint-plugin-dockerfile/{}/schema.json", version), + update_url: Some("https://plugins.dprint.dev/dprint/dprint-plugin-dockerfile/latest.json".to_string()), + } + } + + fn check_config_updates(&self, _message: CheckConfigUpdatesMessage) -> Result, FormatError> { + Ok(Vec::new()) + } + fn license_text(&mut self) -> String { std::str::from_utf8(include_bytes!("../LICENSE")).unwrap().into() } - fn format( - &mut self, - file_path: &Path, - file_bytes: Vec, - config: &Configuration, - _format_with_host: impl FnMut(&Path, Vec, &ConfigKeyMap) -> FormatResult, - ) -> FormatResult { - let file_text = String::from_utf8(file_bytes)?; - let result = super::format_text(file_path, &file_text, config)?; + fn format(&mut self, request: SyncFormatRequest, _format_with_host: impl FnMut(SyncHostFormatRequest) -> FormatResult) -> FormatResult { + let file_text = String::from_utf8(request.file_bytes)?; + let result = super::format_text(request.file_path, &file_text, request.config).map_err(FormatError::new)?; Ok(result.map(|file_text| file_text.into_bytes())) } } diff --git a/tests/test.rs b/tests/test.rs index c8b1d4a..9e47682 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -4,6 +4,7 @@ extern crate dprint_plugin_dockerfile; //#[macro_use] extern crate debug_here; use std::path::PathBuf; +use std::sync::Arc; // use std::time::Instant; use dprint_core::configuration::*; @@ -27,15 +28,15 @@ fn test_specs() { }, { let global_config = global_config.clone(); - move |file_path, file_text, spec_config| { + Arc::new(move |file_path, file_text, spec_config| { let spec_config: ConfigKeyMap = serde_json::from_value(spec_config.clone().into()).unwrap(); let config_result = resolve_config(spec_config, &global_config); ensure_no_diagnostics(&config_result.diagnostics); format_text(file_path, file_text, &config_result.config).map_err(Into::into) - } + }) }, - move |_file_path, _file_text, _spec_config| { + Arc::new(move |_file_path, _file_text, _spec_config| { #[cfg(feature = "tracing")] { let config_result = resolve_config(parse_config_key_map(_spec_config), &global_config); @@ -45,6 +46,6 @@ fn test_specs() { #[cfg(not(feature = "tracing"))] panic!("\n====\nPlease run with `cargo test --features tracing` to get trace output\n====\n") - }, + }), ) } From 25ce7a1a9cf7fe9e8f9c4792f01db5f5d0df9762 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 8 Jun 2026 15:03:42 -0400 Subject: [PATCH 2/3] update --- deployment/npm/package-lock.json | 37 ++++++++++++++++++++------------ deployment/npm/package.json | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/deployment/npm/package-lock.json b/deployment/npm/package-lock.json index 21a9913..77156e8 100644 --- a/deployment/npm/package-lock.json +++ b/deployment/npm/package-lock.json @@ -1,14 +1,23 @@ -{ - "name": "@dprint/dockerfile", - "version": "0.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@dprint/formatter": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@dprint/formatter/-/formatter-0.1.4.tgz", - "integrity": "sha512-L7PifpVn+u1fH+5jUNv6W2Ie5LYvG5rlXCB9hn/byozAj1WOjaZczwvWmYWNS2zObF3d+PjKf6ON+HCPHjqNvQ==", - "dev": true - } - } -} +{ + "name": "@dprint/dockerfile", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@dprint/dockerfile", + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "@dprint/formatter": "~0.5.1" + } + }, + "node_modules/@dprint/formatter": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@dprint/formatter/-/formatter-0.5.1.tgz", + "integrity": "sha512-cdZUrm0iv/FnnY3CKE2dEcVhNEzrC551aE2h2mTFwQCRBrqyARLDnb7D+3PlXTUVp3s34ftlnGOVCmhLT9DeKA==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/deployment/npm/package.json b/deployment/npm/package.json index 918340d..66826ba 100644 --- a/deployment/npm/package.json +++ b/deployment/npm/package.json @@ -24,6 +24,6 @@ "test": "node index.test.js" }, "devDependencies": { - "@dprint/formatter": "~0.1.4" + "@dprint/formatter": "~0.5.1" } } From 4ba36549cd3fb116c4e000afa2fa453e18b03c6d Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 8 Jun 2026 15:06:51 -0400 Subject: [PATCH 3/3] fix --- deployment/npm/index.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deployment/npm/index.test.js b/deployment/npm/index.test.js index f6f4895..842ec64 100644 --- a/deployment/npm/index.test.js +++ b/deployment/npm/index.test.js @@ -5,6 +5,9 @@ const getPath = require("./index").getPath; const buffer = require("fs").readFileSync(getPath()); const formatter = createFromBuffer(buffer); -const result = formatter.formatText("file.dockerfile", "RUN /bin/bash"); +const result = formatter.formatText({ + filePath: "file.dockerfile", + fileText: "RUN /bin/bash", +}); assert.strictEqual(result, "RUN /bin/bash\n");