-
Notifications
You must be signed in to change notification settings - Fork 908
[Merged by Bors] - feat: privateModule linter
#31820
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
Closed
thorimur
wants to merge
36
commits into
leanprover-community:master
from
thorimur:privateModule-linter
Closed
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
517890a
feat: `privateModule` linter
thorimur 7128f36
chore: update Mathlib.Tactic.Linter
thorimur c5f8ac9
chore: mk_all
thorimur b0e8728
chore: copyright header
thorimur d94be07
poke CI
thorimur 0cd9a0e
fix(unfold?): improved implementation of `isUserFriendly` (#31608)
JovanGerb 0dbb887
chore: add `@[expose] public section`
thorimur 3d56a33
chore: namespacing, default value := false
thorimur c255969
ci(check_pr_titles.yaml): fix conditional, skip bors title edits (#31…
bryangingechen ec88da6
choe: turn on module system in MathlibTest
thorimur 8505c37
chore: make public
thorimur 7b70c89
test
thorimur 850c006
chore: clarify which module
thorimur c45365a
chore: remove TODO, implementation notes
thorimur c4b77b5
chore: set option to `true` in tests
thorimur ad9b101
chore: update lakefile with option set to `true`
thorimur 4350b17
chore: update test
thorimur 552f00e
Merge branch 'master' into privateModule-linter
thorimur bcdc50b
Merge branch 'master' into privateModule-linter
thorimur 4cf4989
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur abb973e
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur 4fe8b1c
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur 95fc31a
Update Mathlib/Tactic/Linter/PrivateModule.lean
thorimur bbb3a59
chore: extra newline
thorimur 0729c34
chore: add to Mathlib.Init
thorimur 73368c4
chore: comment
thorimur fe59839
chore: remove double negation for readability, add comments
thorimur c3e7848
chore: activate the linter via `mathlibStandardSet` in test
thorimur 7cc7c11
chore: update test
thorimur 594a334
feat: use `env.constants.map₂`
thorimur ca0e0a5
chore: remove unnecessary `import all`
thorimur 18e7d3d
docs: `privateModule`
thorimur 895863e
chore: indentation
thorimur 7b473e2
chore: update message
thorimur efd6576
docs: update docs
thorimur 7939536
Merge branch 'master' into privateModule-linter
thorimur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,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 := { | ||
thorimur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| defValue := true | ||
thorimur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| descr := "Enable the `privateModule` linter, which lints against nonempty modules that have only \ | ||
| private declarations." | ||
| } | ||
|
|
||
| def privateModule : Linter where | ||
thorimur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| run stx := do | ||
thorimur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if stx.isOfKind ``Parser.Command.eoi then | ||
adomani marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.