Skip to content

feat: add linter.redundantVisibility for redundant private/public modifiers - #13132

Merged
Kha merged 11 commits into
leanprover:masterfrom
Kha:push-yxkwqnuupklk
Apr 13, 2026
Merged

Kha merged 11 commits into
leanprover:masterfrom
Kha:push-yxkwqnuupklk

Conversation

@Kha

@Kha Kha commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

This PR adds a linter.redundantVisibility option (default true) that warns
when a visibility modifier has no effect because it matches the default for the
current context:

  • private outside a public section in a module file, where declarations
    are already module-scoped by default
  • public in a non-module file or inside a public section, where
    declarations are already public by default

The check is integrated directly into elabModifiers so it covers all
declaration types uniformly.

…ection`

This PR adds a `linter.privateInPrivate` option (default `true`) that warns when
`private` is used outside a `public section` in a `module` file, since declarations
are already module-scoped by default and `private` has no additional effect.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Mar 26, 2026
@leanprover-bot

leanprover-bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-24 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-03-26 11:10:10)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase d53b46a0f3a7d0822550f4179ca3dab446a3c448 --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-10 17:41:49)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-04-11 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-04-13 09:10:02)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 26, 2026
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Mar 26, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 26, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Mar 26, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Mar 26, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • 💥 Mathlib branch lean-pr-testing-13132 build failed against this PR. (2026-03-26 12:01:58) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase d53b46a0f3a7d0822550f4179ca3dab446a3c448 --onto e0a29f43d2e4685febd0ed6bcfad511f7a235b6f. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-10 17:41:47)

…`, warn on redundant `public` too

This PR renames the linter option and extends it to also warn when `public` is
used in a context where declarations are already public by default (non-`module`
files or inside `public section`).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Kha Kha changed the title feat: warn on redundant private in module files outside public section feat: add linter.redundantVisibility for redundant private/public modifiers Mar 26, 2026
… modifiers

This PR skips the redundant visibility check when the visibility keyword
lacks original source info, which indicates it was generated by a macro
(e.g. `elab`, `macro_rules`, `syntax`, `notation`).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 26, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 26, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 26, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 26, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@Rob23oba

Copy link
Copy Markdown
Contributor

Hmm elabInitialize does something weird with the visibility (respects the surrounding scope for the declaration being initialized but not for the initializer, where it uses public if you don't specify private explicitly).

@Kha

Kha commented Mar 29, 2026

Copy link
Copy Markdown
Member Author

@Rob23oba Could you file an issue with an example?

@Kha
Kha force-pushed the push-yxkwqnuupklk branch from ebf1020 to ec2ae2a Compare April 10, 2026 13:12
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@Kha
Kha enabled auto-merge April 10, 2026 16:47
@Kha
Kha force-pushed the push-yxkwqnuupklk branch from dcf70dd to 65194b6 Compare April 10, 2026 16:50
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@Kha
Kha added this pull request to the merge queue Apr 13, 2026
Merged via the queue into leanprover:master with commit 2b8c273 Apr 13, 2026
17 checks passed
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Apr 13, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Apr 13, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Apr 13, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@Kha
Kha deleted the push-yxkwqnuupklk branch April 14, 2026 12:55
volodeyka pushed a commit that referenced this pull request Apr 16, 2026
…c` modifiers (#13132)

This PR adds a `linter.redundantVisibility` option (default `true`) that
warns
when a visibility modifier has no effect because it matches the default
for the
current context:

- `private` outside a `public section` in a `module` file, where
declarations
  are already module-scoped by default
- `public` in a non-`module` file or inside a `public section`, where
  declarations are already public by default

The check is integrated directly into `elabModifiers` so it covers all
declaration types uniformly.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
kim-em added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 4, 2026
* Update lean-toolchain for testing leanprover/lean4#13086

* feat: add `Lean.Grind.PowIdentity` instance for finite fields

This provides a `PowIdentity K (Fintype.card K)` instance for any finite
field, based on `FiniteField.pow_card` (Fermat's little theorem). This
allows the `grind` ring solver to reduce high-degree polynomials over
finite fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Update lean-toolchain for testing leanprover/lean4#13132

* Update lean-toolchain for leanprover/lean4#13132

* Update lean-toolchain for leanprover/lean4#13132

* Update lean-toolchain for testing leanprover/lean4#13223

* Update lean-toolchain for testing leanprover/lean4#13229

* chore: indent tactic blocks after `by` and `decreasing_by`

Adapt to leanprover/lean4#13217 which requires indented tactic sequences
after `by` and `decreasing_by`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: indent tactic block in EmptyLine test

Adapt to leanprover/lean4#13217.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: indent expression continuations at column 0

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: indent expression continuations at column 0

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Update lean-toolchain for leanprover/lean4#13229

* Update lean-toolchain for leanprover/lean4#13223

* Update lean-toolchain for leanprover/lean4#13229

* Update lean-toolchain for leanprover/lean4#13229

* Update lean-toolchain for leanprover/lean4#13229

* Update lean-toolchain for leanprover/lean4#13223

* chore: fix linter tests

* lake update

* fix hash command linter

* fix bad merge

* fixes

* fixes

* unpleasant fix.

* touch for CI

* cleanup of adaptation notes

* chore: adaptations for nightly-2026-04-06

* chore: bump to nightly-2026-04-07

* chore: adaptations for nightly-2026-04-07

* chore: bump to nightly-2026-04-08

* Update lean-toolchain for testing leanprover/lean4#13262

* Update lean-toolchain for leanprover/lean4#13262

* universe fixes

* chore: bump to nightly-2026-04-09

* Update lean-toolchain for testing leanprover/lean4#13346

* Update lean-toolchain for leanprover/lean4#13346

* lake update

* fixes

* fix tests

* ci: skip inputRev validation on nightly-testing branch

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* chore: bump to nightly-2026-04-10

* fix

* chore(nolints): add docBlame exceptions for auto-generated `instInhabited.default`

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix(lint-style): filter out duplicate `Init` from `Mathlib.lean` imports

`Lean.parseImports'` now emits `Init` more than once for module-system
files such as `Mathlib.lean`, but `findImportsFromSource` (in importGraph)
only `.erase`s the first occurrence. The remaining `Init` was treated as a
module to lint, producing `uncaught exception: no such file or directory ...
file: Init.lean` and breaking the `lint-style` CI job on `nightly-testing`.

Defensively filter out any remaining `Init` after `findImportsFromSource`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix

* fix plausible

* Update lean-toolchain for leanprover/lean4#13346

* chore: update importGraph, remove duplicate Init workaround

Updates importGraph to pick up leanprover-community/import-graph#115,
which fixes `findImportsFromSource` to filter (not just erase) `Init`.
This removes the need for the defensive `.filter (· != `Init)` we added
to `lint-style.lean`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* chore: bump to nightly-2026-04-11

* silence linter

* broken test: still broken, but doesn't stop the build.

* fix: exempt files registering initializers from the `privateModule` linter

* Revert "silence linter"

This reverts commit 8da25c3.

* chore: remove unused sections in front of lone `declare_aesop_rule_sets`

* chore: restore `initialize` test for `privateModule` linter with correct wording

* chore: restore `privateModule` `initialize` test with linter turned on

* fixes

* fix from nightly-testing

* importGraph has been fixed

* chore: bump to nightly-2026-04-13

* Update lean-toolchain for testing leanprover/lean4#13325

* Update lean-toolchain for leanprover/lean4#13325

* chore: silence simp `varHead` and `varOther` warnings

* chore: silence `varHead` warning

* chore: fix `globalAtrtributeIn` test

* chore: fix `Archive` build

* Update lean-toolchain for leanprover/lean4#13325

* Update lean-toolchain for leanprover/lean4#13325

* fix from nightly-testing

* chore: bump to nightly-2026-04-14

* chore: bump to nightly-2026-04-15

* adapt to lean4#13363: canUnfoldAtMatcher allowlist changes

Adapt proofs to lean4#13363 which replaces the transparency bump from
`.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist
in `canUnfoldAtMatcher`. Class projections that were previously unfolded
automatically in match discriminants now need explicit unfolding.

