瀏覽代碼

fix: adjust padding on autofmt

Jonathan Kelley 2 年之前
父節點
當前提交
3945928c59
共有 3 個文件被更改,包括 25 次插入6 次删除
  1. 5 5
      packages/autofmt/src/writer.rs
  2. 2 1
      packages/autofmt/tests/samples.rs
  3. 18 0
      packages/autofmt/tests/samples/reallylong.rsx

+ 5 - 5
packages/autofmt/src/writer.rs

@@ -135,16 +135,16 @@ impl Writer<'_> {
 
 
             total += match &attr.attr {
             total += match &attr.attr {
                 ElementAttr::AttrText { value, name } => {
                 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 } => {
                 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 } => {
                 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 } => {
                 ElementAttr::CustomAttrExpression { name, value } => {
-                    name.value().len() + value.span().line_length() + 3
+                    name.value().len() + value.span().line_length() + 6
                 }
                 }
                 ElementAttr::EventTokens { tokens, name } => {
                 ElementAttr::EventTokens { tokens, name } => {
                     let location = Location::new(tokens.span().start());
                     let location = Location::new(tokens.span().start());
@@ -164,7 +164,7 @@ impl Writer<'_> {
                         self.cached_formats[&location].len()
                         self.cached_formats[&location].len()
                     };
                     };
 
 
-                    len + name.span().line_length() + 3
+                    len + name.span().line_length() + 6
                 }
                 }
             };
             };
         }
         }

+ 2 - 1
packages/autofmt/tests/samples.rs

@@ -36,5 +36,6 @@ twoway![
     messy_indent,
     messy_indent,
     long_exprs,
     long_exprs,
     ifchain_forloop,
     ifchain_forloop,
-    t2
+    t2,
+    reallylong
 ];
 ];

+ 18 - 0
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",
+        }
+    }))
+};