Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
517890a
feat: `privateModule` linter
thorimur Nov 19, 2025
7128f36
chore: update Mathlib.Tactic.Linter
thorimur Nov 19, 2025
c5f8ac9
chore: mk_all
thorimur Nov 19, 2025
b0e8728
chore: copyright header
thorimur Nov 19, 2025
d94be07
poke CI
thorimur Nov 19, 2025
0cd9a0e
fix(unfold?): improved implementation of `isUserFriendly` (#31608)
JovanGerb Nov 19, 2025
0dbb887
chore: add `@[expose] public section`
thorimur Nov 19, 2025
3d56a33
chore: namespacing, default value := false
thorimur Nov 19, 2025
c255969
ci(check_pr_titles.yaml): fix conditional, skip bors title edits (#31…
bryangingechen Nov 19, 2025
ec88da6
choe: turn on module system in MathlibTest
thorimur Nov 19, 2025
8505c37
chore: make public
thorimur Nov 19, 2025
7b70c89
test
thorimur Nov 19, 2025
850c006
chore: clarify which module
thorimur Nov 19, 2025
c45365a
chore: remove TODO, implementation notes
thorimur Nov 19, 2025
c4b77b5
chore: set option to `true` in tests
thorimur Nov 19, 2025
ad9b101
chore: update lakefile with option set to `true`
thorimur Nov 19, 2025
4350b17
chore: update test
thorimur Nov 19, 2025
552f00e
Merge branch 'master' into privateModule-linter
thorimur Nov 19, 2025
bcdc50b
Merge branch 'master' into privateModule-linter
thorimur Nov 19, 2025
4cf4989
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur Nov 19, 2025
abb973e
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur Nov 19, 2025
4fe8b1c
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur Nov 19, 2025
95fc31a
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur Nov 19, 2025
bbb3a59
chore: extra newline
thorimur Nov 19, 2025
0729c34
chore: add to Mathlib.Init
thorimur Nov 19, 2025
73368c4
chore: comment
thorimur Nov 19, 2025
fe59839
chore: remove double negation for readability, add comments
thorimur Nov 19, 2025
c3e7848
chore: activate the linter via `mathlibStandardSet` in test
thorimur Nov 19, 2025
7cc7c11
chore: update test
thorimur Nov 20, 2025
594a334
feat: use `env.constants.map₂`
thorimur Nov 20, 2025
ca0e0a5
chore: remove unnecessary `import all`
thorimur Nov 20, 2025
18e7d3d
docs: `privateModule`
thorimur Nov 20, 2025
895863e
chore: indentation
thorimur Nov 20, 2025
7b473e2
chore: update message
thorimur Nov 20, 2025
efd6576
docs: update docs
thorimur Nov 20, 2025
7939536
Merge branch 'master' into privateModule-linter
thorimur Nov 21, 2025
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 @@ -6436,6 +6436,7 @@ public import Mathlib.Tactic.Linter.MinImports
public import Mathlib.Tactic.Linter.Multigoal
public import Mathlib.Tactic.Linter.OldObtain
public import Mathlib.Tactic.Linter.PPRoundtrip
public import Mathlib.Tactic.Linter.PrivateModule
public import Mathlib.Tactic.Linter.Style
public import Mathlib.Tactic.Linter.TextBased
public import Mathlib.Tactic.Linter.UnusedTactic
Expand Down
1 change: 1 addition & 0 deletions Mathlib/Tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public import Mathlib.Tactic.Linter.MinImports
public import Mathlib.Tactic.Linter.Multigoal
public import Mathlib.Tactic.Linter.OldObtain
public import Mathlib.Tactic.Linter.PPRoundtrip
public import Mathlib.Tactic.Linter.PrivateModule
public import Mathlib.Tactic.Linter.Style
public import Mathlib.Tactic.Linter.TextBased
public import Mathlib.Tactic.Linter.UnusedTactic
Expand Down
1 change: 1 addition & 0 deletions Mathlib/Tactic/Linter.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public meta import Mathlib.Tactic.Linter.DeprecatedModule
public meta import Mathlib.Tactic.Linter.HaveLetLinter
public meta import Mathlib.Tactic.Linter.MinImports
public meta import Mathlib.Tactic.Linter.PPRoundtrip
public meta import Mathlib.Tactic.Linter.PrivateModule
public meta import Mathlib.Tactic.Linter.UpstreamableDecl
52 changes: 52 additions & 0 deletions Mathlib/Tactic/Linter/PrivateModule.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/-
Copyright (c) 2025 Thomas R. Murrills. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas R. Murrills
-/
module

public import Mathlib.Init
public import Lean.Environment
import all Lean.Environment

/-!
# Private module linter

This linter lints against nonempty modules that have only private declarations, and suggests adding
`@[expose] public section` to the top.
-/

-- TODO: `module` is not enabled in MathlibTest yet, so tests should be written for this once it is.

meta section

open Lean Elab Command Linter

/-- The `privateModule` linter lints against nonempty modules that have only private declarations,
and suggests adding `@[expose] public section` to the top. -/
register_option linter.privateModule : Bool := {
defValue := true
descr := "Enable the `privateModule` linter, which lints against nonempty modules that have only \
private declarations."
}

def privateModule : Linter where
run stx := do
if stx.isOfKind ``Parser.Command.eoi then
unless getLinterValue linter.privateModule (← getLinterOptions) do
return
if (← getEnv).header.isModule then
-- Wait for everything (necessary?)
let _ := (← getEnv).checked.get
-- TODO: why doesn't this work?
-- if (← getEnv).asyncConstsMap.public.size = 0 then
-- if (← getEnv).asyncConstsMap.private.size ≠ 0 then
unless (← getEnv).asyncConstsMap.public.revList.any
(!(`_private).isPrefixOf ·.constInfo.name) do
if (← getEnv).asyncConstsMap.private.size ≠ 0 then
let topOfFileRef := Syntax.atom (.synthetic ⟨0⟩ ⟨0⟩) ""
logLint linter.privateModule topOfFileRef
"Module only contains private declarations.\n\n\
Consider adding `@[expose] public section` at the beginning of the module."

initialize addLinter privateModule
Loading