[Merged by Bors] - feat: syntax linter for #-commands#11019
[Merged by Bors] - feat: syntax linter for #-commands#11019
#-commands#11019Conversation
| For example, `#eval, #guard, #guard_msgs` all trigger a message. | ||
| -/ | ||
| register_option linter.hashCommand : Bool := { | ||
| defValue := true |
There was a problem hiding this comment.
I don't think this should be enabled by default, but it should be enabled in CI (can do so in this PR). What do you think?
There was a problem hiding this comment.
I actually think that I prefer it to be disabled by default outside of CI: if I am using #eval in a file, I expect to want to see the output and not be bugged by the linter! I'll look up how to make sure that CI uses a different default.
There was a problem hiding this comment.
Yeah I agree exactly, I think its enoguh to call lean in CI with -Dlinter.hashCommand=true
There was a problem hiding this comment.
I am failing to make this work locally:
$ lake build Mathlib.mwe
[303/304] Building Mathlib.mwe
error: > LEAN_PATH=./.lake/packages/std/.lake/build/lib:./.lake/packages/Qq/.lake/build/lib:./.lake/packages/aesop/.lake/build/lib:./.lake/packages/proofwidgets/.lake/build/lib:./.lake/packages/Cli/.lake/build/lib:./.lake/packages/importGraph/.lake/build/lib:./.lake/build/lib LD_LIBRARY_PATH=./.lake/build/lib /home/damiano/.elan/toolchains/leanprover--lean4---v4.6.0-rc1/bin/lean -Dlinter.hashCommand=true -Dpp.unicode.fun=true -Dpp.proofs.withType=false -DautoImplicit=false -DrelaxedAutoImplicit=false ./././Mathlib/mwe.lean -R ././. -o ./.lake/build/lib/Mathlib/mwe.olean -i ./.lake/build/lib/Mathlib/mwe.ilean -c ./.lake/build/ir/Mathlib/mwe.c
error: stderr:
invalid -D parameter, unknown configuration option 'linter.hashCommand'
error: external command `/home/damiano/.elan/toolchains/leanprover--lean4---v4.6.0-rc1/bin/lean` exited with code 1
There was a problem hiding this comment.
I modified this
weakLeanArgs :=
if get_config? CI |>.isSome then
#["-DwarningAsError=true", "-Dlinter.hashCommand=true"]
else
#["-Dlinter.hashCommand=true"]There was a problem hiding this comment.
Alex, it seems that it is not an option to make this linter quiet locally, but chatty on CI. I propose to make the linter available with quiet default: hopefully in the future it will be possible to set different defaults globally and then the linter would reach its full potential!
There was a problem hiding this comment.
Hmm, it's a hack to work around it now, but: what if we made the defValue := true, yet also checked warningAsError in the linter (and left a very visible note, and even made the description "enables the `#`-command linter as long as `warningAsError` is `true`")? I.e.
def getLinterHash (o : Options) : Bool :=
Linter.getLinterValue linter.hashCommand o && warningAsError.get oThen it would run in CI (since that uses warningAsError := true) but not locally under normal circumstances.
I guess the question is: in practice, would someone want to turn on this linter locally? Or is it ok if it's only ever run in CI?
(Another option is to keep defValue := false but turn it on whenever warningAsError := true, i.e. using || instead of && above.)
There was a problem hiding this comment.
For me, the main use of this linter while working on a PR, would be when a #-command is silent. If I am using a "noisy" #-command, I am probably curious about its output and adding the linter warning would be annoying.
If there were a way of making the linter noisy exactly when the #-command is not, then I would like it always on, I think.
There was a problem hiding this comment.
Having it on while editing when there are no messages is a good idea! I do wonder whether it should also be on everywhere during CI for good error messages (as mentioned elsewhere). I guess the logic would be getLinterHash (<- getOptions) && ((<- get).messages.msgs.size == 0 || warningAsError.get (<- getOptions)) in that case. I won't insist on this, though! :)
|
I like this much more than the sed version! |
thorimur
left a comment
There was a problem hiding this comment.
This review seems bigger than it is. It's basically:
- style/documentation
- code tweaking/taking care of edge cases
- questions about a couple of details
This PR looks very nice! :)
…ommunity/mathlib4 into adomani/hash_command_linter
ac6194d to
9d9f40d
Compare
There was a problem hiding this comment.
Apologies for the delay—very close to looking good to me! :) (Also see comment about withSetOptionIn' which is not organized as part of this review.)
I would like to see if we can run this during CI if possible by hijacking the warningAsError option (only until the underlying issue is fixed, of course)—see comment.
| For example, `#eval, #guard, #guard_msgs` all trigger a message. | ||
| -/ | ||
| register_option linter.hashCommand : Bool := { | ||
| defValue := true |
There was a problem hiding this comment.
Hmm, it's a hack to work around it now, but: what if we made the defValue := true, yet also checked warningAsError in the linter (and left a very visible note, and even made the description "enables the `#`-command linter as long as `warningAsError` is `true`")? I.e.
def getLinterHash (o : Options) : Bool :=
Linter.getLinterValue linter.hashCommand o && warningAsError.get oThen it would run in CI (since that uses warningAsError := true) but not locally under normal circumstances.
I guess the question is: in practice, would someone want to turn on this linter locally? Or is it ok if it's only ever run in CI?
(Another option is to keep defValue := false but turn it on whenever warningAsError := true, i.e. using || instead of && above.)
|
Thomas, thank you very much for your comments! The new |
adomani
left a comment
There was a problem hiding this comment.
Oh, I thought that I had replied to those previous messages, but they got lost in review!
Anyway, I ended up allowing more #guards!
|
Ok, after yet another failed test, I decided to make the |
|
Tests pass; I took one last look and pushed a few tiny tweaks. (@adomani Feel free to revert those if you prefer!) (A follow-up PR could remove the sed-based linter this replaces. Imho, this doesn't have to happen in this PR.) |
|
🚀 Pull request has been placed on the maintainer queue by grunweg. |
The linter was rewritten in Lean in #11019.
|
Filed #13142 for the follow-up. |
|
Thanks 🎉 bors merge |
A Lean-linter implementation of the `#`-command linter introduced in #10809. This linter produces a warning whenever a non-allowed `#`-command is used. The allowed commands are ```lean #align #align_import #noalign #adaptation_note ``` [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2311019.3A.20a.20syntax.20linter.20for.20.23-commands) Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
|
Pull request successfully merged into master. Build succeeded: |
#-commands#-commands
The linter was rewritten in Lean in #11019.
A Lean-linter implementation of the `#`-command linter introduced in #10809. This linter produces a warning whenever a non-allowed `#`-command is used. The allowed commands are ```lean #align #align_import #noalign #adaptation_note ``` [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2311019.3A.20a.20syntax.20linter.20for.20.23-commands) Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
The linter was rewritten in Lean in #11019. This removes one separate workflow step.
A Lean-linter implementation of the `#`-command linter introduced in #10809. This linter produces a warning whenever a non-allowed `#`-command is used. The allowed commands are ```lean #align #align_import #noalign #adaptation_note ``` [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2311019.3A.20a.20syntax.20linter.20for.20.23-commands) Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
The linter was rewritten in Lean in #11019. This removes one separate workflow step.
A Lean-linter implementation of the `#`-command linter introduced in #10809. This linter produces a warning whenever a non-allowed `#`-command is used. The allowed commands are ```lean #align #align_import #noalign #adaptation_note ``` [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2311019.3A.20a.20syntax.20linter.20for.20.23-commands) Co-authored-by: Michael Rothgang <rothgami@math.hu-berlin.de>
The linter was rewritten in Lean in #11019. This removes one separate workflow step.
A Lean-linter implementation of the
#-command linter introduced in #10809.This linter produces a warning whenever a non-allowed
#-command is used. The allowed commands areZulip discussion
This PR is accompanied by #11028, which places the linter in.Tactic.Basic, to make sure that (most of)Mathlibpasses the#-command linter