* fix lint errors from lean4#13363 adaptation

- Add doc string to `WithZero.withZeroSup`
- Add `nolint simpNF` to auto-generated equation lemmas for
  `RegularExpression.matches'` and `RegularExpression.map`
- Add `nolint simpNF` to `orderLHom_leSymb`

* fixes

* fix

* fixes

* chore: bump to nightly-2026-04-16

* fix tests

* fix upstreamed import

* chore: bump to nightly-2026-04-17

* set_option

* Update lean-toolchain for testing leanprover/lean4#13441

* chore: adaptations for leanprover/lean4#13389

* fixes

* fixes

* fixes

* fix Init filter in MinImports

* fix test

* add set_options

* chore: bump to nightly-2026-04-19

* chore: bump to nightly-2026-04-20

* fix bad merge

* fix #guard_msgs output

* chore: bump to nightly-2026-04-22

* chore: bump to nightly-2026-04-23

* cleanup

* revert an unnecessary change

* revert unnecessary changes

* add adaptation notes

* minor fixes, whitespace and PR links

* two improvements

* improvements

* slightly improve the proof in Limits/Shapes/Equalizers.lean

* More

* chore: bump to nightly-2026-04-24

* adapt to lean4#13363: canUnfoldAtMatcher allowlist changes

Adapt proofs to lean4#13363 which replaces the transparency bump from
`.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist
in `canUnfoldAtMatcher`. Class projections like `CategoryStruct.comp`,
`CategoryStruct.id`, `Stream.next?`, `Min.min` etc. are no longer
auto-unfolded in match discriminants and need explicit unfolding in
proofs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: remove unused helper lemmas from Ordinal/Notation adaptation

Remove `zero_zero_eq`, `one_one_eq`, `repr_zero'`, and `ofNat_unfold`
which were added during the lean4#13363 adaptation but are not used in
any proofs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Update lean-toolchain for leanprover/lean4#13363

* adapt Limits/Shapes/ConcreteCategory to lean4#13363

Use `WalkingMulticospan.Hom.id_eq_id` and `Functor.map_id` to reduce
stuck matches on `𝟙` in WalkingMulticospan naturality proofs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Bump batteries

* Update lean-toolchain for leanprover/lean4#13363

* chore: bump to nightly-2026-04-25

* satisfy linter

* chore: bump to nightly-2026-04-27

* Apply suggestion from @kim-em

* Apply suggestion from @kim-em

---------

Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Wojciech Rozowski <[email protected]>
Co-authored-by: mathlib-nightly-testing[bot] <mathlib-nightly-testing[bot]@users.noreply.github.com>
Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: thorimur <[email protected]>
Co-authored-by: Julia Markus Himmel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-other mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants