mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 20:53:06 +00:00
fix: only apply comments if relevant
This commit is contained in:
parent
fa9ebe17cc
commit
19e6e43358
6 changed files with 35 additions and 1 deletions
|
@ -127,7 +127,9 @@ impl Buffer {
|
|||
for child in children {
|
||||
// Exprs handle their own indenting/line breaks
|
||||
if !matches!(child, BodyNode::RawExpr(_)) {
|
||||
self.write_comments(child.span())?;
|
||||
if self.current_span_is_primary(child.span()) {
|
||||
self.write_comments(child.span())?;
|
||||
}
|
||||
self.tabbed_line()?;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,3 +23,4 @@ twoway! ("complex" => complex);
|
|||
twoway! ("tiny" => tiny);
|
||||
|
||||
twoway! ("tinynoopt" => tinynoopt);
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
rsx! {
|
||||
div {
|
||||
// Comments
|
||||
class: "asdasd",
|
||||
"hello world"
|
||||
}
|
||||
div {
|
||||
// My comment here 1
|
||||
// My comment here 2
|
||||
|
|
14
packages/autofmt/tests/wrong.rs
Normal file
14
packages/autofmt/tests/wrong.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
macro_rules! twoway {
|
||||
($val:literal => $name:ident) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
let src_right = include_str!(concat!("./wrong/", $val, ".rsx"));
|
||||
let src_wrong = include_str!(concat!("./wrong/", $val, ".wrong.rsx"));
|
||||
let formatted = dioxus_autofmt::fmt_file(src_wrong);
|
||||
let out = dioxus_autofmt::apply_formats(src_wrong, formatted);
|
||||
pretty_assertions::assert_eq!(&src_right, &out);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
twoway!("comments" => comments);
|
7
packages/autofmt/tests/wrong/comments.rsx
Normal file
7
packages/autofmt/tests/wrong/comments.rsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
rsx! {
|
||||
div {
|
||||
// Comments
|
||||
class: "asdasd",
|
||||
"hello world"
|
||||
}
|
||||
}
|
5
packages/autofmt/tests/wrong/comments.wrong.rsx
Normal file
5
packages/autofmt/tests/wrong/comments.wrong.rsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
rsx! {
|
||||
div {
|
||||
// Comments
|
||||
class: "asdasd", "hello world" }
|
||||
}
|
Loading…
Reference in a new issue