From 16ef8447c83b23ded72b21231283f31d74bc9d33 Mon Sep 17 00:00:00 2001 From: "Shahar \"Dawn\" Or" Date: Mon, 13 Oct 2025 06:21:34 +0700 Subject: [PATCH] chore: 1-expr tests bool-comparison Co-authored-by: Wes Gray --- Cargo.lock | 193 +++++++++++++++++- Cargo.toml | 6 +- bin/Cargo.toml | 3 + bin/tests/_utils.rs | 22 ++ bin/tests/bool_comparison.rs | 30 +++ bin/tests/data/bool_comparison.nix | 27 --- bin/tests/main.rs | 1 - ...d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap | 9 + ...0af8951e09a9a9891d29b3ba9e762a2978adb.snap | 9 + ...c464f576f6a4446acc939f98ebb9329d6b700.snap | 5 + ...86ba7a32f5546c3a2194d2636a2684391e3f1.snap | 9 + ...8db36bce21a1cb65b60ec15b901e87b62c13a.snap | 9 + ...2832657a82dd5a58392f23345b22467a89b1a.snap | 9 + ...30499b7344b794644163af528b0c834c5cca4.snap | 9 + ...89ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap | 9 + ...99db3e016d21e6183a706845dfed17d803393.snap | 9 + ...232840736b9034ef1b55d1c8c92b9f5098a14.snap | 9 + ...ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap | 9 + ...cab32d5e69473f7a6b6fe660eec020d70993d.snap | 9 + ...f9612a7d67a527e818e7b599d193265345cc6.snap | 5 + ...2b65cd144d55b060637c5ff8085d81bef6c49.snap | 9 + ...6bf4b645ebdaf948399be54f775686a58347b.snap | 9 + ...87a7c1a667495e18432ed8f38540fd051cec1.snap | 9 + ...d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap | 11 + ...0af8951e09a9a9891d29b3ba9e762a2978adb.snap | 11 + ...c464f576f6a4446acc939f98ebb9329d6b700.snap | 5 + ...86ba7a32f5546c3a2194d2636a2684391e3f1.snap | 11 + ...8db36bce21a1cb65b60ec15b901e87b62c13a.snap | 11 + ...2832657a82dd5a58392f23345b22467a89b1a.snap | 11 + ...30499b7344b794644163af528b0c834c5cca4.snap | 11 + ...89ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap | 11 + ...99db3e016d21e6183a706845dfed17d803393.snap | 11 + ...232840736b9034ef1b55d1c8c92b9f5098a14.snap | 11 + ...ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap | 11 + ...cab32d5e69473f7a6b6fe660eec020d70993d.snap | 11 + ...f9612a7d67a527e818e7b599d193265345cc6.snap | 5 + ...2b65cd144d55b060637c5ff8085d81bef6c49.snap | 11 + ...6bf4b645ebdaf948399be54f775686a58347b.snap | 11 + ...87a7c1a667495e18432ed8f38540fd051cec1.snap | 11 + .../snapshots/main__bool_comparison_fix.snap | 48 ----- .../snapshots/main__bool_comparison_lint.snap | 102 --------- macros/Cargo.toml | 2 + macros/src/lib.rs | 6 + macros/src/test.rs | 110 ++++++++++ 44 files changed, 664 insertions(+), 186 deletions(-) create mode 100644 bin/tests/_utils.rs create mode 100644 bin/tests/bool_comparison.rs delete mode 100644 bin/tests/data/bool_comparison.nix create mode 100644 bin/tests/snapshots/bool_comparison__fix_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap create mode 100644 bin/tests/snapshots/bool_comparison__fix_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap create mode 100644 bin/tests/snapshots/bool_comparison__lint_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap delete mode 100644 bin/tests/snapshots/main__bool_comparison_fix.snap delete mode 100644 bin/tests/snapshots/main__bool_comparison_lint.snap create mode 100644 macros/src/test.rs diff --git a/Cargo.lock b/Cargo.lock index 6a2be5e..024449f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + [[package]] name = "ariadne" version = "0.1.3" @@ -49,6 +55,21 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bstr" version = "0.2.17" @@ -71,7 +92,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "indexmap", "lazy_static", @@ -113,6 +134,15 @@ version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-channel" version = "0.5.2" @@ -157,6 +187,26 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" version = "1.6.1" @@ -169,12 +219,50 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi", +] + [[package]] name = "globset" version = "0.4.8" @@ -218,6 +306,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "ignore" version = "0.4.18" @@ -254,6 +348,7 @@ checksum = "46fdb647ebde000f43b5b53f773c30cf9b0cb4300453208713fa38b2c70935a0" dependencies = [ "console", "once_cell", + "regex", "similar", ] @@ -283,9 +378,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.106" +version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "log" @@ -300,8 +401,10 @@ dependencies = [ name = "macros" version = "0.0.0" dependencies = [ + "hex", "proc-macro2", "quote", + "sha2", "syn 2.0.106", ] @@ -402,6 +505,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rayon" version = "1.5.1" @@ -429,9 +538,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -440,9 +549,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "rnix" @@ -472,6 +581,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +dependencies = [ + "bitflags 2.9.4", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.5" @@ -524,6 +646,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "similar" version = "2.1.0" @@ -534,11 +667,13 @@ checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3" name = "statix" version = "0.5.8" dependencies = [ + "anyhow", "ariadne", "clap", "ignore", "insta", "lib", + "macros", "paste", "rayon", "rnix", @@ -547,6 +682,7 @@ dependencies = [ "serde_json", "similar", "strip-ansi-escapes", + "tempfile", "thiserror", "toml", "vfs", @@ -589,6 +725,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -651,6 +800,12 @@ dependencies = [ "serde", ] +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + [[package]] name = "unicase" version = "2.6.0" @@ -730,6 +885,24 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -834,6 +1007,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + [[package]] name = "yansi" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 67c0d65..888a64a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,13 @@ edition = "2024" license = "MIT" [workspace.dependencies] +anyhow = "1.0.100" ariadne = "0.1.3" clap = "3.0.0-beta.4" +hex = "0.4.3" ignore = "0.4.18" indexmap = "1.6.2" -insta = "1.43.2" +insta = { features = ["filters"], version = "1.43.2" } lazy_static = "1.0" lib.path = "./lib" macros.path = "./macros" @@ -24,9 +26,11 @@ rnix = "0.12.0" rowan = "0.15.17" serde = { features = ["derive"], version = "1.0.68" } serde_json = { version = "1.0.68" } +sha2 = "0.10.9" similar = "2.1.0" strip-ansi-escapes = "0.1.1" syn = { features = ["full"], version = "2.0" } +tempfile = "3.23.0" thiserror = "1.0.30" toml = "0.5.8" vfs.path = "./vfs" diff --git a/bin/Cargo.toml b/bin/Cargo.toml index 06c3d09..77c66b0 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -15,16 +15,19 @@ name = "statix" path = "src/main.rs" [dependencies] +anyhow.workspace = true ariadne.workspace = true clap.workspace = true ignore.workspace = true lib.workspace = true +macros.workspace = true rayon.workspace = true rnix.workspace = true rowan.workspace = true serde.workspace = true serde_json = { optional = true, workspace = true } similar.workspace = true +tempfile.workspace = true thiserror.workspace = true toml.workspace = true vfs.workspace = true diff --git a/bin/tests/_utils.rs b/bin/tests/_utils.rs new file mode 100644 index 0000000..6dcc2a7 --- /dev/null +++ b/bin/tests/_utils.rs @@ -0,0 +1,22 @@ +use std::{io::Write, process::Command}; + +use tempfile::NamedTempFile; + +pub fn test_cli(expression: &str, args: &[&str]) -> anyhow::Result { + let mut fixture = NamedTempFile::with_suffix(".nix")?; + fixture.write_all(expression.as_bytes())?; + fixture.write_all(b"\n")?; // otherwise diff says there's no newline at end of file + + let output = Command::new("cargo") + .arg("run") + .arg("--") + .args(args) + .arg(fixture.path()) + .output()?; + + let stdout = strip_ansi_escapes::strip(output.stdout)?; + let stdout = String::from_utf8(stdout)?; + let stdout = stdout.replace(fixture.path().to_str().unwrap(), ""); + + Ok(stdout) +} diff --git a/bin/tests/bool_comparison.rs b/bin/tests/bool_comparison.rs new file mode 100644 index 0000000..a2c889f --- /dev/null +++ b/bin/tests/bool_comparison.rs @@ -0,0 +1,30 @@ +mod _utils; + +use macros::generate_tests; + +generate_tests! { + rule: bool_comparison, + expressions: [ + // trivial + "a == true", + "b == true", + "true == c", + "true == d", + // not equals + "e != true", + "f != false", + "true != g", + "false != h", + // non-matches + "i == j", + "k != l", + // both sides bool + "false == false", + "false == true", + "true == false", + "true == true", + // has attr + "false == m ? n", + "true == o ? p", + ], +} diff --git a/bin/tests/data/bool_comparison.nix b/bin/tests/data/bool_comparison.nix deleted file mode 100644 index 28b3b1e..0000000 --- a/bin/tests/data/bool_comparison.nix +++ /dev/null @@ -1,27 +0,0 @@ -[ - # trivial - (a == true) - (b == true) - (true == c) - (true == d) - - # not equals - (e != true) - (f != false) - (true != g) - (false != h) - - # non-matches - (i == j) - (k != l) - - # both sides bool - (false == false) - (false == true) - (true == false) - (true == true) - - # has attr - (false == m ? n) - (true == o ? p) -] diff --git a/bin/tests/main.rs b/bin/tests/main.rs index b4e9441..51d913d 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs @@ -44,7 +44,6 @@ fn test_cli(test_name: &str, file_path: &str, args: &[&str]) { } test_lint! { - bool_comparison, empty_let_in, manual_inherit, manual_inherit_from, diff --git a/bin/tests/snapshots/bool_comparison__fix_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap b/bin/tests/snapshots/bool_comparison__fix_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap new file mode 100644 index 0000000..cc8620a --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"f != false\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-f != false ++f diff --git a/bin/tests/snapshots/bool_comparison__fix_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap b/bin/tests/snapshots/bool_comparison__fix_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap new file mode 100644 index 0000000..211d245 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == d\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true == d ++d diff --git a/bin/tests/snapshots/bool_comparison__fix_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap b/bin/tests/snapshots/bool_comparison__fix_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap new file mode 100644 index 0000000..d551c5b --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"k != l\"" +--- + diff --git a/bin/tests/snapshots/bool_comparison__fix_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap b/bin/tests/snapshots/bool_comparison__fix_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap new file mode 100644 index 0000000..cb1c9f7 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == false\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-false == false ++!false diff --git a/bin/tests/snapshots/bool_comparison__fix_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap b/bin/tests/snapshots/bool_comparison__fix_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap new file mode 100644 index 0000000..f27140b --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false != h\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-false != h ++h diff --git a/bin/tests/snapshots/bool_comparison__fix_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap b/bin/tests/snapshots/bool_comparison__fix_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap new file mode 100644 index 0000000..745004a --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == true\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true == true ++true diff --git a/bin/tests/snapshots/bool_comparison__fix_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap b/bin/tests/snapshots/bool_comparison__fix_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap new file mode 100644 index 0000000..672e178 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == c\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true == c ++c diff --git a/bin/tests/snapshots/bool_comparison__fix_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap b/bin/tests/snapshots/bool_comparison__fix_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap new file mode 100644 index 0000000..b9e508b --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true != g\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true != g ++!g diff --git a/bin/tests/snapshots/bool_comparison__fix_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap b/bin/tests/snapshots/bool_comparison__fix_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap new file mode 100644 index 0000000..4a9c983 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"b == true\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-b == true ++b diff --git a/bin/tests/snapshots/bool_comparison__fix_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap b/bin/tests/snapshots/bool_comparison__fix_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap new file mode 100644 index 0000000..5983024 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == m ? n\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-false == m ? n ++!m ? n diff --git a/bin/tests/snapshots/bool_comparison__fix_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap b/bin/tests/snapshots/bool_comparison__fix_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap new file mode 100644 index 0000000..bcf6e72 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"a == true\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-a == true ++a diff --git a/bin/tests/snapshots/bool_comparison__fix_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap b/bin/tests/snapshots/bool_comparison__fix_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap new file mode 100644 index 0000000..9ceb964 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == o ? p\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true == o ? p ++o ? p diff --git a/bin/tests/snapshots/bool_comparison__fix_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap b/bin/tests/snapshots/bool_comparison__fix_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap new file mode 100644 index 0000000..90d1b49 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"i == j\"" +--- + diff --git a/bin/tests/snapshots/bool_comparison__fix_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap b/bin/tests/snapshots/bool_comparison__fix_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap new file mode 100644 index 0000000..d5e0a1e --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == true\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-false == true ++!true diff --git a/bin/tests/snapshots/bool_comparison__fix_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap b/bin/tests/snapshots/bool_comparison__fix_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap new file mode 100644 index 0000000..87f4adb --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"e != true\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-e != true ++!e diff --git a/bin/tests/snapshots/bool_comparison__fix_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap b/bin/tests/snapshots/bool_comparison__fix_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap new file mode 100644 index 0000000..5e06117 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__fix_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap @@ -0,0 +1,9 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == false\"" +--- +--- ++++ [fixed] +@@ -1 +1 @@ +-true == false ++false diff --git a/bin/tests/snapshots/bool_comparison__lint_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap b/bin/tests/snapshots/bool_comparison__lint_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap new file mode 100644 index 0000000..e3f5206 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_101b3f071d9ef6e1c6cddd4b3d4d2a4f7d4cf2764ff5811ee2d532b3ccb45690.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"f != false\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ f != false + · ─────┬──── + · ╰────── Comparing f with boolean literal false +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap b/bin/tests/snapshots/bool_comparison__lint_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap new file mode 100644 index 0000000..f2923f3 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_43a857afe823ef70b47d4e0fbf00af8951e09a9a9891d29b3ba9e762a2978adb.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == d\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true == d + · ────┬──── + · ╰────── Comparing d with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap b/bin/tests/snapshots/bool_comparison__lint_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap new file mode 100644 index 0000000..d551c5b --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_4e4d41c24c973c0bc560aeaaf95c464f576f6a4446acc939f98ebb9329d6b700.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"k != l\"" +--- + diff --git a/bin/tests/snapshots/bool_comparison__lint_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap b/bin/tests/snapshots/bool_comparison__lint_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap new file mode 100644 index 0000000..bd0f41a --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_5d2c71eef69cc07e519dc3646f786ba7a32f5546c3a2194d2636a2684391e3f1.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == false\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ false == false + · ───────┬────── + · ╰──────── Comparing false with boolean literal false +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap b/bin/tests/snapshots/bool_comparison__lint_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap new file mode 100644 index 0000000..76e6951 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_630b66ca8810d52f4e68ed1c8d68db36bce21a1cb65b60ec15b901e87b62c13a.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false != h\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ false != h + · ─────┬──── + · ╰────── Comparing h with boolean literal false +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap b/bin/tests/snapshots/bool_comparison__lint_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap new file mode 100644 index 0000000..cd7a424 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_82b623ef0ecd1e0e70c1dbe39f02832657a82dd5a58392f23345b22467a89b1a.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == true\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true == true + · ──────┬───── + · ╰─────── Comparing true with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap b/bin/tests/snapshots/bool_comparison__lint_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap new file mode 100644 index 0000000..cf663e7 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_9f48ebd94e1733d7ccda130d62830499b7344b794644163af528b0c834c5cca4.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == c\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true == c + · ────┬──── + · ╰────── Comparing c with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap b/bin/tests/snapshots/bool_comparison__lint_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap new file mode 100644 index 0000000..9251f71 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_a09de9082d480f3e54de569de2789ebfee65a1ecbd31dcbdfc543b8b13e4bda4.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true != g\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true != g + · ────┬──── + · ╰────── Comparing g with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap b/bin/tests/snapshots/bool_comparison__lint_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap new file mode 100644 index 0000000..9ae1c7b --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_a11a365119d2c64750d4253426c99db3e016d21e6183a706845dfed17d803393.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"b == true\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ b == true + · ────┬──── + · ╰────── Comparing b with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap b/bin/tests/snapshots/bool_comparison__lint_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap new file mode 100644 index 0000000..b340830 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_a14c6695accf2da707eaeb76ded232840736b9034ef1b55d1c8c92b9f5098a14.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == m ? n\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ false == m ? n + · ───────┬────── + · ╰──────── Comparing m ? n with boolean literal false +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap b/bin/tests/snapshots/bool_comparison__lint_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap new file mode 100644 index 0000000..8dba507 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_a30c834e61da781cbcbc0c95b79ab0a51a81f1fdc5a5d885d778f43d268ed2b3.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"a == true\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ a == true + · ────┬──── + · ╰────── Comparing a with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap b/bin/tests/snapshots/bool_comparison__lint_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap new file mode 100644 index 0000000..1100232 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_a83e7884e4c039d6517795734c6cab32d5e69473f7a6b6fe660eec020d70993d.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == o ? p\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true == o ? p + · ──────┬────── + · ╰──────── Comparing o ? p with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap b/bin/tests/snapshots/bool_comparison__lint_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap new file mode 100644 index 0000000..90d1b49 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_b3f4aa5bde6c87b7b513da28d18f9612a7d67a527e818e7b599d193265345cc6.snap @@ -0,0 +1,5 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"i == j\"" +--- + diff --git a/bin/tests/snapshots/bool_comparison__lint_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap b/bin/tests/snapshots/bool_comparison__lint_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap new file mode 100644 index 0000000..a75666a --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_ba56854c55bd3954b56d4e0c3d32b65cd144d55b060637c5ff8085d81bef6c49.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"false == true\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ false == true + · ──────┬────── + · ╰──────── Comparing true with boolean literal false +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap b/bin/tests/snapshots/bool_comparison__lint_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap new file mode 100644 index 0000000..223e665 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_c031ce4a7d754ef42071e72da7d6bf4b645ebdaf948399be54f775686a58347b.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"e != true\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ e != true + · ────┬──── + · ╰────── Comparing e with boolean literal true +───╯ diff --git a/bin/tests/snapshots/bool_comparison__lint_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap b/bin/tests/snapshots/bool_comparison__lint_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap new file mode 100644 index 0000000..9d3b3d9 --- /dev/null +++ b/bin/tests/snapshots/bool_comparison__lint_eb450df0fb6d76e9df94f175a6b87a7c1a667495e18432ed8f38540fd051cec1.snap @@ -0,0 +1,11 @@ +--- +source: bin/tests/bool_comparison.rs +expression: "\"true == false\"" +--- +[W01] Warning: Unnecessary comparison with boolean + ╭─[:1:1] + │ + 1 │ true == false + · ──────┬────── + · ╰──────── Comparing false with boolean literal true +───╯ diff --git a/bin/tests/snapshots/main__bool_comparison_fix.snap b/bin/tests/snapshots/main__bool_comparison_fix.snap deleted file mode 100644 index 389d3a5..0000000 --- a/bin/tests/snapshots/main__bool_comparison_fix.snap +++ /dev/null @@ -1,48 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "&stdout" ---- ---- tests/data/bool_comparison.nix -+++ tests/data/bool_comparison.nix [fixed] -@@ -1,27 +1,27 @@ - [ - # trivial -- (a == true) -- (b == true) -- (true == c) -- (true == d) -+ a -+ b -+ c -+ d - - # not equals -- (e != true) -- (f != false) -- (true != g) -- (false != h) -+ (!e) -+ f -+ (!g) -+ h - - # non-matches - (i == j) - (k != l) - - # both sides bool -- (false == false) -- (false == true) -- (true == false) -- (true == true) -+ (!false) -+ (!true) -+ false -+ true - - # has attr -- (false == m ? n) -- (true == o ? p) -+ (!m ? n) -+ (o ? p) - ] diff --git a/bin/tests/snapshots/main__bool_comparison_lint.snap b/bin/tests/snapshots/main__bool_comparison_lint.snap deleted file mode 100644 index 3dd4961..0000000 --- a/bin/tests/snapshots/main__bool_comparison_lint.snap +++ /dev/null @@ -1,102 +0,0 @@ ---- -source: bin/tests/main.rs -expression: "&stdout" ---- -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:3:4] - │ - 3 │ (a == true) - · ────┬──── - · ╰────── Comparing a with boolean literal true -───╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:4:4] - │ - 4 │ (b == true) - · ────┬──── - · ╰────── Comparing b with boolean literal true -───╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:5:4] - │ - 5 │ (true == c) - · ────┬──── - · ╰────── Comparing c with boolean literal true -───╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:6:4] - │ - 6 │ (true == d) - · ────┬──── - · ╰────── Comparing d with boolean literal true -───╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:9:4] - │ - 9 │ (e != true) - · ────┬──── - · ╰────── Comparing e with boolean literal true -───╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:10:4] - │ - 10 │ (f != false) - · ─────┬──── - · ╰────── Comparing f with boolean literal false -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:11:4] - │ - 11 │ (true != g) - · ────┬──── - · ╰────── Comparing g with boolean literal true -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:12:4] - │ - 12 │ (false != h) - · ─────┬──── - · ╰────── Comparing h with boolean literal false -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:19:4] - │ - 19 │ (false == false) - · ───────┬────── - · ╰──────── Comparing false with boolean literal false -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:20:4] - │ - 20 │ (false == true) - · ──────┬────── - · ╰──────── Comparing true with boolean literal false -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:21:4] - │ - 21 │ (true == false) - · ──────┬────── - · ╰──────── Comparing false with boolean literal true -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:22:4] - │ - 22 │ (true == true) - · ──────┬───── - · ╰─────── Comparing true with boolean literal true -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:25:4] - │ - 25 │ (false == m ? n) - · ───────┬────── - · ╰──────── Comparing m ? n with boolean literal false -────╯ -[W01] Warning: Unnecessary comparison with boolean - ╭─[tests/data/bool_comparison.nix:26:4] - │ - 26 │ (true == o ? p) - · ──────┬────── - · ╰──────── Comparing o ? p with boolean literal true -────╯ diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 395ceb6..ca34cb8 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -7,8 +7,10 @@ version = "0.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +hex.workspace = true proc-macro2.workspace = true quote.workspace = true +sha2.workspace = true syn.workspace = true [lib] diff --git a/macros/src/lib.rs b/macros/src/lib.rs index cc10e30..af2324e 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,5 +1,6 @@ mod explain; mod metadata; +mod test; use explain::generate_explain_impl; use metadata::{RawLintMeta, generate_meta_impl}; @@ -43,3 +44,8 @@ pub fn lint(attr: TokenStream, item: TokenStream) -> TokenStream { }) .into() } + +#[proc_macro] +pub fn generate_tests(input: TokenStream) -> TokenStream { + crate::test::generate_tests(input) +} diff --git a/macros/src/test.rs b/macros/src/test.rs new file mode 100644 index 0000000..14419b7 --- /dev/null +++ b/macros/src/test.rs @@ -0,0 +1,110 @@ +use proc_macro::TokenStream; +use quote::{ToTokens, quote}; +use sha2::{Digest, Sha256}; +use syn::{ + Error, ExprArray, ExprLit, Ident, Lit, LitStr, Token, + parse::{Parse, ParseStream}, + parse_macro_input, + spanned::Spanned, +}; + +struct MacroInvocation { + rule: Ident, + expressions: Vec, +} + +impl Parse for MacroInvocation { + fn parse(input: ParseStream) -> syn::Result { + const RULE_VALUE: &str = "rule"; + const EXPRESSSIONS_VALUE: &str = "expressions"; + let rule_attribute = input.parse::()?; + + if rule_attribute != RULE_VALUE { + return Err(Error::new( + rule_attribute.span(), + "expected `{RULE_VALUE:?}`", + )); + } + + input.parse::()?; + let rule = input.parse::()?; + input.parse::()?; + let expressions = input.parse::()?; + + if expressions != EXPRESSSIONS_VALUE { + return Err(Error::new( + expressions.span(), + "expected `{EXPRESSSIONS_VALUE:?}`", + )); + } + + input.parse::()?; + let ExprArray { elems, .. } = input.parse::()?; + + let expressions = elems + .into_iter() + .map(|expr| match expr { + syn::Expr::Lit(ExprLit { + lit: Lit::Str(nix_expression), + .. + }) => Ok(nix_expression), + _ => Err(Error::new(expr.span(), "expected a literal string")), + }) + .collect::, _>>()?; + + input.parse::()?; + Ok(MacroInvocation { rule, expressions }) + } +} + +pub fn generate_tests(input: TokenStream) -> TokenStream { + let MacroInvocation { rule, expressions } = parse_macro_input!(input as MacroInvocation); + expressions + .into_iter() + .map(|nix_expression| { + let lint_test = make_test(&rule, TestKind::Lint, &nix_expression); + let fix_test = make_test(&rule, TestKind::Fix, &nix_expression); + + quote! { + #lint_test + + #fix_test + } + }) + .collect::() + .into() +} + +#[derive(Clone, Copy, Debug)] +enum TestKind { + Lint, + Fix, +} + +fn make_test(rule: &Ident, kind: TestKind, nix_expression: &LitStr) -> proc_macro2::TokenStream { + let expression_hash = Sha256::digest(nix_expression.to_token_stream().to_string()); + let expression_hash = hex::encode(expression_hash); + + let kind_str = match kind { + TestKind::Lint => "lint", + TestKind::Fix => "fix", + }; + + let test_name = format!("{rule}_{kind_str}_{expression_hash}"); + let test_ident = Ident::new(&test_name, nix_expression.span()); + let snap_name = format!("{kind_str}_{expression_hash}"); + + let args = match kind { + TestKind::Lint => quote! {&["check"]}, + TestKind::Fix => quote! {&["fix", "--dry-run"]}, + }; + + quote! { + #[test] + fn #test_ident() { + let expression = #nix_expression; + let stdout = _utils::test_cli(expression, #args).unwrap(); + insta::assert_snapshot!(#snap_name, stdout, &format!("{expression:?}")); + } + } +} -- 2.51.2