mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
commit
e16dd2c208
5 changed files with 97 additions and 40 deletions
|
@ -46,9 +46,9 @@ steps:
|
|||
- formatting-before-vs-after.patch.txt
|
||||
- formatting-after.patch.txt
|
||||
command:
|
||||
- git config --global user.email ci@cd
|
||||
- git config --global user.email CI/CD
|
||||
- git config --global user.name CI/CD
|
||||
- git clone --depth 1 https://github.com/nixos/nixpkgs
|
||||
- git clone --branch=master --depth 1 --origin=upstream file:///data/nixpkgs
|
||||
|
||||
- echo --- Formatting - before
|
||||
- nix run github:kamadorueda/alejandra -- nixpkgs 2>/dev/null
|
||||
|
@ -68,7 +68,9 @@ steps:
|
|||
- closure-after.txt
|
||||
- closure-before-vs-after.patch.txt
|
||||
command:
|
||||
- git clone --depth 1 https://github.com/nixos/nixpkgs
|
||||
- git config --global user.email CI/CD
|
||||
- git config --global user.name CI/CD
|
||||
- git clone --branch=master --depth 1 --origin=upstream file:///data/nixpkgs
|
||||
|
||||
- echo --- Closure @ before
|
||||
- nix-env --query --available --attr-path --drv-path --file nixpkgs --xml > closure-before.txt
|
||||
|
|
|
@ -52,26 +52,15 @@ pub fn rule(
|
|||
let next = children.peek_next().unwrap();
|
||||
let next_kind = next.element.kind();
|
||||
|
||||
if matches!(
|
||||
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
|
||||
) || (matches!(next_kind, rnix::SyntaxKind::NODE_LAMBDA)
|
||||
&& !matches!(
|
||||
next.element
|
||||
.clone()
|
||||
.into_node()
|
||||
.unwrap()
|
||||
.children()
|
||||
.next()
|
||||
.unwrap()
|
||||
.kind(),
|
||||
rnix::SyntaxKind::NODE_PATTERN
|
||||
))
|
||||
if false
|
||||
|| matches!(
|
||||
next_kind,
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
)
|
||||
|| (matches!(next_kind, rnix::SyntaxKind::NODE_APPLY)
|
||||
&& matches!(
|
||||
next.element
|
||||
|
@ -90,6 +79,39 @@ pub fn rule(
|
|||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
))
|
||||
|| (matches!(next_kind, rnix::SyntaxKind::NODE_LAMBDA)
|
||||
&& !matches!(
|
||||
next.element
|
||||
.clone()
|
||||
.into_node()
|
||||
.unwrap()
|
||||
.children()
|
||||
.next()
|
||||
.unwrap()
|
||||
.kind(),
|
||||
rnix::SyntaxKind::NODE_PATTERN
|
||||
))
|
||||
|| (matches!(next_kind, rnix::SyntaxKind::NODE_WITH)
|
||||
&& matches!(
|
||||
next.element
|
||||
.clone()
|
||||
.into_node()
|
||||
.unwrap()
|
||||
.children()
|
||||
.collect::<Vec<rnix::SyntaxNode>>()
|
||||
.iter()
|
||||
.rev()
|
||||
.next()
|
||||
.unwrap()
|
||||
.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_IDENT
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_LITERAL
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
))
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
|
|
|
@ -19,19 +19,18 @@ pub fn rule(
|
|||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
|
||||
// /**/
|
||||
let mut comment = 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(_) => {}
|
||||
});
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE =
|
||||
children.peek_prev().unwrap().element.kind()
|
||||
{
|
||||
if comment {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else {
|
||||
|
@ -40,7 +39,6 @@ pub fn rule(
|
|||
|
||||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
|
@ -68,17 +66,35 @@ pub fn rule(
|
|||
|
||||
// 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::FormatWider(child.element));
|
||||
if comment
|
||||
|| matches!(child.element.kind(), rnix::SyntaxKind::NODE_WITH)
|
||||
|| !matches!(
|
||||
child.element.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_IDENT
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_LITERAL
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
)
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,12 @@
|
|||
(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;})
|
||||
{ a = with b;with b;with b;
|
||||
1;
|
||||
}
|
||||
{binPath = with pkgs;
|
||||
makeBinPath (
|
||||
[
|
||||
rsync
|
||||
util-linux]);}
|
||||
]
|
||||
|
|
|
@ -46,11 +46,7 @@
|
|||
a = with b; 1;
|
||||
# comment
|
||||
}
|
||||
(
|
||||
with a;
|
||||
with b;
|
||||
with c; { a = 1; }
|
||||
)
|
||||
(with a; with b; with c; { a = 1; })
|
||||
(
|
||||
with a;
|
||||
with b;
|
||||
|
@ -70,4 +66,17 @@
|
|||
b = 2;
|
||||
}
|
||||
)
|
||||
{
|
||||
a = with b; with b; with b; 1;
|
||||
}
|
||||
{
|
||||
binPath =
|
||||
with pkgs;
|
||||
makeBinPath (
|
||||
[
|
||||
rsync
|
||||
util-linux
|
||||
]
|
||||
);
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue