From 3945928c595b16529966c3e310f9227c29709452 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 13 Jan 2023 17:16:06 -0800 Subject: [PATCH] fix: adjust padding on autofmt --- packages/autofmt/src/writer.rs | 10 +++++----- packages/autofmt/tests/samples.rs | 3 ++- packages/autofmt/tests/samples/reallylong.rsx | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 packages/autofmt/tests/samples/reallylong.rsx diff --git a/packages/autofmt/src/writer.rs b/packages/autofmt/src/writer.rs index 9e507ed70..cdbdbed45 100644 --- a/packages/autofmt/src/writer.rs +++ b/packages/autofmt/src/writer.rs @@ -135,16 +135,16 @@ impl Writer<'_> { total += match &attr.attr { ElementAttr::AttrText { value, name } => { - value.source.as_ref().unwrap().value().len() + name.span().line_length() + 3 + value.source.as_ref().unwrap().value().len() + name.span().line_length() + 6 } ElementAttr::AttrExpression { name, value } => { - value.span().line_length() + name.span().line_length() + 3 + value.span().line_length() + name.span().line_length() + 6 } ElementAttr::CustomAttrText { value, name } => { - value.source.as_ref().unwrap().value().len() + name.value().len() + 3 + value.source.as_ref().unwrap().value().len() + name.value().len() + 6 } ElementAttr::CustomAttrExpression { name, value } => { - name.value().len() + value.span().line_length() + 3 + name.value().len() + value.span().line_length() + 6 } ElementAttr::EventTokens { tokens, name } => { let location = Location::new(tokens.span().start()); @@ -164,7 +164,7 @@ impl Writer<'_> { self.cached_formats[&location].len() }; - len + name.span().line_length() + 3 + len + name.span().line_length() + 6 } }; } diff --git a/packages/autofmt/tests/samples.rs b/packages/autofmt/tests/samples.rs index c9489d7d0..0c031c0d2 100644 --- a/packages/autofmt/tests/samples.rs +++ b/packages/autofmt/tests/samples.rs @@ -36,5 +36,6 @@ twoway![ messy_indent, long_exprs, ifchain_forloop, - t2 + t2, + reallylong ]; diff --git a/packages/autofmt/tests/samples/reallylong.rsx b/packages/autofmt/tests/samples/reallylong.rsx new file mode 100644 index 000000000..6de13287f --- /dev/null +++ b/packages/autofmt/tests/samples/reallylong.rsx @@ -0,0 +1,18 @@ +pub static Icon3: Component<()> = |cx| { + cx.render(rsx!(svg { class: "w-6 h-6", + stroke_linecap: "round", + fill: "none", + stroke_linejoin: "round", + stroke_width: "2", + stroke: "currentColor", + view_box: "0 0 24 24", + path { + d: "M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2", + } + circle { + cx: "12", + cy: "7", + r: "4", + } + })) +};