Zulip Chat Archive
Stream: lean4
Topic: Configuring/modernizing runLinter
Michael Rothgang (Jul 11 2024 at 17:49):
Occasionally, I would like to configure the behaviour of runLinter, such as
- also run lint X (say, the docBlameThm linter)[1]
- only run lint X/omit lint Y (say, if I'm running on all of mathlib; the simpNF linters take a while on my computer)
In addition, the user experience of using runLinter
can be improved: no --help output, no documentation what its inputs do. They are all somewhat obvious, but not quite. I remember looking for a way to do the above; it took me a while to figure out this was not possible.
Perhaps I have been spoilt by the Rust ecosystem, but I like my tools telling me right away what they can and cannot do!
The most apparent way to address both is to
(1) rewrite runLinter as a proper CLI app (instead of the ad hoc command line argument parsing it's doing today)
(2) add flags such as
--print-linters
: print the list of all linters it discovered and exit-
--add-linters
: also run the following linters, even if they were disabled before
(my use case: run a linter which is@[env_linter disabled]
, when I cannot or do not want to edit the project defining the linter) -
--exclude-linters X Y
: do not run linters X or Y (say, for performance reasons or because I'm not interested in their output right now) --only-linters Z
: only run linter Z (say, if I added this anew)
Is there any reasons to not do this? Are the longer-term plans in this area I should be aware of?
I have a prototype for this in a mathlib branch; if this is deemed useful, I'm happy to make a PR to batteries to improve runLinter
there.)
[1] I can do so in individual files using the #lint docBlameThm command. I would like to run it on the whole project, however.
Michael Rothgang (Jul 11 2024 at 17:49):
To un-#xy: my original motivation was regenerating mathlib's nolints.json
file locally. I know how to do this, but running all the simp linters takes a while. I can have my computer start this, cook dinner and have the results afterwards, but there ought to be a better way.
Another motivation was re-discovering the docBlameThm
linter, which is disabled by default: I currently cannot run it on mathlib without editing core or batteries; this should not be necessary.
Michael Rothgang (Jul 12 2024 at 09:38):
Mathlib PR #14654 is a proof of concept PR for the UX I can imagine. Comments very welcome.
Michael Rothgang (Jul 12 2024 at 09:50):
batteries#881 makes first baby steps in this direction, by fixing the getChecks
function
Michael Rothgang (Jul 19 2024 at 07:03):
Thanks for the comments and merging the batteries PR!
Michael Rothgang (Jul 19 2024 at 07:03):
In light of the discussion about the naming convention, I would like to rename runLinter
(to be in kebab-case, for example).
At the same time, runLinter
is slightly ambiguous, now that syntax linters exist and at least mathlib is gaining quite a few of them. Since runLinter
runs all linters tagged with env_lint
, how about renaming to env-lint
? (I would perform this rename along with adding a warning to the old script, pointing out the rename. After perhaps a month or two, that warning can be removed.)
CC @Kim Morrison
Kim Morrison (Jul 20 2024 at 22:02):
I don't think env needs to be in the executable name. I think the plan is that we are going to transition to using lake lint
(in fact, if I understand right we can already do this, but I'm on mobile and can't verify). It is meant to work just like @[test_driver] does for lake test
.
Kim Morrison (Jul 20 2024 at 22:03):
The distinction between syntax and environment linters should be prominent in the documentation for both, but people who are just trying to use them don't need to know immediately.
Kim Morrison (Jul 20 2024 at 22:04):
That said, I guess it's no harm to rename the executable as you suggest, and then immediately hide it behind lake lint
.
Michael Rothgang (Jul 20 2024 at 22:09):
Kim Morrison said:
That said, I guess it's no harm to rename the executable as you suggest, and then immediately hide it behind
lake lint
.
That would be my preferred solution also!
Bryan Gin-ge Chen (Sep 22 2024 at 04:11):
Sorry for bumping this old thread with something only tangentially related to the conversation.
Looking at the diff of our most recent mathlib4 automatic update nolints PR, it looks like lake exe runLinter --update
writes a nolints.json file without a final newline. It'd be nice to fix that since anyone editing the file manually will most likely add a final newline character so this will just lead to diff noise. (This is of course hardly a huge deal, but I figured I'd post here while it was on my mind.)
Maybe if @Michael Rothgang 's runLinter rewrite is still forthcoming, this can be worked in somehow?
Damiano Testa (Sep 22 2024 at 20:08):
Bryan, does #17038 look like it might solve the issue? Sorry, I do not have time to test it now.
Bryan Gin-ge Chen (Sep 22 2024 at 20:23):
Hi Damiano, this is my first time looking at the lean code in that file, but isn't that PR touching code (in Mathlib/Tactic/Linter/TextBased.lean) which writes changes to the .lean file being linted and not the code where the nolints.json
file containing exceptions is updated?
I could be wrong but I think the nolints.json file is generated with a missing final newline in scripts/runLinter.lean in batteries.
Damiano Testa (Sep 22 2024 at 20:52):
You're probably right. Then I think that the missing line break is here:
I remember fixing a similar issue with shake a while back.
Damiano Testa (Sep 22 2024 at 20:53):
I think that the JSON pretty
-fier does not add a final line break to the file.
Damiano Testa (Sep 22 2024 at 20:54):
I've already switched off the computer for the night, though. If you want to add a .push '\n'
yourself, feel free to do so! Otherwise, I'll do it tomorrow.
Damiano Testa (Sep 22 2024 at 20:56):
This is the analogous line in shake:
https://github.com/leanprover-community/mathlib4/blob/master/Shake%2FMain.lean#L538
Damiano Testa (Sep 23 2024 at 07:15):
I tested this locally and it seems to work as intended.
I am having some difficulty testing it in CI, though.
Michael Rothgang (Sep 23 2024 at 07:50):
That PR looks good to me - you got to it before I saw this thread in full :-)
Bryan Gin-ge Chen (Sep 29 2024 at 21:06):
It looks like the update nolints job is now saving a file ending in a newline: https://github.com/leanprover-community/mathlib4/pull/17245/files
Thanks Damiano! (I've closed #17038 for now.)
Last updated: May 02 2025 at 03:31 UTC