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:
parent
07d79340ed
commit
52a85dd4d7
3 changed files with 44 additions and 3 deletions
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue