1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +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 item_index: usize = 0;
let mut inline_next_comment = false;
loop { loop {
// /**/ // /**/
children.drain_comments_and_newlines(|element| { children.drain_comments_and_newlines(|element| {
match element { match element {
crate::children::DrainCommentOrNewline::Comment(text) => { crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::NewLine); if inline_next_comment && text.starts_with("#") {
steps.push_back(crate::builder::Step::Pad); 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)); steps.push_back(crate::builder::Step::Comment(text));
item_index += 1; item_index += 1;
inline_next_comment = false;
} }
crate::children::DrainCommentOrNewline::Newline(newlines) => { crate::children::DrainCommentOrNewline::Newline(newlines) => {
if newlines > 1 if newlines > 1
@ -51,13 +58,16 @@ pub fn rule(
{ {
steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::NewLine);
} }
inline_next_comment = newlines == 0;
} }
}; };
}); });
if let Some(child) = children.peek_next() { 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; break;
} }
@ -81,6 +91,7 @@ pub fn rule(
} }
children.move_next(); children.move_next();
inline_next_comment = true;
} }
} }

View file

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