Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generic linter, absorbing cdot linter and attribute [instance] in linter #12143

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b9ee1c4
feat: a `cdot` linter
adomani Apr 15, 2024
8a0cbd3
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani Apr 15, 2024
62c4ec1
shake
adomani Apr 16, 2024
0f37862
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani Apr 16, 2024
5a756e1
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani May 10, 2024
041b63e
chore: two cdots to cdots
adomani May 10, 2024
c93d535
Merge branch 'adomani/to_cdots' into adomani/generic_cdot_linter
adomani May 10, 2024
d616a4a
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani May 13, 2024
c549476
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani May 20, 2024
b6c2665
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani May 25, 2024
db96839
move to Tactic/Linter, merge attribute instance in
adomani May 25, 2024
3c6c075
more docs
adomani May 25, 2024
6d05339
rename to GenericSyntaxLinter
adomani May 25, 2024
ee4f74e
Add test file
adomani May 25, 2024
27a0327
remove .lean
adomani May 25, 2024
374d63a
lint
adomani May 25, 2024
4364442
mathlib's noshake
adomani May 25, 2024
23a0b93
Merge remote-tracking branch 'origin/master' into adomani/generic_cdo…
adomani May 26, 2024
ece0acd
Merge branch 'master' into adomani/generic_cdot_linter
adomani May 26, 2024
adbf4c3
Merge branch 'master' into adomani/generic_cdot_linter
grunweg Jul 22, 2024
bb39434
Fix three stray cdots.
grunweg Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,7 @@ import Mathlib.Tactic.ByContra
import Mathlib.Tactic.CC.Addition
import Mathlib.Tactic.CC.Datatypes
import Mathlib.Tactic.CC.Lemmas
import Mathlib.Tactic.CDotLinter
import Mathlib.Tactic.CancelDenoms
import Mathlib.Tactic.CancelDenoms.Core
import Mathlib.Tactic.Cases
Expand Down
1 change: 1 addition & 0 deletions Mathlib/Tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Mathlib.Tactic.ByContra
import Mathlib.Tactic.CC.Addition
import Mathlib.Tactic.CC.Datatypes
import Mathlib.Tactic.CC.Lemmas
import Mathlib.Tactic.CDotLinter
import Mathlib.Tactic.CancelDenoms
import Mathlib.Tactic.CancelDenoms.Core
import Mathlib.Tactic.Cases
Expand Down
1 change: 1 addition & 0 deletions Mathlib/Tactic/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.ExtendDoc
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.TypeStar
import Mathlib.Tactic.CDotLinter

set_option autoImplicit true

Expand Down
73 changes: 73 additions & 0 deletions Mathlib/Tactic/CDotLinter.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Lean.Elab.Command
import Lean.Linter.Util

/-!
# The "generic" linter

The "generic" linter takes as input a function
`unwanted : Syntax → Array Syntax` that returns the syntax nodes of an input syntax that
should be flagged.


TODO:
adomani marked this conversation as resolved.
Show resolved Hide resolved
* Add `blackout? : Syntax → Bool` to prevent further inspection by the linter?
* Add `context? : InfoTree → Bool` for further effects combining `unwanted` and `blackout?` and
possibly doing some further filtering?

See #11890 for an example of how this may be extended.
-/

open Lean Elab

namespace Mathlib.Linter

/-- The "generic" linter emits a warning on "generic" syntax. -/
adomani marked this conversation as resolved.
Show resolved Hide resolved
register_option linter.generic : Bool := {
defValue := true
descr := "enable the generic linter"
}

namespace generic

/-- find `cdot` syntax. -/
adomani marked this conversation as resolved.
Show resolved Hide resolved
partial
def findDot : Syntax → (Array Syntax)
| stx@(.node _ k args) =>
let dargs := (args.map findDot).flatten
if k == ``Lean.Parser.Term.cdot then dargs.push stx else dargs
|_ => default

/-- is the actual symbol `·`? -/
def isCDot? : Syntax → Bool
| .node _ _ #[.atom _ v] => v == "·"
| _ => false

/-- the main unwanted syntax: a `cdot` that is not a `·`. -/
adomani marked this conversation as resolved.
Show resolved Hide resolved
def unwanted.cDot (stx : Syntax) : Array Syntax :=
(findDot stx).filter (!isCDot? ·)

end generic

end Mathlib.Linter

namespace Mathlib.Linter.generic

/-- Gets the value of the `linter.generic` option. -/
def getLinterHash (o : Options) : Bool := Linter.getLinterValue linter.generic o

/-- The main implementation of the terminal refine linter. -/
def terminalRefineLinter (contains? : Syntax → Array Syntax) : Linter where
adomani marked this conversation as resolved.
Show resolved Hide resolved
run := withSetOptionIn fun stx => do
unless getLinterHash (← getOptions) do
return
if (← MonadState.get).messages.hasErrors then
return
let _ ← (contains? stx).mapM fun s =>
Linter.logLint linter.generic s m!"here"

initialize addLinter (terminalRefineLinter unwanted.cDot)
2 changes: 1 addition & 1 deletion scripts/noshake.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
["Mathlib.Tactic.CategoryTheory.MonoidalComp"],
"Mathlib.Tactic.CC.Addition":
["Mathlib.Logic.Basic", "Mathlib.Tactic.CC.Lemmas"],
"Mathlib.Tactic.Basic": ["Batteries"],
"Mathlib.Tactic.Basic": ["Batteries", "Mathlib.Tactic.CDotLinter"],
"Mathlib.Tactic.Attr.Register": ["Lean.Meta.Tactic.Simp.SimpTheorems"],
"Mathlib.Tactic.ArithMult": ["Mathlib.Tactic.ArithMult.Init"],
"Mathlib.RingTheory.PolynomialAlgebra": ["Mathlib.Data.Matrix.DMatrix"],
Expand Down
Loading