1
1
pub ( crate ) fn rule (
2
2
build_ctx : & crate :: builder:: BuildCtx ,
3
3
node : & rnix:: SyntaxNode ,
4
+ ) -> std:: collections:: LinkedList < crate :: builder:: Step > {
5
+ rule_with_configuration ( build_ctx, node, true )
6
+ }
7
+
8
+ pub ( crate ) fn rule_with_configuration (
9
+ build_ctx : & crate :: builder:: BuildCtx ,
10
+ node : & rnix:: SyntaxNode ,
11
+ simplify : bool ,
4
12
) -> std:: collections:: LinkedList < crate :: builder:: Step > {
5
13
let mut steps = std:: collections:: LinkedList :: new ( ) ;
6
14
@@ -10,6 +18,29 @@ pub(crate) fn rule(
10
18
let expression = children. next ( ) . unwrap ( ) ;
11
19
let closer = children. next ( ) . unwrap ( ) ;
12
20
21
+ // Simplify this expression
22
+ if simplify
23
+ && !opener. has_inline_comment
24
+ && !opener. has_comments
25
+ && !expression. has_inline_comment
26
+ && !expression. has_comments
27
+ && !closer. has_inline_comment
28
+ && !closer. has_comments
29
+ && matches ! (
30
+ expression. element. kind( ) ,
31
+ rnix:: SyntaxKind :: NODE_ATTR_SET
32
+ | rnix:: SyntaxKind :: NODE_IDENT
33
+ | rnix:: SyntaxKind :: NODE_LIST
34
+ | rnix:: SyntaxKind :: NODE_LITERAL
35
+ | rnix:: SyntaxKind :: NODE_PAREN
36
+ | rnix:: SyntaxKind :: NODE_PATH_WITH_INTERPOL
37
+ | rnix:: SyntaxKind :: NODE_STRING
38
+ )
39
+ {
40
+ steps. push_back ( crate :: builder:: Step :: Format ( expression. element ) ) ;
41
+ return steps;
42
+ }
43
+
13
44
let vertical = opener. has_inline_comment
14
45
|| opener. has_trivialities
15
46
|| expression. has_inline_comment
0 commit comments