mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
Merge pull request #124 from kamadorueda/kamadorueda
feat: inline let-ins comments
This commit is contained in:
commit
042bf5f959
3 changed files with 42 additions and 2 deletions
|
@ -38,19 +38,27 @@ 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| match element {
|
children.drain_comments_and_newlines(|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));
|
||||||
|
inline_next_comment = false;
|
||||||
}
|
}
|
||||||
crate::children::DrainCommentOrNewline::Newline(newlines) => {
|
crate::children::DrainCommentOrNewline::Newline(newlines) => {
|
||||||
if newlines > 1 && item_index > 0 && item_index < items_count {
|
if newlines > 1 && item_index > 0 && item_index < items_count {
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline_next_comment = newlines == 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,6 +85,7 @@ pub fn rule(
|
||||||
}
|
}
|
||||||
|
|
||||||
children.move_next();
|
children.move_next();
|
||||||
|
inline_next_comment = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,20 @@
|
||||||
#7
|
#7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(let # 1
|
||||||
|
#2
|
||||||
|
a=1; # 3
|
||||||
|
b=1;
|
||||||
|
c=1; # 4
|
||||||
|
#5
|
||||||
|
|
||||||
|
#6
|
||||||
|
|
||||||
|
d=1;
|
||||||
|
#7
|
||||||
|
in
|
||||||
|
d)
|
||||||
|
|
||||||
({
|
({
|
||||||
a, # comment
|
a, # comment
|
||||||
b ? 2,# comment
|
b ? 2,# comment
|
||||||
|
|
|
@ -81,6 +81,23 @@
|
||||||
#7
|
#7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
let
|
||||||
|
# 1
|
||||||
|
#2
|
||||||
|
a = 1; # 3
|
||||||
|
b = 1;
|
||||||
|
c = 1; # 4
|
||||||
|
#5
|
||||||
|
|
||||||
|
#6
|
||||||
|
|
||||||
|
d = 1;
|
||||||
|
#7
|
||||||
|
in
|
||||||
|
d
|
||||||
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
a,
|
a,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue