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

with: inline follow on expressions

This commit is contained in:
Tom Bereknyei 2022-02-10 20:16:08 -05:00
parent 0c095ed50d
commit 77db3703b1
6 changed files with 101 additions and 19 deletions

View file

@ -56,6 +56,7 @@ pub fn rule(
next_kind,
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_WITH
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
@ -87,6 +88,7 @@ pub fn rule(
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_WITH
| rnix::SyntaxKind::NODE_STRING
))
{

View file

@ -40,6 +40,19 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
if let rnix::SyntaxKind::TOKEN_COMMENT =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
if let rnix::SyntaxKind::NODE_WITH = child.element.kind() {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
}
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element));
@ -54,25 +67,30 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
let mut comment : bool = false;
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);
steps.push_back(crate::builder::Step::Comment(text));
comment = true;
}
crate::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr
let child = children.get_next().unwrap();
if comment || matches!(child.element.kind(),rnix::SyntaxKind::NODE_WITH) {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element));
}
}

View file

@ -12,4 +12,7 @@
description = "something";
};
}
{ meta = with lib;
# comment
{ a=1; b=2; c=3; };}
]

View file

@ -1,12 +1,10 @@
[
{
meta =
with lib;
{
a = 1;
b = 2;
c = 3;
};
meta = with lib; {
a = 1;
b = 2;
c = 3;
};
}
{ stdenv
, lib
@ -19,11 +17,18 @@
src = fetchFrom {
url = "example/${version}";
};
meta =
with lib;
{
maintainers = with maintainers; [ someone ];
description = "something";
};
meta = with lib; {
maintainers = with maintainers; [ someone ];
description = "something";
};
}
{
meta = with lib;
# comment
{
a = 1;
b = 2;
c = 3;
};
}
]

View file

@ -6,4 +6,19 @@
( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( with b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
{ a = with b; 1;}
{ a = with b; 1 + 1;}
{ a = with b; {c=1;};}
{ a = with b; {c=1; d=2; e=3;};}
{ a = with b;
# comment
1;
}
{ a = with b;
1;
# comment
}
(with a; with b; with c; {a=1;})
(with a; with b; with c; {a=1;b=2;})
(with a; /* comment */ with b; with c; {a=1;b=2;})
]

View file

@ -12,8 +12,7 @@
/*
a
*/
b;
c
b; c
)
(
with
@ -27,8 +26,48 @@
c
)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{ a = with b; 1; }
{ a = with b; 1 + 1; }
{ a = with b; { c = 1; }; }
{
a = with b; {
c = 1;
d = 2;
e = 3;
};
}
{
a = with b;
# comment
1;
}
{
a = with b; 1;
# comment
}
(
with a;
with b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
with c; { a = 1; }
)
(
with a;
with b;
with c; {
a = 1;
b = 2;
}
)
(
with a;
/*
comment
*/
with b;
with c; {
a = 1;
b = 2;
}
)
]