Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions bin/tests/data/useless_parens.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
let
# parens around primitives
a = {
primitive = {
b = ("hello");
c = (d);
e = ({ f = 2; });
};

# parens around let-value
g = (1 + 2);
h = ({ inherit i; });
value1 = (1 + 2);
value2 = ({ inherit i; });

# TODO: binary exprs, function args etc.
binop =
let id = x: x; in
(id [3])
++ (id [1] ++ [2])
;
binop_no =
(1 + 1)
* (2 + 2)
;

# precedence
arith1 =
4 + (5 * 3)
;
arith2 =
(4 * 5) / 5
;
arith3_no =
4 * (5 / 5)
;

primitive_binop =
[1] ++ ([2])
;

string_concat =
(builtins.readFile ./x.txt)
+ (lib.optionalString true ''
foo
'')
+ (lib.optionalString true ''
bar
'')
;

# TODO: function args etc.
in
# parens around let body
(null)
62 changes: 55 additions & 7 deletions bin/tests/snapshots/main__useless_parens_fix.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
source: bin/tests/main.rs
expression: "& stdout"

---
--- tests/data/useless_parens.nix
+++ tests/data/useless_parens.nix [fixed]
@@ -1,16 +1,16 @@
@@ -1,51 +1,51 @@
let
# parens around primitives
a = {
primitive = {
- b = ("hello");
- c = (d);
- e = ({ f = 2; });
Expand All @@ -17,13 +18,60 @@ expression: "& stdout"
};

# parens around let-value
- g = (1 + 2);
- h = ({ inherit i; });
+ g = 1 + 2;
+ h = { inherit i; };
- value1 = (1 + 2);
- value2 = ({ inherit i; });
+ value1 = 1 + 2;
+ value2 = { inherit i; };

# TODO: binary exprs, function args etc.
binop =
let id = x: x; in
- (id [3])
- ++ (id [1] ++ [2])
+ id [3]
+ ++ id [1] ++ [2]
;
binop_no =
(1 + 1)
* (2 + 2)
;

# precedence
arith1 =
- 4 + (5 * 3)
+ 4 + 5 * 3
;
arith2 =
- (4 * 5) / 5
+ 4 * 5 / 5
;
arith3_no =
4 * (5 / 5)
;

primitive_binop =
- [1] ++ ([2])
+ [1] ++ [2]
;

string_concat =
- (builtins.readFile ./x.txt)
- + (lib.optionalString true ''
+ builtins.readFile ./x.txt
+ + lib.optionalString true ''
foo
- '')
- + (lib.optionalString true ''
+ ''
+ + lib.optionalString true ''
bar
- '')
+ ''
;

# TODO: function args etc.
in
# parens around let body
- (null)
+ null


72 changes: 62 additions & 10 deletions bin/tests/snapshots/main__useless_parens_lint.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
source: bin/tests/main.rs
expression: "& out"

---
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:16:3]
╭─[data/useless_parens.nix:51:3]
16 │ (null)
51 │ (null)
· ───┬──
· ╰──── Useless parentheses around body of let expression
────╯
Expand All @@ -31,16 +32,67 @@ expression: "& out"
· ╰─────── Useless parentheses around value in binding
───╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:10:7]
╭─[data/useless_parens.nix:10:12]
10 │ g = (1 + 2);
· ───┬───
· ╰───── Useless parentheses around value in binding
10 │ value1 = (1 + 2);
· ───┬───
· ╰───── Useless parentheses around value in binding
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:11:7]
╭─[data/useless_parens.nix:11:12]
11 │ h = ({ inherit i; });
· ────────┬───────
· ╰───────── Useless parentheses around value in binding
11 │ value2 = ({ inherit i; });
· ────────┬───────
· ╰───────── Useless parentheses around value in binding
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:15:5]
15 │ (id [3])
· ────┬───
· ╰───── Useless parentheses in operand of binary operator
16 │ ++ (id [1] ++ [2])
· ───────┬───────
· ╰───────── Useless parentheses in operand of binary operator
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:25:9]
25 │ 4 + (5 * 3)
· ───┬───
· ╰───── Useless parentheses in operand of binary operator
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:28:5]
28 │ (4 * 5) / 5
· ───┬───
· ╰───── Useless parentheses in operand of binary operator
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:35:12]
35 │ [1] ++ ([2])
· ──┬──
· ╰──── Useless parentheses around primitive expression
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:43:7]
43 │ ╭─▶ + (lib.optionalString true ''
45 │ ├─▶ '')
· │
· ╰───────────── Useless parentheses in operand of binary operator
────╯
[W08] Warning: These parentheses can be omitted
╭─[data/useless_parens.nix:39:5]
39 │ (builtins.readFile ./x.txt)
· ─────────────┬─────────────
· ╰─────────────── Useless parentheses in operand of binary operator
40 │ ╭─▶ + (lib.optionalString true ''
42 │ ├─▶ '')
· │
· ╰───────────── Useless parentheses in operand of binary operator
────╯

Loading