From ee054657eef97f1c77e485d01376a7d2f043cebb Mon Sep 17 00:00:00 2001 From: DevinR Date: Thu, 7 Dec 2023 19:58:57 -0500 Subject: [PATCH 1/5] Fix reamaining issues with array newlines and equal sign spaces --- examp/equal_sign.toml | 14 +++++++++ src/fmt.rs | 67 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 examp/equal_sign.toml diff --git a/examp/equal_sign.toml b/examp/equal_sign.toml new file mode 100644 index 0000000..4611241 --- /dev/null +++ b/examp/equal_sign.toml @@ -0,0 +1,14 @@ +# oh yea +[dependencies] +c="0" +d="0" +a="0" +b="0" + +[dependencies.alpha] +version ="0.15" +default-features =false +more-stuff ={sub = false, object = 10 } +dot.key = "foo" +dot.no.space = true +features =["full", "parsing", "printing", "visit-mut"] diff --git a/src/fmt.rs b/src/fmt.rs index a10f5be..bf236fe 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -2,6 +2,11 @@ use std::str::FromStr; use toml_edit::{Document, Item, RawString, Table, Value}; +#[cfg(target_os = "windows")] +const NEWLINE_PATTERN: &str = "\r\n"; +#[cfg(not(target_os = "windows"))] +const NEWLINE_PATTERN: &str = "\n"; + /// The config file for formatting toml after sorting. /// /// Use the `FromStr` to create a config from a string. @@ -34,6 +39,16 @@ pub struct Config { /// Defaults to `false`. pub compact_arrays: bool, + /// Max line length before arrays are broken up with newlines. + /// + /// Defaults to 80. + pub max_array_line_len: usize, + + /// Number of spaces to indent for arrays broken up with newlines. + /// + /// Defaults to 4. + pub indent_count: usize, + /// Omit whitespace padding inside inline tables. /// /// Defaults to `false`. @@ -73,6 +88,8 @@ impl Config { Self { always_trailing_comma: false, multiline_trailing_comma: true, + max_array_line_len: 80, + indent_count: 4, space_around_eq: true, compact_arrays: false, compact_inline_tables: false, @@ -107,6 +124,14 @@ impl FromStr for Config { .get("multiline_trailing_comma") .and_then(toml_edit::Item::as_bool) .unwrap_or_default(), + max_array_line_len: toml + .get("max_array_line_len") + .and_then(toml_edit::Item::as_integer) + .unwrap_or_default() as usize, + indent_count: toml + .get("indent_count") + .and_then(toml_edit::Item::as_integer) + .unwrap_or(4) as usize, space_around_eq: toml .get("space_around_eq") .and_then(toml_edit::Item::as_bool) @@ -147,11 +172,30 @@ impl FromStr for Config { fn fmt_value(value: &mut Value, config: &Config) { match value { Value::Array(arr) => { - // TODO if multi line trailing comma and compact array + if arr.to_string().len() > config.max_array_line_len { + let len = arr.len(); + for (i, val) in arr.iter_mut().enumerate() { + val.decor_mut().set_prefix(format!( + "{}{}", + NEWLINE_PATTERN, + " ".repeat(config.indent_count) + )); + if i == (len - 1) { + val.decor_mut().set_suffix(format!( + "{}{}", + if config.multiline_trailing_comma { "," } else { "" }, + NEWLINE_PATTERN + )); + } + } + } else { + arr.fmt(); + } + arr.decor_mut().set_prefix(" "); arr.set_trailing_comma(config.always_trailing_comma); - arr.fmt(); } Value::InlineTable(table) => { + table.decor_mut().set_prefix(" "); table.fmt(); } // Since the above variants have fmt methods we can only ever @@ -170,10 +214,6 @@ fn fmt_value(value: &mut Value, config: &Config) { } fn fmt_table(table: &mut Table, config: &Config) { - #[cfg(target_os = "windows")] - const NEWLINE_PATTERN: &'static str = "\r\n"; - #[cfg(not(target_os = "windows"))] - const NEWLINE_PATTERN: &str = "\n"; // Checks the header decor for blank lines let blank_header_lines = table .decor() @@ -194,6 +234,16 @@ fn fmt_table(table: &mut Table, config: &Config) { let keys: Vec<_> = table.iter().map(|(k, _)| k.to_owned()).collect(); for key in keys { + println!( + "key {} {} val: {:?}", + key, + table.get(&key).map_or(false, |item| item.is_value()), + table.get(&key) + ); + let is_value_for_space = table.get(&key).map_or(false, |item| { + item.is_value() && item.as_inline_table().map_or(true, |t| !t.is_dotted()) + }); + let dec = table.key_decor_mut(&key).unwrap(); let prefix = dec.prefix().and_then(RawString::as_str).unwrap_or(""); let blank_lines = prefix.lines().filter(|l| !l.starts_with('#')).count(); @@ -217,15 +267,16 @@ fn fmt_table(table: &mut Table, config: &Config) { // This is weirdly broken, inserts underscores into `[foo.bar]` table // headers. Revisit later. - /* if config.space_around_eq + if config.space_around_eq && dec.suffix().and_then(RawString::as_str).map_or(true, str::is_empty) + && is_value_for_space { dec.set_suffix(format!( "{}{}", dec.suffix().and_then(RawString::as_str).unwrap_or(""), ' ' )); - } */ + } match table.get_mut(&key).unwrap() { Item::Table(table) => { From a4399565fe346fb14b239d9a54bb42c0e527edb5 Mon Sep 17 00:00:00 2001 From: DevinR Date: Fri, 8 Dec 2023 12:06:40 -0500 Subject: [PATCH 2/5] Fix getting newline happy in arrays --- examp/ru.toml | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/fmt.rs | 17 +-- 2 files changed, 291 insertions(+), 8 deletions(-) create mode 100644 examp/ru.toml diff --git a/examp/ru.toml b/examp/ru.toml new file mode 100644 index 0000000..d187954 --- /dev/null +++ b/examp/ru.toml @@ -0,0 +1,282 @@ +[package] +name = "ruma" +categories = ["api-bindings", "web-programming"] +keywords = ["matrix", "chat", "messaging", "ruma"] +description = "Types and traits for working with the Matrix protocol." +homepage = "https://ruma.io/" +repository = "https://github.com/ruma/ruma" +readme = "README.md" +license = "MIT" +version = "0.9.4" +edition = "2021" +rust-version = { workspace = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[features] +api = ["ruma-common/api"] +canonical-json = ["ruma-common/canonical-json", "ruma-events?/canonical-json"] +client = ["dep:ruma-client"] +events = ["dep:ruma-events"] +server-util = ["dep:ruma-server-util"] +signatures = ["dep:ruma-signatures", "canonical-json"] +state-res = ["dep:ruma-state-res"] + +# ruma-client feature flags +client-ext-client-api = ["client", "ruma-client?/client-api"] +client-hyper = ["client", "ruma-client?/hyper"] +client-hyper-native-tls = ["client", "ruma-client?/hyper-native-tls"] +client-isahc = ["client", "ruma-client?/isahc"] +client-reqwest = ["client", "ruma-client?/reqwest"] +client-reqwest-native-tls = ["client", "ruma-client?/reqwest-native-tls"] +client-reqwest-native-tls-vendored = ["client", "ruma-client?/reqwest-native-tls-vendored"] +client-reqwest-rustls-manual-roots = ["client", "ruma-client?/reqwest-rustls-manual-roots"] +client-reqwest-rustls-webpki-roots = ["client", "ruma-client?/reqwest-rustls-webpki-roots"] +client-reqwest-rustls-native-roots = ["client", "ruma-client?/reqwest-rustls-native-roots"] + +appservice-api-c = ["api", "events", "dep:ruma-appservice-api", "ruma-appservice-api?/client"] +appservice-api-s = ["api", "events", "dep:ruma-appservice-api", "ruma-appservice-api?/server"] +appservice-api = ["appservice-api-c", "appservice-api-s"] + +client-api-c = ["api", "events", "dep:ruma-client-api", "ruma-client-api?/client"] +client-api-s = ["api", "events", "dep:ruma-client-api", "ruma-client-api?/server"] +client-api = ["client-api-c", "client-api-s"] + +federation-api-c = ["api", "signatures", "dep:ruma-federation-api", "ruma-federation-api?/client"] +federation-api-s = ["api", "signatures", "dep:ruma-federation-api", "ruma-federation-api?/server"] +federation-api = ["federation-api-c", "federation-api-s"] + +identity-service-api-c = [ + "api", + "dep:ruma-identity-service-api", + "ruma-identity-service-api?/client", +] +identity-service-api-s = [ + "api", + "dep:ruma-identity-service-api", + "ruma-identity-service-api?/server", +] +identity-service-api = ["identity-service-api-c", "identity-service-api-s"] + +push-gateway-api-c = ["api", "dep:ruma-push-gateway-api", "ruma-push-gateway-api?/client"] +push-gateway-api-s = ["api", "dep:ruma-push-gateway-api", "ruma-push-gateway-api?/server"] +push-gateway-api = ["push-gateway-api-c", "push-gateway-api-s"] + +# Required for randomness, current system time in browser environments +js = ["ruma-common/js"] + +# Convenience features +rand = ["ruma-common/rand"] +markdown = ["ruma-events?/markdown"] +html = ["dep:ruma-html", "ruma-events?/html"] + +# Everything except compat, js and unstable features +full = [ + "api", + "client", + "client-ext-client-api", + "events", + "signatures", + "state-res", + "appservice-api", + "client-api", + "federation-api", + "identity-service-api", + "push-gateway-api", + "rand", + "markdown", + "html", +] + +# Enable all compatibility hacks. Deprecated. +compat = [ + "compat-key-id", + "compat-user-id", + "compat-empty-string-null", + "compat-null", + "compat-optional", + "compat-unset-avatar", + "compat-get-3pids", + "compat-signature-id", + "compat-tag-info", +] + +# Allow IDs to exceed 255 bytes. +compat-arbitrary-length-ids = ["ruma-common/compat-arbitrary-length-ids"] + +# Don't validate the version part in `KeyId`. +compat-key-id = ["ruma-common/compat-key-id"] + +# Allow some user IDs that are invalid even with the specified historical +# user ID scheme. +compat-user-id = ["ruma-common/compat-user-id"] + +# Allow some mandatory fields in requests / responses to be missing, defaulting +# them to an empty string in deserialization. +compat-empty-string-null = [ + "ruma-common/compat-empty-string-null", + "ruma-client-api?/compat-empty-string-null", + "ruma-events?/compat-empty-string-null", + "ruma-federation-api?/compat-empty-string-null", +] + +# Allow certain fields to be `null` for compatibility, treating that the same as +# the field being absent. +compat-null = ["ruma-common/compat-null"] + +# Allow certain fields to be absent even though the spec marks them as +# mandatory. Deserialization will yield a default value like an empty string. +compat-optional = ["ruma-common/compat-optional", "ruma-events?/compat-optional"] + +# Unset avatars by sending an empty string, same as what Element Web does, c.f. +# https://github.com/matrix-org/matrix-spec/issues/378#issuecomment-1055831264 +compat-unset-avatar = ["ruma-client-api?/compat-unset-avatar"] + +# Always serialize the threepids response field in `get_3pids::v3::Response`, +# even if its value is an empty list. +compat-get-3pids = ["ruma-client-api?/compat-get-3pids"] + +# Accept `message` as an alias for `error` in `upload_signatures::v3::Failure`, +# since that's what Synapse sends. +compat-upload-signatures = ["ruma-client-api?/compat-upload-signatures"] + +# Allow extra characters in signature IDs not allowed in the specification. +compat-signature-id = ["ruma-signatures?/compat-signature-id"] + +# Allow TagInfo to contain a stringified floating-point value for the `order` field. +compat-tag-info = ["ruma-events?/compat-tag-info"] + +# Specific compatibility for past ring public/private key documents. +ring-compat = ["dep:ruma-signatures", "ruma-signatures?/ring-compat"] + +# unstable: by using any of these, you opt out of all semver guarantees Ruma +# otherwise provides! +unstable-exhaustive-types = [ + "ruma-common/unstable-exhaustive-types", + "ruma-appservice-api?/unstable-exhaustive-types", + "ruma-client-api?/unstable-exhaustive-types", + "ruma-federation-api?/unstable-exhaustive-types", + "ruma-identity-service-api?/unstable-exhaustive-types", + "ruma-push-gateway-api?/unstable-exhaustive-types", + "ruma-state-res?/unstable-exhaustive-types", + "ruma-events?/unstable-exhaustive-types", +] +unstable-extensible-events = [ + "unstable-msc3246", + "unstable-msc3488", + "unstable-msc3553", + "unstable-msc3954", + "unstable-msc3955", +] +unstable-msc1767 = ["ruma-events?/unstable-msc1767"] +unstable-msc2409 = ["ruma-appservice-api?/unstable-msc2409"] +unstable-msc2448 = [ + "ruma-client-api?/unstable-msc2448", + "ruma-events?/unstable-msc2448", + "ruma-federation-api?/unstable-msc2448", +] +unstable-msc2654 = ["ruma-client-api?/unstable-msc2654"] +unstable-msc2666 = ["ruma-client-api?/unstable-msc2666"] +unstable-msc2747 = ["ruma-events?/unstable-msc2747"] +unstable-msc2870 = ["ruma-common/unstable-msc2870"] +unstable-msc2965 = ["ruma-client-api?/unstable-msc2965"] +unstable-msc2967 = ["ruma-client-api?/unstable-msc2967"] +unstable-msc3061 = ["ruma-events?/unstable-msc3061"] +unstable-msc3202 = ["ruma-appservice-api?/unstable-msc3202"] +unstable-msc3245 = ["ruma-events?/unstable-msc3245"] +# Support the m.room.message fallback fields from the first version of MSC3245, +# implemented in Element Web and documented at +# https://github.com/matrix-org/matrix-spec-proposals/blob/83f6c5b469c1d78f714e335dcaa25354b255ffa5/proposals/3245-voice-messages.md +unstable-msc3245-v1-compat = ["ruma-events?/unstable-msc3245-v1-compat"] +unstable-msc3246 = ["ruma-events?/unstable-msc3246"] +unstable-msc3381 = ["ruma-events?/unstable-msc3381"] +unstable-msc3401 = ["ruma-events?/unstable-msc3401"] +unstable-msc3488 = ["ruma-client-api?/unstable-msc3488", "ruma-events?/unstable-msc3488"] +unstable-msc3551 = ["ruma-events?/unstable-msc3551"] +unstable-msc3552 = ["ruma-events?/unstable-msc3552"] +unstable-msc3553 = ["ruma-events?/unstable-msc3553"] +unstable-msc3554 = ["ruma-events?/unstable-msc3554"] +unstable-msc3575 = ["ruma-client-api?/unstable-msc3575"] +unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"] +unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"] +unstable-msc3814 = ["ruma-client-api?/unstable-msc3814"] +unstable-msc3927 = ["ruma-events?/unstable-msc3927"] +unstable-msc3930 = ["ruma-common/unstable-msc3930"] +unstable-msc3931 = ["ruma-common/unstable-msc3931"] +unstable-msc3932 = ["ruma-common/unstable-msc3932"] +unstable-msc3954 = ["ruma-events?/unstable-msc3954"] +unstable-msc3955 = ["ruma-events?/unstable-msc3955"] +unstable-msc3956 = ["ruma-events?/unstable-msc3956"] +unstable-msc3983 = ["ruma-client-api?/unstable-msc3983"] +unstable-msc4075 = ["ruma-events?/unstable-msc4075"] +unstable-pdu = ["ruma-events?/unstable-pdu"] +unstable-unspecified = [ + "ruma-common/unstable-unspecified", + "ruma-federation-api?/unstable-unspecified", + "ruma-push-gateway-api?/unstable-unspecified", +] + +# Private feature, only used in test / benchmarking code +__ci = [ + "full", + "compat-upload-signatures", + "unstable-unspecified", + "unstable-msc1767", + "unstable-msc2409", + "unstable-msc2448", + "unstable-msc2654", + "unstable-msc2666", + "unstable-msc2747", + "unstable-msc2870", + "unstable-msc2965", + "unstable-msc2967", + "unstable-msc3061", + "unstable-msc3202", + "unstable-msc3245", + "unstable-msc3245-v1-compat", + "unstable-msc3246", + "unstable-msc3381", + "unstable-msc3401", + "unstable-msc3488", + "unstable-msc3551", + "unstable-msc3552", + "unstable-msc3553", + "unstable-msc3554", + "unstable-msc3575", + "unstable-msc3618", + "unstable-msc3723", + "unstable-msc3814", + "unstable-msc3927", + "unstable-msc3930", + "unstable-msc3932", + "unstable-msc3954", + "unstable-msc3955", + "unstable-msc3956", + "unstable-msc3983", + "unstable-msc4075", +] + +[dependencies] +assign = { workspace = true } +js_int = { workspace = true } +js_option = "0.1.1" + +ruma-common = { workspace = true } + +ruma-client = { workspace = true, optional = true } +ruma-events = { workspace = true, optional = true } +ruma-html = { workspace = true, optional = true } +ruma-server-util = { workspace = true, optional = true } +ruma-signatures = { workspace = true, optional = true } +ruma-state-res = { workspace = true, optional = true } + +ruma-appservice-api = { workspace = true, optional = true } +ruma-client-api = { workspace = true, optional = true } +ruma-federation-api = { workspace = true, optional = true } +ruma-identity-service-api = { workspace = true, optional = true } +ruma-push-gateway-api = { workspace = true, optional = true } + +[dev-dependencies] +serde = { workspace = true } diff --git a/src/fmt.rs b/src/fmt.rs index bf236fe..deaf9a7 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -127,7 +127,7 @@ impl FromStr for Config { max_array_line_len: toml .get("max_array_line_len") .and_then(toml_edit::Item::as_integer) - .unwrap_or_default() as usize, + .unwrap_or(80) as usize, indent_count: toml .get("indent_count") .and_then(toml_edit::Item::as_integer) @@ -173,6 +173,7 @@ fn fmt_value(value: &mut Value, config: &Config) { match value { Value::Array(arr) => { if arr.to_string().len() > config.max_array_line_len { + let arr_has_trailing_newline = arr.trailing().as_str().map_or(false, |s| s.contains('\n')); let len = arr.len(); for (i, val) in arr.iter_mut().enumerate() { val.decor_mut().set_prefix(format!( @@ -184,14 +185,16 @@ fn fmt_value(value: &mut Value, config: &Config) { val.decor_mut().set_suffix(format!( "{}{}", if config.multiline_trailing_comma { "," } else { "" }, - NEWLINE_PATTERN + if !arr_has_trailing_newline { NEWLINE_PATTERN } else { "" } )); } } } else { arr.fmt(); } + // TODO: this is most likely after an equal sign but not always... arr.decor_mut().set_prefix(" "); + // TODO: can this be moved into the else of the above if/else arr.set_trailing_comma(config.always_trailing_comma); } Value::InlineTable(table) => { @@ -234,12 +237,6 @@ fn fmt_table(table: &mut Table, config: &Config) { let keys: Vec<_> = table.iter().map(|(k, _)| k.to_owned()).collect(); for key in keys { - println!( - "key {} {} val: {:?}", - key, - table.get(&key).map_or(false, |item| item.is_value()), - table.get(&key) - ); let is_value_for_space = table.get(&key).map_or(false, |item| { item.is_value() && item.as_inline_table().map_or(true, |t| !t.is_dotted()) }); @@ -379,3 +376,7 @@ mod test { // println!("{}", toml.to_string()); } } + +// Array { trailing: "\n", trailing_comma: true, decor: Decor { prefix: " ", suffix: empty }, span: None, values: [Value(String(Formatted { value: "unstable-msc3246", repr: "\"unstable-msc3246\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3488", repr: "\"unstable-msc3488\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3553", repr: "\"unstable-msc3553\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3954", repr: "\"unstable-msc3954\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3955", repr: "\"unstable-msc3955\"", decor: Decor { prefix: "\n ", suffix: empty } }))] } + +// Array { trailing: "\n", trailing_comma: true, decor: Decor { prefix: " ", suffix: empty }, span: None, values: [Value(String(Formatted { value: "unstable-msc3246", repr: "\"unstable-msc3246\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3488", repr: "\"unstable-msc3488\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3553", repr: "\"unstable-msc3553\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3954", repr: "\"unstable-msc3954\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3955", repr: "\"unstable-msc3955\"", decor: Decor { prefix: "\r\n ", suffix: ",\r\n" } }))] } From dc64b969c938329bd62013f755659b32f09fd262 Mon Sep 17 00:00:00 2001 From: DevinR Date: Fri, 8 Dec 2023 12:07:08 -0500 Subject: [PATCH 3/5] Add documentation for new tomlfmt options and missing cmd option --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 0a705c4..eb8c351 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ There are three modes cargo-sort can be used in: - Will fail with a non-zero exit code if the file is unsorted. * **-n or --no-format** - Will **NOT** format the sorted toml. This option only has an effect if writing or printing out. + * **--check-format** + - Checks that after sorting the original input file has not changed. * **-g or --grouped** - When sorting keep table key value spacing. If you have dependency groups they will stick but be sorted within the grouping. The `key_value_newlines` config option needs to be `true` for this to have any effect. @@ -36,6 +38,11 @@ Here are the defaults when no `tomlfmt.toml` is found always_trailing_comma = false # trailing comma when multi-line multiline_trailing_comma = true +# the maximum length in bytes of the string of an array object +max_array_line_len = 80 +# number of spaces to indent +indent_count = 4 +# space around equal sign space_around_eq = true # remove all the spacing inside the array compact_arrays = false From eb41df776c74a8561f8486ccb59dfe65399e5684 Mon Sep 17 00:00:00 2001 From: DevinR Date: Fri, 8 Dec 2023 12:15:35 -0500 Subject: [PATCH 4/5] Remove dev comments --- src/fmt.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/fmt.rs b/src/fmt.rs index deaf9a7..39f7d6f 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -376,7 +376,3 @@ mod test { // println!("{}", toml.to_string()); } } - -// Array { trailing: "\n", trailing_comma: true, decor: Decor { prefix: " ", suffix: empty }, span: None, values: [Value(String(Formatted { value: "unstable-msc3246", repr: "\"unstable-msc3246\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3488", repr: "\"unstable-msc3488\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3553", repr: "\"unstable-msc3553\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3954", repr: "\"unstable-msc3954\"", decor: Decor { prefix: "\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3955", repr: "\"unstable-msc3955\"", decor: Decor { prefix: "\n ", suffix: empty } }))] } - -// Array { trailing: "\n", trailing_comma: true, decor: Decor { prefix: " ", suffix: empty }, span: None, values: [Value(String(Formatted { value: "unstable-msc3246", repr: "\"unstable-msc3246\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3488", repr: "\"unstable-msc3488\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3553", repr: "\"unstable-msc3553\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3954", repr: "\"unstable-msc3954\"", decor: Decor { prefix: "\r\n ", suffix: empty } })), Value(String(Formatted { value: "unstable-msc3955", repr: "\"unstable-msc3955\"", decor: Decor { prefix: "\r\n ", suffix: ",\r\n" } }))] } From 5350a09ff63e93cfa86aa398826503466340c58f Mon Sep 17 00:00:00 2001 From: DevinR Date: Fri, 8 Dec 2023 12:19:05 -0500 Subject: [PATCH 5/5] Run cargo fmt --- src/fmt.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fmt.rs b/src/fmt.rs index 39f7d6f..7dde105 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -173,7 +173,8 @@ fn fmt_value(value: &mut Value, config: &Config) { match value { Value::Array(arr) => { if arr.to_string().len() > config.max_array_line_len { - let arr_has_trailing_newline = arr.trailing().as_str().map_or(false, |s| s.contains('\n')); + let arr_has_trailing_newline = + arr.trailing().as_str().map_or(false, |s| s.contains('\n')); let len = arr.len(); for (i, val) in arr.iter_mut().enumerate() { val.decor_mut().set_prefix(format!(