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

Merge pull request #55 from kamadorueda/kamadorueda

feat: indent lambda in a few scenarios only
This commit is contained in:
Kevin Amado 2022-02-09 23:47:54 -05:00 committed by GitHub
commit 5e172e49ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 14 deletions

View file

@ -50,8 +50,10 @@ 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) => {
comment = true;
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text));
@ -60,16 +62,11 @@ pub fn rule(
});
// c
let child_prev = children.peek_prev().unwrap();
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if is_pattern_type
|| matches!(
child_prev.element.kind(),
rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE
)
|| comment
|| (matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_LAMBDA
@ -96,7 +93,16 @@ pub fn rule(
| rnix::SyntaxKind::NODE_STRING
)
{
if build_ctx.pos_new.column > 1 {
let should_indent = !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
) && build_ctx.pos_new.column > 1;
if should_indent {
steps.push_back(crate::builder::Step::Indent);
}
@ -105,7 +111,7 @@ pub fn rule(
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
if build_ctx.pos_new.column > 1 {
if should_indent {
steps.push_back(crate::builder::Step::Dedent);
}
} else {

View file

@ -85,21 +85,21 @@ rec
/*
b
*/
{ b = 1; };
{ b = 1; };
m = a:
/*
b
*/
{
b = 1;
c = 2;
};
{
b = 1;
c = 2;
};
n = pkgs: { };
o =
{ pkgs
, ...
}:
{ };
{ };
a
/*