Skip to content

Commit

Permalink
feat: simplify parens
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadorueda committed Feb 28, 2022
1 parent 0b480bc commit 44affb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/alejandra_engine/src/rules/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ pub(crate) fn rule(

// peek: expr
let child_expr = children.get_next().unwrap();
let child_expr =
if matches!(child_expr.kind(), rnix::SyntaxKind::NODE_PAREN) {
let mut children: Vec<rnix::SyntaxElement> =
child_expr.as_node().unwrap().children_with_tokens().collect();

if children.len() == 3 {
children.swap_remove(1)
} else {
child_expr
}
} else {
child_expr
};

// peek: /**/
let mut comments_after = std::collections::LinkedList::new();
Expand Down
2 changes: 2 additions & 0 deletions src/alejandra_engine/tests/cases/key_value/in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rec /**/ {

a = (((4)));

a = {a = 1 ;};


Expand Down
2 changes: 2 additions & 0 deletions src/alejandra_engine/tests/cases/key_value/out
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
rec
/**/
{
a = 4;

a = {a = 1;};

b = {
Expand Down

0 comments on commit 44affb2

Please sign in to comment.