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 bool-comparison

Co-authored-by: Wes Gray <wes.gray@gmail.com>

+664 -186
+186 -7
Cargo.lock
··· 12 12 ] 13 13 14 14 [[package]] 15 + name = "anyhow" 16 + version = "1.0.100" 17 + source = "registry+https://github.com/rust-lang/crates.io-index" 18 + checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" 19 + 20 + [[package]] 15 21 name = "ariadne" 16 22 version = "0.1.3" 17 23 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 50 56 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 51 57 52 58 [[package]] 59 + name = "bitflags" 60 + version = "2.9.4" 61 + source = "registry+https://github.com/rust-lang/crates.io-index" 62 + checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" 63 + 64 + [[package]] 65 + name = "block-buffer" 66 + version = "0.10.4" 67 + source = "registry+https://github.com/rust-lang/crates.io-index" 68 + checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" 69 + dependencies = [ 70 + "generic-array", 71 + ] 72 + 73 + [[package]] 53 74 name = "bstr" 54 75 version = "0.2.17" 55 76 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 71 92 checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" 72 93 dependencies = [ 73 94 "atty", 74 - "bitflags", 95 + "bitflags 1.3.2", 75 96 "clap_derive", 76 97 "indexmap", 77 98 "lazy_static", ··· 114 135 checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" 115 136 116 137 [[package]] 138 + name = "cpufeatures" 139 + version = "0.2.17" 140 + source = "registry+https://github.com/rust-lang/crates.io-index" 141 + checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" 142 + dependencies = [ 143 + "libc", 144 + ] 145 + 146 + [[package]] 117 147 name = "crossbeam-channel" 118 148 version = "0.5.2" 119 149 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 158 188 ] 159 189 160 190 [[package]] 191 + name = "crypto-common" 192 + version = "0.1.6" 193 + source = "registry+https://github.com/rust-lang/crates.io-index" 194 + checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" 195 + dependencies = [ 196 + "generic-array", 197 + "typenum", 198 + ] 199 + 200 + [[package]] 201 + name = "digest" 202 + version = "0.10.7" 203 + source = "registry+https://github.com/rust-lang/crates.io-index" 204 + checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 205 + dependencies = [ 206 + "block-buffer", 207 + "crypto-common", 208 + ] 209 + 210 + [[package]] 161 211 name = "either" 162 212 version = "1.6.1" 163 213 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 170 220 checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" 171 221 172 222 [[package]] 223 + name = "errno" 224 + version = "0.3.14" 225 + source = "registry+https://github.com/rust-lang/crates.io-index" 226 + checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" 227 + dependencies = [ 228 + "libc", 229 + "windows-sys", 230 + ] 231 + 232 + [[package]] 233 + name = "fastrand" 234 + version = "2.3.0" 235 + source = "registry+https://github.com/rust-lang/crates.io-index" 236 + checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 237 + 238 + [[package]] 173 239 name = "fnv" 174 240 version = "1.0.7" 175 241 source = "registry+https://github.com/rust-lang/crates.io-index" 176 242 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 177 243 178 244 [[package]] 245 + name = "generic-array" 246 + version = "0.14.7" 247 + source = "registry+https://github.com/rust-lang/crates.io-index" 248 + checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" 249 + dependencies = [ 250 + "typenum", 251 + "version_check", 252 + ] 253 + 254 + [[package]] 255 + name = "getrandom" 256 + version = "0.3.3" 257 + source = "registry+https://github.com/rust-lang/crates.io-index" 258 + checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" 259 + dependencies = [ 260 + "cfg-if", 261 + "libc", 262 + "r-efi", 263 + "wasi", 264 + ] 265 + 266 + [[package]] 179 267 name = "globset" 180 268 version = "0.4.8" 181 269 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 219 307 ] 220 308 221 309 [[package]] 310 + name = "hex" 311 + version = "0.4.3" 312 + source = "registry+https://github.com/rust-lang/crates.io-index" 313 + checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 314 + 315 + [[package]] 222 316 name = "ignore" 223 317 version = "0.4.18" 224 318 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 254 348 dependencies = [ 255 349 "console", 256 350 "once_cell", 351 + "regex", 257 352 "similar", 258 353 ] 259 354 ··· 283 378 284 379 [[package]] 285 380 name = "libc" 286 - version = "0.2.106" 381 + version = "0.2.177" 287 382 source = "registry+https://github.com/rust-lang/crates.io-index" 288 - checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" 383 + checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" 384 + 385 + [[package]] 386 + name = "linux-raw-sys" 387 + version = "0.11.0" 388 + source = "registry+https://github.com/rust-lang/crates.io-index" 389 + checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" 289 390 290 391 [[package]] 291 392 name = "log" ··· 300 401 name = "macros" 301 402 version = "0.0.0" 302 403 dependencies = [ 404 + "hex", 303 405 "proc-macro2", 304 406 "quote", 407 + "sha2", 305 408 "syn 2.0.106", 306 409 ] 307 410 ··· 403 506 ] 404 507 405 508 [[package]] 509 + name = "r-efi" 510 + version = "5.3.0" 511 + source = "registry+https://github.com/rust-lang/crates.io-index" 512 + checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" 513 + 514 + [[package]] 406 515 name = "rayon" 407 516 version = "1.5.1" 408 517 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 429 538 430 539 [[package]] 431 540 name = "regex" 432 - version = "1.5.4" 541 + version = "1.7.3" 433 542 source = "registry+https://github.com/rust-lang/crates.io-index" 434 - checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" 543 + checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" 435 544 dependencies = [ 436 545 "aho-corasick", 437 546 "memchr", ··· 440 549 441 550 [[package]] 442 551 name = "regex-syntax" 443 - version = "0.6.25" 552 + version = "0.6.29" 444 553 source = "registry+https://github.com/rust-lang/crates.io-index" 445 - checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 554 + checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" 446 555 447 556 [[package]] 448 557 name = "rnix" ··· 471 580 version = "1.1.0" 472 581 source = "registry+https://github.com/rust-lang/crates.io-index" 473 582 checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 583 + 584 + [[package]] 585 + name = "rustix" 586 + version = "1.1.2" 587 + source = "registry+https://github.com/rust-lang/crates.io-index" 588 + checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" 589 + dependencies = [ 590 + "bitflags 2.9.4", 591 + "errno", 592 + "libc", 593 + "linux-raw-sys", 594 + "windows-sys", 595 + ] 474 596 475 597 [[package]] 476 598 name = "ryu" ··· 525 647 ] 526 648 527 649 [[package]] 650 + name = "sha2" 651 + version = "0.10.9" 652 + source = "registry+https://github.com/rust-lang/crates.io-index" 653 + checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" 654 + dependencies = [ 655 + "cfg-if", 656 + "cpufeatures", 657 + "digest", 658 + ] 659 + 660 + [[package]] 528 661 name = "similar" 529 662 version = "2.1.0" 530 663 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 534 667 name = "statix" 535 668 version = "0.5.8" 536 669 dependencies = [ 670 + "anyhow", 537 671 "ariadne", 538 672 "clap", 539 673 "ignore", 540 674 "insta", 541 675 "lib", 676 + "macros", 542 677 "paste", 543 678 "rayon", 544 679 "rnix", ··· 547 682 "serde_json", 548 683 "similar", 549 684 "strip-ansi-escapes", 685 + "tempfile", 550 686 "thiserror", 551 687 "toml", 552 688 "vfs", ··· 590 726 ] 591 727 592 728 [[package]] 729 + name = "tempfile" 730 + version = "3.23.0" 731 + source = "registry+https://github.com/rust-lang/crates.io-index" 732 + checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" 733 + dependencies = [ 734 + "fastrand", 735 + "getrandom", 736 + "once_cell", 737 + "rustix", 738 + "windows-sys", 739 + ] 740 + 741 + [[package]] 593 742 name = "termcolor" 594 743 version = "1.1.2" 595 744 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 650 799 dependencies = [ 651 800 "serde", 652 801 ] 802 + 803 + [[package]] 804 + name = "typenum" 805 + version = "1.19.0" 806 + source = "registry+https://github.com/rust-lang/crates.io-index" 807 + checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" 653 808 654 809 [[package]] 655 810 name = "unicase" ··· 731 886 ] 732 887 733 888 [[package]] 889 + name = "wasi" 890 + version = "0.14.7+wasi-0.2.4" 891 + source = "registry+https://github.com/rust-lang/crates.io-index" 892 + checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" 893 + dependencies = [ 894 + "wasip2", 895 + ] 896 + 897 + [[package]] 898 + name = "wasip2" 899 + version = "1.0.1+wasi-0.2.4" 900 + source = "registry+https://github.com/rust-lang/crates.io-index" 901 + checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" 902 + dependencies = [ 903 + "wit-bindgen", 904 + ] 905 + 906 + [[package]] 734 907 name = "winapi" 735 908 version = "0.3.9" 736 909 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 833 1006 version = "0.52.6" 834 1007 source = "registry+https://github.com/rust-lang/crates.io-index" 835 1008 checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 1009 + 1010 + [[package]] 1011 + name = "wit-bindgen" 1012 + version = "0.46.0" 1013 + source = "registry+https://github.com/rust-lang/crates.io-index" 1014 + checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" 836 1015 837 1016 [[package]] 838 1017 name = "yansi"
+5 -1
Cargo.toml
··· 8 8 license = "MIT" 9 9 10 10 [workspace.dependencies] 11 + anyhow = "1.0.100" 11 12 ariadne = "0.1.3" 12 13 clap = "3.0.0-beta.4" 14 + hex = "0.4.3" 13 15 ignore = "0.4.18" 14 16 indexmap = "1.6.2" 15 - insta = "1.43.2" 17 + insta = { features = ["filters"], version = "1.43.2" } 16 18 lazy_static = "1.0" 17 19 lib.path = "./lib" 18 20 macros.path = "./macros" ··· 24 26 rowan = "0.15.17" 25 27 serde = { features = ["derive"], version = "1.0.68" } 26 28 serde_json = { version = "1.0.68" } 29 + sha2 = "0.10.9" 27 30 similar = "2.1.0" 28 31 strip-ansi-escapes = "0.1.1" 29 32 syn = { features = ["full"], version = "2.0" } 33 + tempfile = "3.23.0" 30 34 thiserror = "1.0.30" 31 35 toml = "0.5.8" 32 36 vfs.path = "./vfs"
+3
bin/Cargo.toml
··· 15 15 path = "src/main.rs" 16 16 17 17 [dependencies] 18 + anyhow.workspace = true 18 19 ariadne.workspace = true 19 20 clap.workspace = true 20 21 ignore.workspace = true 21 22 lib.workspace = true 23 + macros.workspace = true 22 24 rayon.workspace = true 23 25 rnix.workspace = true 24 26 rowan.workspace = true 25 27 serde.workspace = true 26 28 serde_json = { optional = true, workspace = true } 27 29 similar.workspace = true 30 + tempfile.workspace = true 28 31 thiserror.workspace = true 29 32 toml.workspace = true 30 33 vfs.workspace = true
+22
bin/tests/_utils.rs
··· 1 + use std::{io::Write, process::Command}; 2 + 3 + use tempfile::NamedTempFile; 4 + 5 + pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result<String> { 6 + let mut fixture = NamedTempFile::with_suffix(".nix")?; 7 + fixture.write_all(expression.as_bytes())?; 8 + fixture.write_all(b"\n")?; // otherwise diff says there's no newline at end of file 9 + 10 + let output = Command::new("cargo") 11 + .arg("run") 12 + .arg("--") 13 + .args(args) 14 + .arg(fixture.path()) 15 + .output()?; 16 + 17 + let stdout = strip_ansi_escapes::strip(output.stdout)?; 18 + let stdout = String::from_utf8(stdout)?; 19 + let stdout = stdout.replace(fixture.path().to_str().unwrap(), "<temp_file_path>"); 20 + 21 + Ok(stdout) 22 + }
+30
bin/tests/bool_comparison.rs
··· 1 + mod _utils; 2 + 3 + use macros::generate_tests; 4 + 5 + generate_tests! { 6 + rule: bool_comparison, 7 + expressions: [ 8 + // trivial 9 + "a == true", 10 + "b == true", 11 + "true == c", 12 + "true == d", 13 + // not equals 14 + "e != true", 15 + "f != false", 16 + "true != g", 17 + "false != h", 18 + // non-matches 19 + "i == j", 20 + "k != l", 21 + // both sides bool 22 + "false == false", 23 + "false == true", 24 + "true == false", 25 + "true == true", 26 + // has attr 27 + "false == m ? n", 28 + "true == o ? p", 29 + ], 30 + }
-27
bin/tests/data/bool_comparison.nix
··· 1 - [ 2 - # trivial 3 - (a == true) 4 - (b == true) 5 - (true == c) 6 - (true == d) 7 - 8 - # not equals 9 - (e != true) 10 - (f != false) 11 - (true != g) 12 - (false != h) 13 - 14 - # non-matches 15 - (i == j) 16 - (k != l) 17 - 18 - # both sides bool 19 - (false == false) 20 - (false == true) 21 - (true == false) 22 - (true == true) 23 - 24 - # has attr 25 - (false == m ? n) 26 - (true == o ? p) 27 - ]
-1
bin/tests/main.rs
··· 44 44 } 45 45 46 46 test_lint! { 47 - bool_comparison, 48 47 empty_let_in, 49 48 manual_inherit, 50 49 manual_inherit_from,
+9
bin/tests/snapshots/bool_comparison__fix_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"f != false\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -f != false 9 + +f
+9
bin/tests/snapshots/bool_comparison__fix_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == d\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true == d 9 + +d
+5
bin/tests/snapshots/bool_comparison__fix_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"k != l\"" 4 + --- 5 +
+9
bin/tests/snapshots/bool_comparison__fix_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == false\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -false == false 9 + +!false
+9
bin/tests/snapshots/bool_comparison__fix_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false != h\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -false != h 9 + +h
+9
bin/tests/snapshots/bool_comparison__fix_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == true\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true == true 9 + +true
+9
bin/tests/snapshots/bool_comparison__fix_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == c\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true == c 9 + +c
+9
bin/tests/snapshots/bool_comparison__fix_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true != g\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true != g 9 + +!g
+9
bin/tests/snapshots/bool_comparison__fix_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"b == true\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -b == true 9 + +b
+9
bin/tests/snapshots/bool_comparison__fix_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == m ? n\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -false == m ? n 9 + +!m ? n
+9
bin/tests/snapshots/bool_comparison__fix_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"a == true\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -a == true 9 + +a
+9
bin/tests/snapshots/bool_comparison__fix_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == o ? p\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true == o ? p 9 + +o ? p
+5
bin/tests/snapshots/bool_comparison__fix_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"i == j\"" 4 + --- 5 +
+9
bin/tests/snapshots/bool_comparison__fix_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == true\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -false == true 9 + +!true
+9
bin/tests/snapshots/bool_comparison__fix_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"e != true\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -e != true 9 + +!e
+9
bin/tests/snapshots/bool_comparison__fix_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == false\"" 4 + --- 5 + --- <temp_file_path> 6 + +++ <temp_file_path> [fixed] 7 + @@ -1 +1 @@ 8 + -true == false 9 + +false
+11
bin/tests/snapshots/bool_comparison__lint_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"f != false\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ f != false 9 + · ─────┬──── 10 + · ╰────── Comparing f with boolean literal false 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == d\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true == d 9 + · ────┬──── 10 + · ╰────── Comparing d with boolean literal true 11 + ───╯
+5
bin/tests/snapshots/bool_comparison__lint_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"k != l\"" 4 + --- 5 +
+11
bin/tests/snapshots/bool_comparison__lint_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == false\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ false == false 9 + · ───────┬────── 10 + · ╰──────── Comparing false with boolean literal false 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false != h\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ false != h 9 + · ─────┬──── 10 + · ╰────── Comparing h with boolean literal false 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == true\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true == true 9 + · ──────┬───── 10 + · ╰─────── Comparing true with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == c\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true == c 9 + · ────┬──── 10 + · ╰────── Comparing c with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true != g\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true != g 9 + · ────┬──── 10 + · ╰────── Comparing g with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"b == true\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ b == true 9 + · ────┬──── 10 + · ╰────── Comparing b with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == m ? n\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ false == m ? n 9 + · ───────┬────── 10 + · ╰──────── Comparing m ? n with boolean literal false 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"a == true\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ a == true 9 + · ────┬──── 10 + · ╰────── Comparing a with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == o ? p\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true == o ? p 9 + · ──────┬────── 10 + · ╰──────── Comparing o ? p with boolean literal true 11 + ───╯
+5
bin/tests/snapshots/bool_comparison__lint_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"i == j\"" 4 + --- 5 +
+11
bin/tests/snapshots/bool_comparison__lint_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"false == true\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ false == true 9 + · ──────┬────── 10 + · ╰──────── Comparing true with boolean literal false 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"e != true\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ e != true 9 + · ────┬──── 10 + · ╰────── Comparing e with boolean literal true 11 + ───╯
+11
bin/tests/snapshots/bool_comparison__lint_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap
··· 1 + --- 2 + source: bin/tests/bool_comparison.rs 3 + expression: "\"true == false\"" 4 + --- 5 + [W01] Warning: Unnecessary comparison with boolean 6 + ╭─[<temp_file_path>:1:1] 7 + 8 + 1 │ true == false 9 + · ──────┬────── 10 + · ╰──────── Comparing false with boolean literal true 11 + ───╯
-48
bin/tests/snapshots/main__bool_comparison_fix.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - --- tests/data/bool_comparison.nix 6 - +++ tests/data/bool_comparison.nix [fixed] 7 - @@ -1,27 +1,27 @@ 8 - [ 9 - # trivial 10 - - (a == true) 11 - - (b == true) 12 - - (true == c) 13 - - (true == d) 14 - + a 15 - + b 16 - + c 17 - + d 18 - 19 - # not equals 20 - - (e != true) 21 - - (f != false) 22 - - (true != g) 23 - - (false != h) 24 - + (!e) 25 - + f 26 - + (!g) 27 - + h 28 - 29 - # non-matches 30 - (i == j) 31 - (k != l) 32 - 33 - # both sides bool 34 - - (false == false) 35 - - (false == true) 36 - - (true == false) 37 - - (true == true) 38 - + (!false) 39 - + (!true) 40 - + false 41 - + true 42 - 43 - # has attr 44 - - (false == m ? n) 45 - - (true == o ? p) 46 - + (!m ? n) 47 - + (o ? p) 48 - ]
-102
bin/tests/snapshots/main__bool_comparison_lint.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&stdout" 4 - --- 5 - [W01] Warning: Unnecessary comparison with boolean 6 - ╭─[tests/data/bool_comparison.nix:3:4] 7 - 8 - 3 │ (a == true) 9 - · ────┬──── 10 - · ╰────── Comparing a with boolean literal true 11 - ───╯ 12 - [W01] Warning: Unnecessary comparison with boolean 13 - ╭─[tests/data/bool_comparison.nix:4:4] 14 - 15 - 4 │ (b == true) 16 - · ────┬──── 17 - · ╰────── Comparing b with boolean literal true 18 - ───╯ 19 - [W01] Warning: Unnecessary comparison with boolean 20 - ╭─[tests/data/bool_comparison.nix:5:4] 21 - 22 - 5 │ (true == c) 23 - · ────┬──── 24 - · ╰────── Comparing c with boolean literal true 25 - ───╯ 26 - [W01] Warning: Unnecessary comparison with boolean 27 - ╭─[tests/data/bool_comparison.nix:6:4] 28 - 29 - 6 │ (true == d) 30 - · ────┬──── 31 - · ╰────── Comparing d with boolean literal true 32 - ───╯ 33 - [W01] Warning: Unnecessary comparison with boolean 34 - ╭─[tests/data/bool_comparison.nix:9:4] 35 - 36 - 9 │ (e != true) 37 - · ────┬──── 38 - · ╰────── Comparing e with boolean literal true 39 - ───╯ 40 - [W01] Warning: Unnecessary comparison with boolean 41 - ╭─[tests/data/bool_comparison.nix:10:4] 42 - 43 - 10 │ (f != false) 44 - · ─────┬──── 45 - · ╰────── Comparing f with boolean literal false 46 - ────╯ 47 - [W01] Warning: Unnecessary comparison with boolean 48 - ╭─[tests/data/bool_comparison.nix:11:4] 49 - 50 - 11 │ (true != g) 51 - · ────┬──── 52 - · ╰────── Comparing g with boolean literal true 53 - ────╯ 54 - [W01] Warning: Unnecessary comparison with boolean 55 - ╭─[tests/data/bool_comparison.nix:12:4] 56 - 57 - 12 │ (false != h) 58 - · ─────┬──── 59 - · ╰────── Comparing h with boolean literal false 60 - ────╯ 61 - [W01] Warning: Unnecessary comparison with boolean 62 - ╭─[tests/data/bool_comparison.nix:19:4] 63 - 64 - 19 │ (false == false) 65 - · ───────┬────── 66 - · ╰──────── Comparing false with boolean literal false 67 - ────╯ 68 - [W01] Warning: Unnecessary comparison with boolean 69 - ╭─[tests/data/bool_comparison.nix:20:4] 70 - 71 - 20 │ (false == true) 72 - · ──────┬────── 73 - · ╰──────── Comparing true with boolean literal false 74 - ────╯ 75 - [W01] Warning: Unnecessary comparison with boolean 76 - ╭─[tests/data/bool_comparison.nix:21:4] 77 - 78 - 21 │ (true == false) 79 - · ──────┬────── 80 - · ╰──────── Comparing false with boolean literal true 81 - ────╯ 82 - [W01] Warning: Unnecessary comparison with boolean 83 - ╭─[tests/data/bool_comparison.nix:22:4] 84 - 85 - 22 │ (true == true) 86 - · ──────┬───── 87 - · ╰─────── Comparing true with boolean literal true 88 - ────╯ 89 - [W01] Warning: Unnecessary comparison with boolean 90 - ╭─[tests/data/bool_comparison.nix:25:4] 91 - 92 - 25 │ (false == m ? n) 93 - · ───────┬────── 94 - · ╰──────── Comparing m ? n with boolean literal false 95 - ────╯ 96 - [W01] Warning: Unnecessary comparison with boolean 97 - ╭─[tests/data/bool_comparison.nix:26:4] 98 - 99 - 26 │ (true == o ? p) 100 - · ──────┬────── 101 - · ╰──────── Comparing o ? p with boolean literal true 102 - ────╯
+2
macros/Cargo.toml
··· 7 7 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 8 9 9 [dependencies] 10 + hex.workspace = true 10 11 proc-macro2.workspace = true 11 12 quote.workspace = true 13 + sha2.workspace = true 12 14 syn.workspace = true 13 15 14 16 [lib]
+6
macros/src/lib.rs
··· 1 1 mod explain; 2 2 mod metadata; 3 + mod test; 3 4 4 5 use explain::generate_explain_impl; 5 6 use metadata::{RawLintMeta, generate_meta_impl}; ··· 43 44 }) 44 45 .into() 45 46 } 47 + 48 + #[proc_macro] 49 + pub fn generate_tests(input: TokenStream) -> TokenStream { 50 + crate::test::generate_tests(input) 51 + }
+110
macros/src/test.rs
··· 1 + use proc_macro::TokenStream; 2 + use quote::{ToTokens, quote}; 3 + use sha2::{Digest, Sha256}; 4 + use syn::{ 5 + Error, ExprArray, ExprLit, Ident, Lit, LitStr, Token, 6 + parse::{Parse, ParseStream}, 7 + parse_macro_input, 8 + spanned::Spanned, 9 + }; 10 + 11 + struct MacroInvocation { 12 + rule: Ident, 13 + expressions: Vec<LitStr>, 14 + } 15 + 16 + impl Parse for MacroInvocation { 17 + fn parse(input: ParseStream) -> syn::Result<Self> { 18 + const RULE_VALUE: &str = "rule"; 19 + const EXPRESSSIONS_VALUE: &str = "expressions"; 20 + let rule_attribute = input.parse::<Ident>()?; 21 + 22 + if rule_attribute != RULE_VALUE { 23 + return Err(Error::new( 24 + rule_attribute.span(), 25 + "expected `{RULE_VALUE:?}`", 26 + )); 27 + } 28 + 29 + input.parse::<Token![:]>()?; 30 + let rule = input.parse::<Ident>()?; 31 + input.parse::<Token![,]>()?; 32 + let expressions = input.parse::<Ident>()?; 33 + 34 + if expressions != EXPRESSSIONS_VALUE { 35 + return Err(Error::new( 36 + expressions.span(), 37 + "expected `{EXPRESSSIONS_VALUE:?}`", 38 + )); 39 + } 40 + 41 + input.parse::<Token![:]>()?; 42 + let ExprArray { elems, .. } = input.parse::<ExprArray>()?; 43 + 44 + let expressions = elems 45 + .into_iter() 46 + .map(|expr| match expr { 47 + syn::Expr::Lit(ExprLit { 48 + lit: Lit::Str(nix_expression), 49 + .. 50 + }) => Ok(nix_expression), 51 + _ => Err(Error::new(expr.span(), "expected a literal string")), 52 + }) 53 + .collect::<Result<Vec<_>, _>>()?; 54 + 55 + input.parse::<Token![,]>()?; 56 + Ok(MacroInvocation { rule, expressions }) 57 + } 58 + } 59 + 60 + pub fn generate_tests(input: TokenStream) -> TokenStream { 61 + let MacroInvocation { rule, expressions } = parse_macro_input!(input as MacroInvocation); 62 + expressions 63 + .into_iter() 64 + .map(|nix_expression| { 65 + let lint_test = make_test(&rule, TestKind::Lint, &nix_expression); 66 + let fix_test = make_test(&rule, TestKind::Fix, &nix_expression); 67 + 68 + quote! { 69 + #lint_test 70 + 71 + #fix_test 72 + } 73 + }) 74 + .collect::<proc_macro2::TokenStream>() 75 + .into() 76 + } 77 + 78 + #[derive(Clone, Copy, Debug)] 79 + enum TestKind { 80 + Lint, 81 + Fix, 82 + } 83 + 84 + fn make_test(rule: &Ident, kind: TestKind, nix_expression: &LitStr) -> proc_macro2::TokenStream { 85 + let expression_hash = Sha256::digest(nix_expression.to_token_stream().to_string()); 86 + let expression_hash = hex::encode(expression_hash); 87 + 88 + let kind_str = match kind { 89 + TestKind::Lint => "lint", 90 + TestKind::Fix => "fix", 91 + }; 92 + 93 + let test_name = format!("{rule}_{kind_str}_{expression_hash}"); 94 + let test_ident = Ident::new(&test_name, nix_expression.span()); 95 + let snap_name = format!("{kind_str}_{expression_hash}"); 96 + 97 + let args = match kind { 98 + TestKind::Lint => quote! {&["check"]}, 99 + TestKind::Fix => quote! {&["fix", "--dry-run"]}, 100 + }; 101 + 102 + quote! { 103 + #[test] 104 + fn #test_ident() { 105 + let expression = #nix_expression; 106 + let stdout = _utils::test_cli(expression, #args).unwrap(); 107 + insta::assert_snapshot!(#snap_name, stdout, &format!("{expression:?}")); 108 + } 109 + } 110 + }