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

feat: less indented if-then-else

This commit is contained in:
Kevin Amado 2022-02-23 16:09:49 -05:00
parent 07d79340ed
commit 52a85dd4d7
3 changed files with 44 additions and 3 deletions

View file

@ -64,7 +64,14 @@ pub fn rule(
if if_else.comments_before_then_expr.is_empty() {
// expr
let element = if_else.then_expr.unwrap();
if crate::builder::fits_in_single_line(build_ctx, element.clone()) {
if matches!(
element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
) || crate::builder::fits_in_single_line(build_ctx, element.clone())
{
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(element));
} else {
@ -113,8 +120,14 @@ pub fn rule(
if if_else.comments_before_else_expr.is_empty() {
// expr
let element = if_else.else_expr.unwrap();
if matches!(element.kind(), rnix::SyntaxKind::NODE_IF_ELSE)
|| crate::builder::fits_in_single_line(build_ctx, element.clone())
if matches!(
element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_IF_ELSE
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING
) || crate::builder::fits_in_single_line(build_ctx, element.clone())
{
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(element));

View file

@ -1,4 +1,18 @@
[
(if true
then {
version = "1.2.3";
}
else {
version = "3.2.1";
})
(if true
then ''
some text
''
else ''
other text
'')
(if ./a then b else c)
(if /**/ a /**/ then /**/ b /**/ else /**/ c)
(if if a then b else c then b else if a then b else if a then b else c)

View file

@ -1,4 +1,18 @@
[
(if true
then {
version = "1.2.3";
}
else {
version = "3.2.1";
})
(if true
then ''
some text
''
else ''
other text
'')
(if ./a
then b
else c)