mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
Merge pull request #55 from kamadorueda/kamadorueda
feat: indent lambda in a few scenarios only
This commit is contained in:
commit
5e172e49ac
2 changed files with 20 additions and 14 deletions
|
@ -50,8 +50,10 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
|
let mut comment = false;
|
||||||
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) => {
|
||||||
|
comment = true;
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
|
@ -60,16 +62,11 @@ pub fn rule(
|
||||||
});
|
});
|
||||||
|
|
||||||
// c
|
// c
|
||||||
let child_prev = children.peek_prev().unwrap();
|
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
match layout {
|
match layout {
|
||||||
crate::config::Layout::Tall => {
|
crate::config::Layout::Tall => {
|
||||||
if is_pattern_type
|
if is_pattern_type
|
||||||
|| matches!(
|
|| comment
|
||||||
child_prev.element.kind(),
|
|
||||||
rnix::SyntaxKind::TOKEN_COMMENT
|
|
||||||
| rnix::SyntaxKind::TOKEN_WHITESPACE
|
|
||||||
)
|
|
||||||
|| (matches!(
|
|| (matches!(
|
||||||
child.element.kind(),
|
child.element.kind(),
|
||||||
rnix::SyntaxKind::NODE_LAMBDA
|
rnix::SyntaxKind::NODE_LAMBDA
|
||||||
|
@ -96,7 +93,16 @@ pub fn rule(
|
||||||
| rnix::SyntaxKind::NODE_STRING
|
| 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);
|
steps.push_back(crate::builder::Step::Indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +111,7 @@ pub fn rule(
|
||||||
steps.push_back(crate::builder::Step::FormatWider(
|
steps.push_back(crate::builder::Step::FormatWider(
|
||||||
child.element,
|
child.element,
|
||||||
));
|
));
|
||||||
if build_ctx.pos_new.column > 1 {
|
if should_indent {
|
||||||
steps.push_back(crate::builder::Step::Dedent);
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -85,21 +85,21 @@ rec
|
||||||
/*
|
/*
|
||||||
b
|
b
|
||||||
*/
|
*/
|
||||||
{ b = 1; };
|
{ b = 1; };
|
||||||
m = a:
|
m = a:
|
||||||
/*
|
/*
|
||||||
b
|
b
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
b = 1;
|
b = 1;
|
||||||
c = 2;
|
c = 2;
|
||||||
};
|
};
|
||||||
n = pkgs: { };
|
n = pkgs: { };
|
||||||
o =
|
o =
|
||||||
{ pkgs
|
{ pkgs
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
a
|
a
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue