Syndica / sig

a Solana validator client implementation written in Zig
https://syndica.io/sig
Apache License 2.0
219 stars 34 forks source link

fix(scripts): unused import regex and misc refactoring #362

Closed dnut closed 3 weeks ago

dnut commented 3 weeks ago

I noticed the regex for detecting unused imports was changed in a recent PR. This broke the detection of unused imports. The change made it so you would only detect unused lines that explicitly say @import("..."). But those are not the only lines we want to check. We also want to check for things like const Thing = sig.utils.Thing;. The recent change also broke detection of identifiers with numbers and underscores. So I fixed these issues.

I also made the regex slightly better at detecting file paths within @import lines by including / as a valid character. This identified few more unused imports which I also removed in this PR.

I consolidated the code to a main function so it's clearer what's actually running when you run the script.

I used return values to indicate failed checks, instead of directly calling exit(1) within the check function. That way it always runs all the checks, instead of exiting early.

I renamed the file to style.py. check_style.py is misleading because it's not just a check. By default this script will automatically edit the code to adjust its style. Only if you provide the --check flag does it limit itself to checks. At that point, the name is redundant with the flag. I see "style" as analogous to zig's "fmt" subcommand. By default zig fmt will autoformat the code, and then it limits itself to checks if you use --check.