mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
feat: inline attr-set comments
This commit is contained in:
parent
ba78351e90
commit
8db5bbf5c6
3 changed files with 39 additions and 4 deletions
|
@ -74,20 +74,28 @@ pub fn rule(
|
|||
}
|
||||
|
||||
let mut item_index: usize = 0;
|
||||
let mut inline_next_comment = false;
|
||||
|
||||
loop {
|
||||
// /**/
|
||||
children.drain_comments_and_newlines(|element| match element {
|
||||
crate::children::DrainCommentOrNewline::Comment(text) => {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
if inline_next_comment && text.starts_with("#") {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
item_index += 1;
|
||||
inline_next_comment = false;
|
||||
}
|
||||
crate::children::DrainCommentOrNewline::Newline(newlines) => {
|
||||
if newlines > 1 && item_index > 0 && item_index < items_count {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
}
|
||||
|
||||
inline_next_comment = newlines == 0;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -115,6 +123,7 @@ pub fn rule(
|
|||
}
|
||||
|
||||
children.move_next();
|
||||
inline_next_comment = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,19 @@
|
|||
a = 123; # comment
|
||||
}
|
||||
|
||||
{ # 1
|
||||
#2
|
||||
a=1; # 3
|
||||
b=1;
|
||||
c=1; # 4
|
||||
#5
|
||||
|
||||
#6
|
||||
|
||||
d=1;
|
||||
#7
|
||||
}
|
||||
|
||||
({
|
||||
a, # comment
|
||||
b ? 2,# comment
|
||||
|
|
|
@ -64,8 +64,21 @@
|
|||
]
|
||||
|
||||
{
|
||||
a = 123;
|
||||
# comment
|
||||
a = 123; # comment
|
||||
}
|
||||
|
||||
{
|
||||
# 1
|
||||
#2
|
||||
a = 1; # 3
|
||||
b = 1;
|
||||
c = 1; # 4
|
||||
#5
|
||||
|
||||
#6
|
||||
|
||||
d = 1;
|
||||
#7
|
||||
}
|
||||
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue