Zulip Chat Archive
Stream: mathlib4
Topic: Improper firing of linter.hashcommand
Asei Inoue (Aug 06 2024 at 16:16):
import Mathlib.Data.Real.Sqrt
/-
`#`-commands, such as '#guard', are not allowed in 'Mathlib'
note: this linter can be disabled with `set_option linter.hashCommand false`
-/
#guard "hello, " ++ "world" = "hello, world"
Damiano Testa (Aug 06 2024 at 16:17):
This seems all correct: what is the issue?
Asei Inoue (Aug 06 2024 at 16:18):
The linter.hashcommand may be necessary for Mathlib development, but it is unlikely to be needed for all files importing Mathlib.
Asei Inoue (Aug 06 2024 at 16:19):
I found it annoying that this linter fired when just importing Mathlib.
Asei Inoue (Aug 06 2024 at 16:22):
Can't we separate the 'developer's linter for a specific library' from the 'linter for users'?
Asei Inoue (Aug 06 2024 at 16:23):
I know that it is possible to disable this linter in the options settings. That is not the question I want to ask.
Damiano Testa (Aug 06 2024 at 16:23):
You should import mathlib and be in a file whose path starts with Mathlib
.
Damiano Testa (Aug 06 2024 at 16:23):
Otherwise the linter should be quiet.
Asei Inoue (Aug 06 2024 at 16:24):
You should import mathlib and be in a file whose path starts with
Mathlib
.
Otherwise the linter should be quiet.
Is it not possible to read the lakefile configuration and branch by the name of the package?
Damiano Testa (Aug 06 2024 at 16:24):
Ah, no, this one may only be quiet in tests.
Eric Wieser (Aug 06 2024 at 16:27):
@Damiano Testa, is it expected that this fires in the web editor?
Damiano Testa (Aug 06 2024 at 16:38):
It is designed to be active on any file whose path does not start with test
, except for the test file of the linter itself.
Damiano Testa (Aug 06 2024 at 16:39):
I thought that it had been silenced on files that were not in mathlib, but I must be confusing it with some of the other linters.
Damiano Testa (Aug 06 2024 at 16:42):
In any case, I think that there are always competing desires: projects downstream of mathlib may want to pick and choose which linters they want active and different projects will have different choices. So, neither making the linters always active not always inactive is a good decision.
Damiano Testa (Aug 06 2024 at 16:42):
The new option-setting is just for the command-line lake build
, right?
Damiano Testa (Aug 06 2024 at 16:43):
So, that is also not really going to solve this issue, I think.
Damiano Testa (Aug 06 2024 at 16:44):
Maybe there should be a "linter options" file that contains the default value of each linter and each linter reads off from there its default setting.
Damiano Testa (Aug 06 2024 at 16:45):
So, rather than embedding the defValue
of each linter in the option for the linter, that is something that can be configured independently.
Asei Inoue (Aug 06 2024 at 16:46):
Why not leave it disabled by default and enable it in the Mathlib lakefile?
Damiano Testa (Aug 06 2024 at 16:47):
I do not think that you can enable or disable linters from the lakefile.
Damiano Testa (Aug 06 2024 at 16:47):
Otherwise, this would have been the case for all linters, I think.
Eric Wieser (Aug 06 2024 at 16:51):
Damiano Testa said:
I do not think that you can enable or disable linters from the lakefile.
I think this is new in 4.11?
Damiano Testa (Aug 06 2024 at 16:52):
It could be: I never used it yet, but it was not clear to me that this was not something that could only be set as an option to lake build
.
Asei Inoue (Aug 06 2024 at 16:52):
Add linter.missingDocs
to here works for me....
package «package name» where
leanOptions := #[
⟨`autoImplicit, false⟩,
⟨`relaxedAutoImplicit, false⟩,
⟨`linter.missingDocs, true⟩
]
Damiano Testa (Aug 06 2024 at 16:53):
Ah, but those are the "built-in" linters. Those you can always set in the lakefile.
Damiano Testa (Aug 06 2024 at 16:53):
Ok, if it works, then this solves all problems!
Eric Wieser (Aug 06 2024 at 16:54):
lean4#3403 was the tracking issue for this not working until very recently
Asei Inoue (Aug 06 2024 at 16:54):
It would be a solution if any linter could be configured in the lakefile as well as the built-in linter.
Asei Inoue (Aug 06 2024 at 16:55):
so now this issue can be solved?
Damiano Testa (Aug 06 2024 at 16:55):
Ok, so now everyone is free to set their linter options in the lakefile?
Damiano Testa (Aug 06 2024 at 16:55):
Time to clean up all the "look for the path and cripple the linter"!
Asei Inoue (Aug 06 2024 at 16:58):
So nice! :smiley: :tada: This new feature is awesome...! It is a time to a little celebrate dance ₍₍ (ง ˘ω˘ )ว ⁾⁾
Damiano Testa (Aug 06 2024 at 17:00):
It might even be a policy that every linter's default is false
and each project is expected to opt in in the lakefile.
Asei Inoue (Aug 06 2024 at 17:01):
Some linters would like it to be enabled by default. ex: unusedVariable
Eric Wieser (Aug 06 2024 at 17:01):
The danger with using the new weak
arguments if that if you typo a linter name then it doesn't run at all
Eric Wieser (Aug 06 2024 at 17:01):
(or more realistically, if mathlib decides to rename the linter)
Damiano Testa (Aug 06 2024 at 17:01):
Maybe a deprecation system could be enforced
Asei Inoue (Aug 06 2024 at 17:04):
A possible solution is to specify the location where the linter is defined in lakefile
and to make an error if the file is reached but there is no linter...
Michael Rothgang (Aug 06 2024 at 20:52):
Damiano Testa said:
Time to clean up all the "look for the path and cripple the linter"!
Feel free to push #15521 to completion :-)
Sebastian Ullrich (Aug 06 2024 at 20:54):
Eric Wieser said:
(or more realistically, if mathlib decides to rename the linter)
You phrased that like it could be an issue for downstream users but why would they need weak
in that case? If they want to use a linter, shouldn't they make sure to import it everywhere in their project?
Michael Rothgang (Aug 06 2024 at 20:55):
To clarify: in mathlib, you would need to put weak.linter.longLine
. Projects downstream of it can/should be able to simply use linter.longLine
.
Sebastian Ullrich (Aug 06 2024 at 20:55):
(future improvements that could allow linters to be used without being imported notwithstanding)
Eric Wieser (Aug 07 2024 at 08:52):
Ah, I think I misunderstood how name resolution worked for options, indeed if this only affects mathlib itself then there is much less to worry about
Mario Carneiro (Aug 08 2024 at 07:13):
Damiano Testa said:
It might even be a policy that every linter's default is
false
and each project is expected to opt in in the lakefile.
No, I think it is usually pretty clear when a linter should be default on or default on only in mathlib. Linters which are useful generally and try to improve code quality should be enabled by default, and linters which try to maintain mathlib quality standards or enforce "house rules" of mathlib should be disabled by default and enabled in the mathlib lakefile.
Here's my triage of which is which:
Global:
globalAttributeIn
haveLetLinter
dupNamespace
unusedTacticLinter
Mathlib local:
hashCommandLinter
missingEndLinter
cdotLinter
longLineLinter
oldObtainLinter
(unless this is supposed to be a deprecation warning?)refineLinter
(although maybe it can be made global if we getrefine?
)setOptionLinter
Damiano Testa (Aug 08 2024 at 07:49):
Ok, sounds great!
Ruben Van de Velde (Aug 08 2024 at 08:54):
Yeah, I think old obtain should warn on dependencies so we can remove it
Damiano Testa (Aug 08 2024 at 13:05):
Last updated: May 02 2025 at 03:31 UTC