Skip to content

Conversation

@thorimur
Copy link
Collaborator

@thorimur thorimur commented Nov 19, 2025

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

This linter found 1 violation in Mathlib, which was fixed in #31822.


Open in Gitpod

@github-actions github-actions bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@thorimur thorimur force-pushed the privateModule-linter branch from ad9fc26 to b0e8728 Compare November 19, 2025 19:14
@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@github-actions
Copy link

github-actions bot commented Nov 19, 2025

PR summary 6ff93aa9da

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Tactic.Linter.PrivateModule (new file) 2

Declarations diff

+ bar
+ foo
+ privateModule

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@thorimur thorimur added the WIP Work in progress label Nov 19, 2025
@thorimur thorimur marked this pull request as ready for review November 19, 2025 19:15
@adomani
Copy link
Collaborator

adomani commented Nov 19, 2025

By the way, another standard request would be to add a test of this linter! 😄

@thorimur
Copy link
Collaborator Author

thorimur commented Nov 19, 2025

By the way, another standard request would be to add a test of this linter! 😄

I would love to do this, but the module system is not enabled in MathlibTest, so I can't activate the linter (hence the TODO)! 😅 (I had to test locally in a file in regular Mathlib.)

I'm experimenting with turning on the module system in MathlibTest in #31823, so if that's easy (🤞, not sure if it has been attempted yet, though), maybe let's merge that first and write some tests!

mathlib-bors bot pushed a commit that referenced this pull request Nov 19, 2025
…etion.RingHom (#31822)

This was missed in #31149. Found by the linter in #31820.
/-- 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium-term, we would like to add this to Mathlib.Init, right? Then this linter should be disabled by default, enabled in the lakefile, and this register_option should be public...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. I'll do the latter three things here, right? I could also add it to Mathlib.Init here if you think so, or we can battle-test it first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the latter three can be done here - adding to Mathlib.Init can also happen once this linter is tested properly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#31823 builds just fine, so I've made this a dependent PR and added a couple of basic tests. :) Should I go ahead and add it to Mathlib.Init, or should we see if we see any edge cases first?

Copy link
Collaborator Author

@thorimur thorimur Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0729c34 adds the linter to Mathlib.Init, but I can cherry pick this to another branch if I've misunderstood. :)

@grunweg grunweg added the t-linter Linter label Nov 19, 2025
@adomani
Copy link
Collaborator

adomani commented Nov 19, 2025

By the way, another standard request would be to add a test of this linter! 😄

I would love to do this, but the module system is not enabled in MathlibTest, so I can't activate the linter (hence the TODO)! 😅 (I had to test locally in a file in regular Mathlib.)

🤦 Sorry for not realising that there was a TODO about this in the PR already!

JovanGerb and others added 7 commits November 19, 2025 16:49
…-community#31608)

This PR fixes `isUserFriendly`, in `unfold?`, for two reasons:
- We should only worry about bad constants in the expression if they appear in the visible part of the expression. They should be allowed in e.g. instance implicit arguments.
- We don't want to get raw projections, because these are generally not what we want to work with.
…nprover-community#31814)

The workflow is being skipped on PR edits at the moment and being triggered on edits to the title by bors. This PR fixes both of those issues and some others found during testing.
@thorimur thorimur force-pushed the privateModule-linter branch from 5072232 to 7b70c89 Compare November 19, 2025 21:49
@thorimur
Copy link
Collaborator Author

By the way, another standard request would be to add a test of this linter! 😄

I would love to do this, but the module system is not enabled in MathlibTest, so I can't activate the linter (hence the TODO)! 😅 (I had to test locally in a file in regular Mathlib.)

🤦 Sorry for not realising that there was a TODO about this in the PR already!

Haha, no problem—better to err on the side of tests than otherwise, after all! 😁

@github-actions github-actions bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
Copy link
Collaborator

@grunweg grunweg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The tests look good to me (I haven't looked at the linter's implementation so far).

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Nov 19, 2025
@mathlib4-dependent-issues-bot
Copy link
Collaborator

This PR/issue depends on:

@thorimur thorimur removed the WIP Work in progress label Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants