1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 12:37:45 +00:00

Merge pull request #122 from kamadorueda/kamadorueda

feat: inline lists comments
This commit is contained in:
Kevin Amado 2022-02-16 22:53:44 -05:00 committed by GitHub
commit ba78351e90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View file

@ -33,16 +33,23 @@ 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
@ -51,13 +58,16 @@ pub fn rule(
{
steps.push_back(crate::builder::Step::NewLine);
}
inline_next_comment = newlines == 0;
}
};
});
if let Some(child) = children.peek_next() {
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child.element.kind()
{
let child_kind = child.element.kind();
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child_kind {
break;
}
@ -81,6 +91,7 @@ pub fn rule(
}
children.move_next();
inline_next_comment = true;
}
}

View file

@ -52,11 +52,9 @@
[
# 1
#2
a
# 3
a # 3
b
c
# 4
c # 4
#5
#6