[Merged by Bors] - feat: make the dupNamespace linter catch any duplicate namespace(s)#39793
[Merged by Bors] - feat: make the dupNamespace linter catch any duplicate namespace(s)#39793grunweg wants to merge 33 commits into
dupNamespace linter catch any duplicate namespace(s)#39793Conversation
PR summary 2e7d27597d
|
| File | Base Count | Head Count | Change |
|---|---|---|---|
| Mathlib.Tactic.Linter.Lint | 5 | 4 | -1 (-20.00%) |
Import changes for all files
| Files | Import difference |
|---|---|
Mathlib.Tactic.Linter.Lint |
-1 |
Declarations diff (regex)
+ Bar.Foo.Foo
+ Foo.Bar.Baz.Hoge.Foo.Bar.Baz.az
+ Foo.Bar.Baz.Hoge.Foo.Bar.baz
+ Foo.Bar.Baz.Hoge.Foo.Baz.baz
+ Foo.Bar.Foo.Bar.baz
+ Foo.Bar.Foo.baz
+ Foo.Bar.Foo.baz'
+ Foo.Bar.baz'
+ Foo.Foo
+ Foo.Foo.Bar
+ Foo.Foo.Bar.Baz.hoge
+ Foo.Foos.Bar.Baz
+ Subgroup.AddSubgroup.foo
+ pullback.desc'
- CategoryTheory.Limits.pullback.desc'
- Distribution.IsVanishingOn.smulLeftCLM
- Distribution.dsupport_smulLeftCLM_subset
You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>
## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.
Declarations diff (Lean)
✅ Lean-aware diff — post-build, computed from the Lean environment (commit
2e7d275).
- +3 new declarations
- −3 removed declarations
-CategoryTheory.Limits.CategoryTheory.Limits.pullback.desc'
+CategoryTheory.Limits.pullback.desc'
+Distribution.IsVanishingOn.smulLeftCLM
-Distribution.TemperedDistribution.Distribution.dsupport_smulLeftCLM_subset
-Distribution.TemperedDistribution.IsVanishingOn.Distribution.IsVanishingOn.smulLeftCLM
+Distribution.dsupport_smulLeftCLM_subsetNo changes to strong technical debt.
No changes to weak technical debt.
Current commit 2e7d27597d
Reference commit b4b33fa6e8
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
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
kim-em
left a comment
There was a problem hiding this comment.
One thing outside the diff: the module docstring at L67–70 and the option docstring at L74–77 both still say "at least twice consecutively" and use Nat.One.Nat as the negative example, but after this PR Nat.One.Nat does warn. Both need updating.
| | continue | ||
| Linter.logLint linter.dupNamespace id | ||
| m!"The namespace '{dup}' is duplicated in the declaration '{declName}'" | ||
| if !nm.Nodup then |
There was a problem hiding this comment.
Redundant if you match on the computed list directly: | [] => continue | [ns] => … | dups => …. Avoids the extra O(n²) Nodup pass and reads more directly.
There was a problem hiding this comment.
I actually think the previous logic was more readable. Now, the error message and emitting the linter warning is spread across two similar cases. I'm also not sure if the performance difference matters.
I've changed it anyway (as I don't feel strongly either).
|
This PR/issue depends on: |
|
Now that the dependency was merged, we need to turn off the linter ( These 45 deprecated aliasesand (btw Joël said these shouldn't be used directly so we could try inlining them into the |
dupNamespace linter catch any duplicate namespace(s)
|
Thanks for the helpful review. (Indeed, I had not made a careful pass over this code yet.) I have acted on most comments, and also fixed a pre-existing outdated line in the doc-string. I just wonder: did you just use an LLM to review my PR? Some comments read a bit like that. |
|
@SnirBroshi Good point. If you'd like to do this, be my guest (to e.g. make a PR into this branch)! Otherwise, I'll probably do so tomorrow. |
grunweg#7 |
|
@SnirBroshi I just merged master... do you mind rebasing your PR on top of this one? Then I'll be happy to merge it! |
|
@grunweg Done! |
joneugster
left a comment
There was a problem hiding this comment.
Thanks, this is a good addition to the linter!
- update documentation (including an outdated comment about auto-generated names; there is now a test which verifies this is false), - print multiple namespaces more nicely, - inline duplicate checking: List.Nodup is currently quadratic; let's avoid an additional pass over the full list. It is slightly less readable, but perhaps the performance difference is worth it...
Co-authored-by: Jon Eugster <eugster.jon@gmail.com>
Co-authored-by: Thomas R. Murrills <68410468+thorimur@users.noreply.github.com>
|
This looks good to me, thanks! :) I've also checked that every maintainer merge |
|
🚀 Pull request has been placed on the maintainer queue by thorimur. |
We do have some linting for that, right? (I haven't checked if it would have caught this one. Perhaps it should?) |
…nprover-community#40213) The Scheme.Modules namespace was duplicated in the declaration. Found by the strengthening the `dupNamespace` linter in leanprover-community#39793.
…0390) The old deprecation did not do what it was supposed to, because it duplicate the `NumberField.Units` namespace. This is an oversight from leanprover-community#40239. Found by the linter in leanprover-community#39793. Since that PR is just two days old, I am fixing the deprecation instead of adding an additional one.
|
Thanks! There are a couple of extra exceptions, I think. bors d+ |
|
✌️ grunweg can now approve this pull request until 2026-07-15 22:09 UTC (in 2 weeks). To approve and merge, reply with
|
The PR added deprecated aliases, but in a wrong namespace: this meant the original declarations did not actually get deprecated (and had in fact duplicated namespaces in their name). Fix the deprecation. As these landed just 24 hours ago, we don't deprecate the deprecations. Also update the deprecation date to when the PR was actually merged.
…tion The deprecation accidentally duplicated declaration namespaces, meaning it was never effective. This is confirmed by the declarations diff on the PR back then. Fix it.
|
Thanks! The latest linter run caught two broken deprecations, so this is great! The Lean-based declaration diff in the summary comment is extremely helpful here, by the way. |
|
As this PR is labelled bors merge |
…#39793) Before this PR, the `dupNamespace` linter would only flag a namespace as duplicate if it was repeated in two consecutive positions: `Foo.Foo.bar` would be linted, but neither `Foo.Bar.Foo.Bar.baz` nor `Foo.Bar.Foo.Baz.baz` would be (even though they are very likely unintentional). Strengthen the linter check, to error if any namespace component is duplicated. This has few false positives (which we manually annotate), but catches many pre-existing cases where the duplication was clearly unintentional and undesirable. Most of the mathlib adaptation was done in #39794. Co-authored-by: Snir Broshi <26556598+SnirBroshi@users.noreply.github.com>
|
Pull request successfully merged into master. Build succeeded: |
dupNamespace linter catch any duplicate namespace(s)dupNamespace linter catch any duplicate namespace(s)
…amespace` linter (leanprover#14249) This PR extends `dupNamespace` linter to allow users to opt-in via `linter.extra.dupNamespace.consecutiveOnly` option to check non-consecutive repeated usages of namespace components. By default, only consecutive ones are checked. Opting in for non-consecutive checks matches the behaviour introduced in [mathlib4#39793](leanprover-community/mathlib4#39793).
…leanprover-community#39793) Before this PR, the `dupNamespace` linter would only flag a namespace as duplicate if it was repeated in two consecutive positions: `Foo.Foo.bar` would be linted, but neither `Foo.Bar.Foo.Bar.baz` nor `Foo.Bar.Foo.Baz.baz` would be (even though they are very likely unintentional). Strengthen the linter check, to error if any namespace component is duplicated. This has few false positives (which we manually annotate), but catches many pre-existing cases where the duplication was clearly unintentional and undesirable. Most of the mathlib adaptation was done in leanprover-community#39794. Co-authored-by: Snir Broshi <26556598+SnirBroshi@users.noreply.github.com>
…amespace` linter (leanprover#14249) This PR extends `dupNamespace` linter to allow users to opt-in via `linter.extra.dupNamespace.consecutiveOnly` option to check non-consecutive repeated usages of namespace components. By default, only consecutive ones are checked. Opting in for non-consecutive checks matches the behaviour introduced in [mathlib4#39793](leanprover-community/mathlib4#39793).
…leanprover-community#39793) Before this PR, the `dupNamespace` linter would only flag a namespace as duplicate if it was repeated in two consecutive positions: `Foo.Foo.bar` would be linted, but neither `Foo.Bar.Foo.Bar.baz` nor `Foo.Bar.Foo.Baz.baz` would be (even though they are very likely unintentional). Strengthen the linter check, to error if any namespace component is duplicated. This has few false positives (which we manually annotate), but catches many pre-existing cases where the duplication was clearly unintentional and undesirable. Most of the mathlib adaptation was done in leanprover-community#39794. Co-authored-by: Snir Broshi <26556598+SnirBroshi@users.noreply.github.com>
Before this PR, the
dupNamespacelinter would only flag a namespace as duplicate if it was repeated in two consecutive positions:Foo.Foo.barwould be linted, but neitherFoo.Bar.Foo.Bar.baznorFoo.Bar.Foo.Baz.bazwould be (even though they are very likely unintentional).Strengthen the linter check, to error if any namespace component is duplicated.
This has few false positives (which we manually annotate), but catches many pre-existing
cases where the duplication was clearly unintentional and undesirable.
Most of the mathlib adaptation was done in #39794.