Skip to content

feat(Tactic/Linter/Header): make header linter work downstream#38396

Open
kim-em wants to merge 2 commits intoleanprover-community:masterfrom
kim-em:header-linter-downstream
Open

feat(Tactic/Linter/Header): make header linter work downstream#38396
kim-em wants to merge 2 commits intoleanprover-community:masterfrom
kim-em:header-linter-downstream

Conversation

@kim-em
Copy link
Copy Markdown
Contributor

@kim-em kim-em commented Apr 23, 2026

This PR makes linter.style.header usable in projects downstream of Mathlib. Previously isInMathlib hardcoded a lookup of Mathlib.lean, so the linter silently exited early in (e.g.) CSLib even when enabled via linter.mathlibStandardSet.

The fix uses the root of the current mainModule to find the aggregator file, so Cslib.Foo.Bar now checks Cslib.lean, matching the standard Lean convention that a library named Foo has its root file at Foo.lean. The "skip the aggregator itself" check is generalised from mainModule == \MathlibtomainModule == mainModule.getRoot`.

Reported by Chris Henson on Zulip; cc @chenson2018 @grunweg.

🤖 Prepared with Claude Code

The header linter hardcoded `Mathlib.lean` as the aggregator file to consult
when deciding whether to inspect a file, so it silently exited early on any
project depending on Mathlib (reported for CSLib in
https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/usage.20of.20linter.2Estyle.2Eheader.20downstream).

Replace `isInMathlib` with `isInLibraryRoot`, which takes the root of the
current `mainModule` and looks for `<root>.lean`. This matches the standard
Lean convention where a library named `Foo` has its aggregator at `Foo.lean`,
so e.g. `Cslib.Foo.Bar` now consults `Cslib.lean`.

Also generalise the "skip the aggregator itself" check from
`mainModule == \`Mathlib` to `mainModule == mainModule.getRoot`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

PR summary c1e30e172c

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ isInLibraryRoot
- isInMathlib

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

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

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


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/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).

@github-actions github-actions Bot added the t-linter Linter label Apr 23, 2026
Per code review: the `mainModule == mainModule.getRoot` check is already
covered by the earlier `inLibraryRoot?` gate in practice. Keep the check
as defensive code for the edge case of a root module appearing in
`headerTestFiles`, but update the comment to reflect that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@chenson2018
Copy link
Copy Markdown
Contributor

chenson2018 commented Apr 23, 2026

This looks good to me at first glance. Once the cache is ready I'll try it out with CSLib as additional confirmation.

Edit: This appears to be working as expected.

@chenson2018
Copy link
Copy Markdown
Contributor

It looks the build now fails on a header lint in Archive, so it seems like this is working as intended!

Comment on lines +384 to +386
-- Defensive: skip linting the library root file itself. In practice the
-- `inLibraryRoot?` check above already covers this (a well-formed `<root>.lean`
-- does not import itself), but a root module could appear in `headerTestFiles`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't find the wording "Defensive: " clear at all... let me double-check the comment being outdated: #38405

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check successful: how rephrasing the comment as follows?

Suggested change
-- Defensive: skip linting the library root file itself. In practice the
-- `inLibraryRoot?` check above already covers this (a well-formed `<root>.lean`
-- does not import itself), but a root module could appear in `headerTestFiles`.
-- Skip linting the library root file itself.
-- In practice, the `inLibraryRoot?` check above already covers this (a well-formed `<root>.lean`
-- does not import itself), but a root module could appear in `headerTestFiles`.

@grunweg grunweg self-assigned this Apr 23, 2026
@grunweg
Copy link
Copy Markdown
Contributor

grunweg commented Apr 23, 2026

LGTM, with the one comment rephrased and the build failure fixed (i.e., that archive file getting a valid copyright header). Thanks for doing this!
bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors Bot commented Apr 23, 2026

✌️ kim-em can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@mathlib-triage mathlib-triage Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). t-linter Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants