From e65c4042c4bed094f663e039fe1300531ad6dad1 Mon Sep 17 00:00:00 2001 From: Michael Zhao <44533763+Pistonight@users.noreply.github.com> Date: Wed, 4 Feb 2026 12:04:29 -0800 Subject: [PATCH] feat: allow and detect windows line ending, bump deps --- Cargo.lock | 256 +++++++++++++++++++++++++----------------- Cargo.toml | 6 +- README.md | 8 +- src/format.rs | 67 +++++++---- src/main.rs | 4 +- src/runner.rs | 13 ++- tests/fixture_test.rs | 2 +- 7 files changed, 213 insertions(+), 143 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bca9ca2..2a4c647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,13 +61,13 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "3.0.10" +version = "3.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -88,23 +88,32 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "bytes" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "cc" -version = "1.2.51" +version = "1.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", "shlex", @@ -116,24 +125,30 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" dependencies = [ "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-link 0.2.1", + "windows-link", ] [[package]] name = "clap" -version = "4.5.53" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" +checksum = "6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31a" dependencies = [ "clap_builder", "clap_derive", @@ -141,9 +156,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.53" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" +checksum = "7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238" dependencies = [ "anstream", "anstyle", @@ -153,9 +168,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.49" +version = "4.5.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" +checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" dependencies = [ "heck", "proc-macro2", @@ -165,9 +180,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" [[package]] name = "colorchoice" @@ -181,6 +196,29 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "ctrlc" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790" +dependencies = [ + "dispatch2", + "nix", + "windows-sys 0.61.2", +] + +[[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags", + "block2", + "libc", + "objc2", +] + [[package]] name = "dunce" version = "1.0.5" @@ -221,21 +259,20 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed" +checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys 0.60.2", ] [[package]] name = "find-msvc-tools" -version = "0.1.6" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "glob" @@ -263,9 +300,9 @@ checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "iana-time-zone" -version = "0.1.63" +version = "0.1.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -287,9 +324,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", @@ -303,9 +340,9 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" dependencies = [ "once_cell", "wasm-bindgen", @@ -313,15 +350,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.178" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libredox" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ "bitflags", "libc", @@ -336,7 +373,7 @@ checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "lisensor" -version = "0.2.1" +version = "0.2.2" dependencies = [ "chrono", "pistonite-cu", @@ -355,6 +392,18 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -374,6 +423,21 @@ dependencies = [ "libc", ] +[[package]] +name = "objc2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + [[package]] name = "once_cell" version = "1.21.3" @@ -388,9 +452,9 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "oneshot" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ce411919553d3f9fa53a0880544cda985a112117a0444d5ff1e870a893d6ea" +checksum = "269bca4c2591a28585d6bf10d9ed0332b7d76900a1b02bec41bdc3a2cdcda107" [[package]] name = "pathdiff" @@ -406,12 +470,13 @@ checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pistonite-cu" -version = "0.6.8" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9677c885544d200ac3533351856d94ddc3791745129dda953f5dbf021427e73e" +checksum = "f3b18427d8fab2be730e99547fc7d8561b88dcfdbc44ad0c12b133cf54c09511" dependencies = [ "anyhow", "clap", + "ctrlc", "dunce", "env_filter", "filetime", @@ -434,18 +499,18 @@ dependencies = [ [[package]] name = "pistonite-cu-proc-macros" -version = "0.2.3" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a4d4328bb2eeb0a250ca56061e7ca32fff3485bcda1758fab781fd59a64f03" +checksum = "e718dd81a0ec3dd511004e565b521c63a26204d7bfce9100007bbd3e7a11cebf" dependencies = [ "pistonite-pm", ] [[package]] name = "pistonite-pm" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8c0b5010d5525ffbc3d4d1c3338b6167b03b6980553c042093f5b04736213fa" +checksum = "bb759ff95dafff75b9b43ed487a6eff22630bbf8d2d4b220ba97f307dfea2c65" dependencies = [ "proc-macro2", "quote", @@ -454,36 +519,36 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.104" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.42" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.5.18" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -493,9 +558,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -504,9 +569,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "rustix" @@ -580,9 +645,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.112" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21f182278bf2d2bcb3c88b1b08a37df029d71ce3d3ae26168e3c653b213b99d4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -601,9 +666,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.48.0" +version = "1.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" dependencies = [ "bytes", "pin-project-lite", @@ -623,9 +688,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.9.10+spec-1.1.0" +version = "0.9.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0825052159284a1a8b4d6c0c86cbc801f2da5afd2b225fa548c72f2e74002f48" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ "indexmap", "serde_core", @@ -680,35 +745,22 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -716,22 +768,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" dependencies = [ "unicode-ident", ] @@ -749,22 +801,22 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.61.2" +version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement", "windows-interface", - "windows-link 0.1.3", + "windows-link", "windows-result", "windows-strings", ] [[package]] name = "windows-implement" -version = "0.60.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", @@ -773,21 +825,15 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.59.1" +version = "0.59.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "windows-link" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" - [[package]] name = "windows-link" version = "0.2.1" @@ -796,20 +842,20 @@ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-result" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ - "windows-link 0.1.3", + "windows-link", ] [[package]] name = "windows-strings" -version = "0.4.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ - "windows-link 0.1.3", + "windows-link", ] [[package]] @@ -827,7 +873,7 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -836,7 +882,7 @@ version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ - "windows-link 0.2.1", + "windows-link", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", diff --git a/Cargo.toml b/Cargo.toml index c880d5b..139c145 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lisensor" -version = "0.2.1" +version = "0.2.2" edition = "2024" description = "Tool to automatically add, check, and fix license notices in the source files" license = "MIT" @@ -17,12 +17,12 @@ exclude = [ [dependencies] -chrono = "0.4.42" +chrono = "0.4.43" serde = "1" [dependencies.cu] package = "pistonite-cu" -version = "0.6.8" +version = "0.7.4" features = ["print", "fs", "coroutine-heavy", "toml"] # path = "../cu/packages/copper" diff --git a/README.md b/README.md index 8d15336..89c0d4d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ about this format. For languages such as python, the comment style will automatically be changed to `#` instead of `//`. Languages that do not have -either of the comment styles are currently not supported. (Feel free to PR). +either of the comment styles are currently not supported. +(Feel free to PR, it will need to be added to `src/format.rs`). ## Usage @@ -181,8 +182,9 @@ for `Foobar contributors`, but will not touch anything below the sentinel line. Other: - Line ending: - - When checking, any line ending is accepted. - - When fixing, it will turn the file into UNIX line ending. + - When checking, any line ending is accepted (including mixed) + - When fixing, it will turn the file into UNIX line ending unless + the byte sequence `b"\r\n"` (CRLF) is found anywhere in the file - When checking, only the first 2 lines are checked, the rest of the file is ignored. - When fixing, if the third line is not a sentinel line or empty line, diff --git a/src/format.rs b/src/format.rs index 10ca23f..6539a4e 100644 --- a/src/format.rs +++ b/src/format.rs @@ -7,6 +7,8 @@ use std::sync::LazyLock; use cu::pre::*; +const DEFAULT_YEAR: u32 = 2025; // The year this tool is made + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Format { /// The `// ...` format @@ -64,21 +66,23 @@ impl Format { year_start: u32, holder: &str, license: &str, + is_crlf: bool, buf: &mut String, ) -> cu::Result<()> { use std::fmt::Write as _; let year_end = current_year(); + let le = if is_crlf { "\r\n" } else { "\n" }; match self { Self::SlashSlash => { if year_start == year_end { write!( buf, - "// SPDX-License-Identifier: {license}\n// Copyright (c) {year_start} {holder}\n" + "// SPDX-License-Identifier: {license}{le}// Copyright (c) {year_start} {holder}{le}" )?; } else { write!( buf, - "// SPDX-License-Identifier: {license}\n// Copyright (c) {year_start}-{year_end} {holder}\n" + "// SPDX-License-Identifier: {license}{le}// Copyright (c) {year_start}-{year_end} {holder}{le}" )?; } } @@ -86,12 +90,12 @@ impl Format { if year_start == year_end { write!( buf, - "# SPDX-License-Identifier: {license}\n# Copyright (c) {year_start} {holder}\n" + "# SPDX-License-Identifier: {license}{le}# Copyright (c) {year_start} {holder}{le}" )?; } else { write!( buf, - "# SPDX-License-Identifier: {license}\n# Copyright (c) {year_start}-{year_end} {holder}\n" + "# SPDX-License-Identifier: {license}{le}# Copyright (c) {year_start}-{year_end} {holder}{le}" )?; } } @@ -134,26 +138,31 @@ pub fn check_file(path: &Path, expected_holder: &str, expected_license: &str) -> pub fn fix_file(path: &Path, expected_holder: &str, expected_license: &str) -> cu::Result<()> { let format = Format::from_path(path); - let reader = cu::fs::reader(path)?; - let lines = reader.lines(); + let file_content = cu::fs::read_string(path)?; + let lines = file_content.lines(); let mut buf = FixBuf::default(); + // usually this should only go through the first line + // unless the file is unconventional + if file_content.contains("\r\n") { + cu::debug!("will use CRLF for file '{}'", path.display()); + buf.set_crlf(true); + } let mut found_license_line = false; let mut found_copyright_line = false; let mut found_sentinel = false; for line in lines { - let line = cu::check!(line, "error while reading file '{}'", path.display())?; if found_sentinel { - buf.push_line(&line, format); + buf.push_line(line, format); continue; } - if format.starts_with_sentinel(&line) { + if format.starts_with_sentinel(line) { found_sentinel = true; - buf.push_line(&line, format); + buf.push_line(line, format); continue; } - if format.check_strip_license_line(&line).is_some() { + if format.check_strip_license_line(line).is_some() { if found_license_line { cu::bail!( "multiple license line found! Consider adding a sentinel line if there are other license notices that need to be kept!" @@ -162,7 +171,7 @@ pub fn fix_file(path: &Path, expected_holder: &str, expected_license: &str) -> c found_license_line = true; continue; } - if let Some(copyright_info) = format.check_strip_copyright_line(&line) { + if let Some(copyright_info) = format.check_strip_copyright_line(line) { if found_copyright_line { cu::bail!( "multiple copyright line found! Consider adding a sentinel line if there are other license notices that need to be kept!" @@ -176,7 +185,7 @@ pub fn fix_file(path: &Path, expected_holder: &str, expected_license: &str) -> c buf.perform_fix_if_need(format, year_start, expected_holder, expected_license)?; continue; } - buf.push_line(&line, format); + buf.push_line(line, format); } // format new notice if didn't find one buf.perform_fix_if_need(format, current_year(), expected_holder, expected_license)?; @@ -188,25 +197,30 @@ pub fn fix_file(path: &Path, expected_holder: &str, expected_license: &str) -> c #[derive(Default)] struct FixBuf { buf: String, + is_crlf: bool, fixed: bool, fixed_when_empty: bool, } impl FixBuf { + pub fn set_crlf(&mut self, crlf: bool) { + self.is_crlf = crlf; + } fn push_line(&mut self, line: &str, format: Format) { + let le_byte_len = if self.is_crlf { 2 } else { 1 }; if self.fixed_when_empty { if !format.starts_with_sentinel(line) && !line.is_empty() { - self.buf.reserve(line.len() + 2); - self.buf.push('\n'); + self.buf.reserve(line.len() + le_byte_len * 2); + self.push_line_ending(); } else { - self.buf.reserve(line.len() + 1); + self.buf.reserve(line.len() + le_byte_len); } self.fixed_when_empty = false; } else { - self.buf.reserve(line.len() + 1); + self.buf.reserve(line.len() + le_byte_len); } self.buf.push_str(line); - self.buf.push('\n'); + self.push_line_ending(); } fn perform_fix_if_need( &mut self, @@ -219,12 +233,12 @@ impl FixBuf { return Ok(()); } let current_content = std::mem::take(&mut self.buf); - format.format(year_start, holder, license, &mut self.buf)?; + format.format(year_start, holder, license, self.is_crlf, &mut self.buf)?; // add an empty line if needed if !current_content.is_empty() { if !format.starts_with_sentinel(¤t_content) && !current_content.starts_with('\n') { - self.buf.push('\n'); + self.push_line_ending(); } } else { self.fixed_when_empty = true; @@ -233,18 +247,25 @@ impl FixBuf { self.fixed = true; Ok(()) } + fn push_line_ending(&mut self) { + if self.is_crlf { + self.buf.push_str("\r\n"); + } else { + self.buf.push('\n'); + } + } } fn parse_copyright_info(info: &str) -> (u32, u32, &str) { let mut parts = info.splitn(2, ' '); let (year_start, year_end) = match parts.next() { - None => (2025, 2025), + None => (DEFAULT_YEAR, DEFAULT_YEAR), Some(x) => { let mut parts = x.splitn(2, '-'); let year_start = parts .next() .and_then(|x| cu::parse::(x).ok()) - .unwrap_or(2025); + .unwrap_or(DEFAULT_YEAR); let year_end = parts .next() .and_then(|x| cu::parse::(x).ok()) @@ -259,7 +280,7 @@ fn parse_copyright_info(info: &str) -> (u32, u32, &str) { fn current_year() -> u32 { if cfg!(test) { // mock current year in tests - return 2025; + return DEFAULT_YEAR; } static YEAR: LazyLock = LazyLock::new(|| { use chrono::Datelike; diff --git a/src/main.rs b/src/main.rs index abced0a..3ca2387 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,9 @@ async fn main(mut args: Cli) -> cu::Result<()> { if result.is_err() { if fix { - cu::bailfyi!("some issues could not be fixed automatically."); + cu::bail!("some issues could not be fixed automatically."); } else { - cu::bailfyi!("license check unsuccesful."); + cu::bail!("license check unsuccesful."); } } diff --git a/src/runner.rs b/src/runner.rs index ef1618e..55f7816 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -29,11 +29,14 @@ impl std::fmt::Display for Failure { /// - `Ok(Err(failure))` means the run was successful, but issues are found. /// - `Err(e)` means the run itself was not successful. pub async fn run(config: Config, fix: bool) -> cu::Result> { - let bar = cu::progress_unbounded_lowp(if fix { + let bar = cu::progress(if fix { "fixing files" } else { "processing files" - }); + }) + .keep(false) + .total(0) + .spawn(); let mut path_map = BTreeMap::new(); let mut handles = Vec::new(); @@ -66,7 +69,7 @@ pub async fn run(config: Config, fix: bool) -> cu::Result> { // put handles into a set to be auto aborted // with error handling below let total = handles.len(); - bar.set_total(total); + bar.set_total(total as u64); let mut set = cu::co::set(handles); // handle glob errors first @@ -81,7 +84,6 @@ pub async fn run(config: Config, fix: bool) -> cu::Result> { cu::bail!("error while searching for files"); } - let mut count = 0; let mut errors = vec![]; while let Some(result) = set.next().await { // join error @@ -90,8 +92,7 @@ pub async fn run(config: Config, fix: bool) -> cu::Result> { if let Err(e) = result { errors.push(e) } - count += 1; - cu::progress!(&bar, count, "{}", path.display()); + cu::progress!(bar += 1, "{}", path.display()); } if !errors.is_empty() { diff --git a/tests/fixture_test.rs b/tests/fixture_test.rs index 4985a32..59865c6 100644 --- a/tests/fixture_test.rs +++ b/tests/fixture_test.rs @@ -6,7 +6,7 @@ use std::path::Path; use lisensor::{Config, run}; pub fn run_fixture(name: &str) -> cu::Result<()> { - cu::init_print_options(cu::lv::Color::Never, cu::lv::Print::QuietQuiet, None); + cu::cli::level("qq"); let update_output = std::env::var("FIXTURE_UPDATE").unwrap_or_default().as_str() == "1"; let fixtures = Path::new("tests").join("fixtures");