-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
dupNamespace
as a syntax linter (#11154)
An implementation of the `dupNamespace` from `Std` as a syntax linter. The linter emits a warning for declarations that have a repeated, consecutive namespace: * `Nat.Nat.foo` triggers the linter; * `Nat.foo.Nat` does *not* trigger the linter. *Note.* This linter will not detect duplication in namespaces of autogenerated declarations (other than the one whose `declId` is present in the source declaration). [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60dupNamespace.60.20linter) The linter found ```lean private theorem Seminorm.Seminorm.isLUB_sSup ... ``` that is skipped by the environment `dupNamespace` linter.
- Loading branch information
Showing
3 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Mathlib.Tactic.Lint | ||
import Mathlib.Tactic.ToAdditive | ||
|
||
set_option linter.dupNamespace true in | ||
/-- warning: | ||
The namespace 'add' is duplicated in the declaration 'add.add' | ||
[linter.dupNamespace] | ||
-/ | ||
#guard_msgs in | ||
def add.add := True | ||
|
||
namespace Foo | ||
set_option linter.dupNamespace true in | ||
/-- warning: | ||
The namespace 'Foo' is duplicated in the declaration 'Foo.Foo.foo' | ||
[linter.dupNamespace] | ||
-/ | ||
#guard_msgs in | ||
def Foo.foo := True | ||
|
||
-- the `dupNamespace` linter does not notice that `to_additive` created `Foo.add.add`. | ||
#guard_msgs in | ||
@[to_additive] theorem add.mul : True := .intro | ||
|
||
-- However, the declaration `Foo.add.add` is present in the environment. | ||
run_cmd Lean.Elab.Command.liftTermElabM do | ||
let decl := (← Lean.getEnv).find? ``Foo.add.add | ||
guard decl.isSome | ||
|
||
namespace Nat | ||
/-- | ||
warning: | ||
The namespace 'Nat' is duplicated in the declaration 'Foo.Nat.Nat.Nats' [linter.dupNamespace] | ||
-/ | ||
#guard_msgs in | ||
alias Nat.Nats := Nat | ||
|
||
end Nat | ||
end Foo | ||
|
||
namespace add | ||
/-- | ||
warning: The namespace 'add' is duplicated in the declaration 'add.add' [linter.dupNamespace] | ||
-/ | ||
#guard_msgs in | ||
export Nat (add) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters