[checks] Implement Python checks and fix some violations - #9146
[checks] Implement Python checks and fix some violations#9146eisenwave wants to merge 24 commits into
Conversation
| - name: setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: "20" | ||
|
|
||
| - name: install pyright | ||
| run: npm install -g pyright |
There was a problem hiding this comment.
I'm not sure pyright is a good call. There are other alternatives that do not require pulling in node as dependency.
There was a problem hiding this comment.
I just use it because it integrates nicely with VSCode out of the box. What would you recommend instead?
| message: str, | ||
| ) -> None: | ||
| """Report a failure at `self.file_path`.""" | ||
| emit_check_failure( |
There was a problem hiding this comment.
emit_check_failure is only called from within classes deriving from Check. Can you fold it into fail and consistently use this one?
There was a problem hiding this comment.
After the changes in 7af3d56, I wouldn't want to. The difference is that fail is just a convenience function that provides the file path automatically, and I would want there to be a global "emit failure" function at some level, in case we expand the sources of failures in the future.
emit_check_failure is basically the global console.error counterpart, and that has kind of a right to exist even if you always use it via a wrapper. That might change at some point.
|
@Tsche thanks a lot for the review. It'll take some time to clean it all up. |
|
All the pre-existing issues are taken care of in separate PRs. Now comes rebasing on the latest motions and addressing all the feedback on the Python script. |
1. Nested if statements get flagged. These are replaced with "and". 2. Mutable default initializers for members are flagged. Initialization is moved to __init__.





Fixes #8086
I've mentioned the option to improve the checks in Croydon to @tkoeppe, and he seemed generally open to the idea.
In summary, this PR converts all the checks we have in
check-source.sh(plus some additional once adopted fromcheck-output.sh) and turns them into a Python script. The benefits are:sedandgreppiping. The code is relatively simple Python. It still uses a bunch of regular expressions for a lot of checks; the greatest benefits are in the more complex checks.EXPECTCHECKNEXTLINE.NOCHECKBEGINand other directives. This makes it possible for us to add much more aggressive checks that would have previously been infeasible because they generate too much noise in old TeX sources.\tcode{\exposid{...}}in a part ofnumerics.texbecause there are too many violations.\textitin "newer" TeX ranges for example without having to fix every single violation. We could also use it to catch many "bad words" or "bad phrases" that appear too often to be checked right now, but that we don't want perpetuated.\refto a section that is introduced by another paper, you can still get a green build by suppressing the\refcheck (that is, at least for thecheck-sourcechecks).There are a few notable new checks that make things a lot easier in the future:
base-env-balancingchecks for balancing of\beginand\endcommands. It's quite easy to get it wrong, and when you do, it tends to blow up after minutes during the TeX build in bizarre and hard-to-debug ways.base-unknown-commandchecks for use of TeX commands that have never appeared before in the code base. It's very unlikely that this is intentional in most PRs, and very likely that someone just wrote\tocdeinstead of\tcodeor something else stupid. If we need a new TeX command, we can just add it to the list.