Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: 1-expr tests eta_reduction

+69 -49
-21
bin/tests/data/eta_reduction.nix
··· 1 - let 2 - double = x: x * 2; 3 - inherit (builtins) map; 4 - xs = [ 1 2 3 ]; 5 - f = { 6 - inherit double; 7 - val = 2; 8 - }; 9 - in 10 - [ 11 - (map (x: double x) xs) 12 - 13 - # don't lint on non-free exprs 14 - (map (f: f.double f.val) [ f ]) 15 - 16 - # other non-free forms 17 - (map (f: {inherit f;}.double f.val) [ f ]) 18 - 19 - # don't reduce on more complex lambda bodies 20 - (map (x: builtins.div 3 x) xs) 21 - ]
+19
bin/tests/eta_reduction.rs
··· 1 + mod _utils; 2 + 3 + use macros::generate_tests; 4 + 5 + generate_tests! { 6 + rule: manual_inherit, 7 + expressions: [ 8 + "let double = x: x * 2; in map (x: double x) [1 2 3]", 9 + 10 + // don't lint on non-free exprs 11 + "let f = { double = x: x *2; val = 2; }; in map (f: f.double f.val) [ f ]", 12 + 13 + // other non-free forms 14 + "let f = { double = x: x *2; val = 2; }; in map (f: {inherit f;}.double f.val) [ f ]", 15 + 16 + // don't reduce on more complex lambda bodies 17 + "map (x: builtins.div 3 x) [1 2 3]", 18 + ], 19 + }
-1
bin/tests/main.rs
··· 44 44 } 45 45 46 46 test_lint! { 47 - eta_reduction, 48 47 useless_parens, 49 48 empty_pattern, 50 49 redundant_pattern_bind,
+5
bin/tests/snapshots/eta_reduction__fix_1753a4ee5edee65b9e4cbd0efbbfb45be4abfe4c556a183b4e56dd3e2ebb200e.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let f = { double = x: x *2; val = 2; }; in map (f: {inherit f;}.double f.val) [ f ]\"" 4 + --- 5 +
+5
bin/tests/snapshots/eta_reduction__fix_2af9e5afbc8ddbb1cdd61c38fa47661f18ef38e477f843fa6eb8fe3f11d76462.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let f = { double = x: x *2; val = 2; }; in map (f: f.double f.val) [ f ]\"" 4 + --- 5 +
+9
bin/tests/snapshots/eta_reduction__fix_371c868dbc9581a6fc41c7085146a422829b37c0e7d4ec0cf2b2d48d2e116b71.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let double = x: x * 2; in map (x: double x) [1 2 3]\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -let double = x: x * 2; in map (x: double x) [1 2 3] 9 + +let double = x: x * 2; in map double [1 2 3]
+5
bin/tests/snapshots/eta_reduction__fix_860ea9e8412515330162460cc2e1b25bc90c61c53b6c5bd37981257482ae7254.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"map (x: builtins.div 3 x) [1 2 3]\"" 4 + --- 5 +
+5
bin/tests/snapshots/eta_reduction__lint_1753a4ee5edee65b9e4cbd0efbbfb45be4abfe4c556a183b4e56dd3e2ebb200e.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let f = { double = x: x *2; val = 2; }; in map (f: {inherit f;}.double f.val) [ f ]\"" 4 + --- 5 +
+5
bin/tests/snapshots/eta_reduction__lint_2af9e5afbc8ddbb1cdd61c38fa47661f18ef38e477f843fa6eb8fe3f11d76462.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let f = { double = x: x *2; val = 2; }; in map (f: f.double f.val) [ f ]\"" 4 + --- 5 +
+11
bin/tests/snapshots/eta_reduction__lint_371c868dbc9581a6fc41c7085146a422829b37c0e7d4ec0cf2b2d48d2e116b71.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"let double = x: x * 2; in map (x: double x) [1 2 3]\"" 4 + --- 5 + [W07] Warning: This function expression is eta reducible 6 + ╭─[<temp_file_path>:1:32] 7 + 8 + 1 │ let double = x: x * 2; in map (x: double x) [1 2 3] 9 + · ─────┬───── 10 + · ╰─────── Found eta-reduction: double 11 + ───╯
+5
bin/tests/snapshots/eta_reduction__lint_860ea9e8412515330162460cc2e1b25bc90c61c53b6c5bd37981257482ae7254.snap
··· 1 + --- 2 + source: bin/tests/eta_reduction.rs 3 + expression: "\"map (x: builtins.div 3 x) [1 2 3]\"" 4 + --- 5 +
-16
bin/tests/snapshots/main__eta_reduction_fix.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - --- tests/data/eta_reduction.nix 6 - +++ tests/data/eta_reduction.nix [fixed] 7 - @@ -7,9 +7,9 @@ 8 - val = 2; 9 - }; 10 - in 11 - [ 12 - - (map (x: double x) xs) 13 - + (map double xs) 14 - 15 - # don't lint on non-free exprs 16 - (map (f: f.double f.val) [ f ])
-11
bin/tests/snapshots/main__eta_reduction_lint.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - [W07] Warning: This function expression is eta reducible 6 - ╭─[tests/data/eta_reduction.nix:11:9] 7 - 8 - 11 │ (map (x: double x) xs) 9 - · ─────┬───── 10 - · ╰─────── Found eta-reduction: double 11 - ────╯