Skip to content

Commit d8d2a17

Browse files
grunwegSnirBroshi
authored andcommitted
feat: make the dupNamespace linter catch any duplicate namespace(s) (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>
1 parent 46faa85 commit d8d2a17

20 files changed

Lines changed: 190 additions & 25 deletions

File tree

Mathlib/Algebra/Polynomial/Bivariate.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ lemma pderiv_zero_equivMvPolynomial {R : Type*} [CommRing R] (p : R[X][Y]) :
353353
simp_rw [← Polynomial.C_mul_X_pow_eq_monomial]
354354
simp [map_nsmul]
355355

356+
set_option linter.dupNamespace false in
356357
@[deprecated (since := "2025-12-09")]
357358
alias Polynomial.Bivariate.pderiv_zero_equivMvPolynomial := pderiv_zero_equivMvPolynomial
358359

@@ -367,6 +368,7 @@ lemma pderiv_one_equivMvPolynomial (p : R[X][Y]) :
367368
simp_rw [← Polynomial.C_mul_X_pow_eq_monomial]
368369
simp [derivative_pow]
369370

371+
set_option linter.dupNamespace false in
370372
@[deprecated (since := "2025-12-09")]
371373
alias Polynomial.Bivariate.pderiv_one_equivMvPolynomial := pderiv_one_equivMvPolynomial
372374

Mathlib/Analysis/Distribution/Support.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ theorem smulLeftCLM (hf : IsVanishingOn f s) {g : E → ℂ} (hg : g.HasTemperat
189189
rw [SchwartzMap.smulLeftCLM_apply hg]
190190
exact (tsupport_smul_subset_right g u).trans hu
191191

192-
@[deprecated (since := "2026-06-27")] alias Distribution.IsVanishingOn.smulLeftCLM :=
192+
@[deprecated (since := "2026-07-01")] alias _root_.Distribution.IsVanishingOn.smulLeftCLM :=
193193
Distribution.TemperedDistribution.IsVanishingOn.smulLeftCLM
194194

195195
open LineDeriv
@@ -225,7 +225,7 @@ theorem dsupport_smulLeftCLM_subset {g : E → ℂ} (hg : g.HasTemperateGrowth)
225225
dsupport (smulLeftCLM F g f) ⊆ dsupport f := by
226226
gcongr; fun_prop
227227

228-
@[deprecated (since := "2026-06-27")] alias Distribution.dsupport_smulLeftCLM_subset :=
228+
@[deprecated (since := "2026-07-01")] alias _root_.Distribution.dsupport_smulLeftCLM_subset :=
229229
Distribution.TemperedDistribution.dsupport_smulLeftCLM_subset
230230

231231
open LineDeriv

Mathlib/Analysis/InnerProductSpace/JointEigenspace.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ theorem directSum_isInternal_of_pairwise_commute [DecidableEq (n → 𝕜)]
140140
· rw [iSup_iInf_eq_top_of_commute hT hC, top_orthogonal_eq_bot]
141141
· exact orthogonalFamily_iInf_eigenspaces hT
142142

143+
set_option linter.dupNamespace false in
143144
@[deprecated (since := "2026-05-24")]
144145
alias LinearMap.IsSymmetric.directSum_isInternal_of_pairwise_commute :=
145146
directSum_isInternal_of_pairwise_commute

Mathlib/CategoryTheory/Bicategory/Adjunction/Adj.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,27 @@ def iso₂Mk {α β : a ⟶ b} (el : α.l ≅ β.l) (er : β.r ≅ α.r)
131131

132132
namespace Bicategory
133133

134+
set_option linter.dupNamespace false in
134135
/-- The associator in the bicategory `Adj B`. -/
135136
@[simps!]
136137
def associator (α : a ⟶ b) (β : b ⟶ c) (γ : c ⟶ d) : (α ≫ β) ≫ γ ≅ α ≫ β ≫ γ :=
137138
iso₂Mk (α_ _ _ _) (α_ _ _ _) (conjugateEquiv_associator_hom _ _ _)
138139

140+
set_option linter.dupNamespace false in
139141
/-- The left unitor in the bicategory `Adj B`. -/
140142
@[simps!]
141143
def leftUnitor (α : a ⟶ b) : 𝟙 a ≫ α ≅ α :=
142144
iso₂Mk (λ_ _) (ρ_ _).symm
143145
(by simpa using conjugateEquiv_id_comp_right_apply α.adj α.adj (𝟙 _))
144146

147+
set_option linter.dupNamespace false in
145148
/-- The right unitor in the bicategory `Adj B`. -/
146149
@[simps!]
147150
def rightUnitor (α : a ⟶ b) : α ≫ 𝟙 b ≅ α :=
148151
iso₂Mk (ρ_ _) (λ_ _).symm
149152
(by simpa using conjugateEquiv_comp_id_right_apply α.adj α.adj (𝟙 _))
150153

154+
set_option linter.dupNamespace false in
151155
/-- The left whiskering in the bicategory `Adj B`. -/
152156
@[simps]
153157
def whiskerLeft (α : a ⟶ b) {β β' : b ⟶ c} (y : β ⟶ β') : α ≫ β ⟶ α ≫ β' where
@@ -156,6 +160,7 @@ def whiskerLeft (α : a ⟶ b) {β β' : b ⟶ c} (y : β ⟶ β') : α ≫ β
156160
conjugateEquiv_τl := by
157161
simp [conjugateEquiv_whiskerLeft, Hom₂.conjugateEquiv_τl]
158162

163+
set_option linter.dupNamespace false in
159164
/-- The right whiskering in the bicategory `Adj B`. -/
160165
@[simps]
161166
def whiskerRight {α α' : a ⟶ b} (x : α ⟶ α') (β : b ⟶ c) : α ≫ β ⟶ α' ≫ β where

Mathlib/CategoryTheory/Groupoid/VertexGroup.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ def _root_.CategoryTheory.Functor.mapVertexGroup {D : Type v} [Groupoid D] (φ :
8383
map_one' := φ.map_id c
8484
map_mul' := φ.map_comp
8585

86+
set_option linter.dupNamespace false in
8687
@[deprecated (since := "2026-05-24")]
8788
alias CategoryTheory.Functor.mapVertexGroup := CategoryTheory.Functor.mapVertexGroup
8889

90+
set_option linter.dupNamespace false in
8991
@[deprecated (since := "2026-05-24")]
9092
alias CategoryTheory.Functor.mapVertexGroup_apply := CategoryTheory.Functor.mapVertexGroup_apply
9193

Mathlib/CategoryTheory/Limits/Shapes/Pullback/HasPullback.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ def pushout.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h
204204
{ l : pushout f g ⟶ W // pushout.inl _ _ ≫ l = h ∧ pushout.inr _ _ ≫ l = k } :=
205205
⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩
206206

207-
@[deprecated (since := "2026-06-25")]
208-
alias CategoryTheory.Limits.pullback.desc' := pushout.desc'
207+
@[deprecated (since := "2026-06-25")] alias pullback.desc' := pushout.desc'
209208

210209
@[reassoc]
211210
theorem pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] :

Mathlib/CategoryTheory/Subobject/Classifier/Defs.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ namespace SubobjectRepresentableBy
392392
given `h : SubobjectRepresentableBy Ω`. -/
393393
def Ω₀ : Subobject Ω := h.homEquiv (𝟙 Ω)
394394

395+
set_option linter.dupNamespace false in
395396
@[deprecated (since := "2026-03-06")]
396397
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.Ω₀ := Ω₀
397398
@[deprecated (since := "2026-03-06")]
@@ -403,6 +404,7 @@ lemma homEquiv_eq {X : C} (f : X ⟶ Ω) :
403404
h.homEquiv f = (Subobject.pullback f).obj h.Ω₀ := by
404405
simpa using! h.homEquiv_comp f (𝟙 _)
405406

407+
set_option linter.dupNamespace false in
406408
@[deprecated (since := "2026-03-06")]
407409
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.homEquiv_eq := homEquiv_eq
408410
@[deprecated (since := "2026-03-06")]
@@ -414,6 +416,7 @@ lemma pullback_homEquiv_symm_obj_Ω₀ {X : C} (x : Subobject X) :
414416
(Subobject.pullback (h.homEquiv.symm x)).obj h.Ω₀ = x := by
415417
rw [← homEquiv_eq, Equiv.apply_symm_apply]
416418

419+
set_option linter.dupNamespace false in
417420
@[deprecated (since := "2026-03-06")]
418421
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.pullback_homEquiv_symm_obj_Ω₀ :=
419422
pullback_homEquiv_symm_obj_Ω₀
@@ -428,6 +431,7 @@ variable {U X : C} (m : U ⟶ X) [Mono m]
428431
/-- `h.χ m` is the characteristic map of monomorphism `m` given by the bijection `h.homEquiv`. -/
429432
def χ : X ⟶ Ω := h.homEquiv.symm (Subobject.mk m)
430433

434+
set_option linter.dupNamespace false in
431435
@[deprecated (since := "2026-03-06")]
432436
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.χ := χ
433437
@[deprecated (since := "2026-03-06")]
@@ -440,6 +444,7 @@ noncomputable def iso : MonoOver.mk m ≅
440444
(Subobject.representativeIso (.mk m)).symm ≪≫ Subobject.representative.mapIso
441445
(eqToIso (h.pullback_homEquiv_symm_obj_Ω₀ (.mk m)).symm)
442446

447+
set_option linter.dupNamespace false in
443448
@[deprecated (since := "2026-03-06")]
444449
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.iso := iso
445450
@[deprecated (since := "2026-03-06")]
@@ -459,6 +464,7 @@ alias _root_.CategoryTheory.Classifier.SubobjectRepresentableBy.iso := iso
459464
noncomputable def π : U ⟶ Subobject.underlying.obj h.Ω₀ :=
460465
(h.iso m).hom.hom.left ≫ Subobject.pullbackπ (h.χ m) h.Ω₀
461466

467+
set_option linter.dupNamespace false in
462468
@[deprecated (since := "2026-03-06")]
463469
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.π := π
464470
@[deprecated (since := "2026-03-06")]
@@ -473,6 +479,7 @@ lemma iso_inv_left_π :
473479
convert! Category.id_comp _ using 2
474480
exact (MonoOver.forget _ ⋙ Over.forget _).congr_map (h.iso m).inv_hom_id
475481

482+
set_option linter.dupNamespace false in
476483
@[deprecated (since := "2026-03-06")]
477484
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.iso_inv_left_π := iso_inv_left_π
478485
@[deprecated (since := "2026-03-06")]
@@ -484,13 +491,15 @@ lemma iso_inv_hom_left_comp :
484491
((Subobject.pullback (h.χ m)).obj h.Ω₀).arrow :=
485492
MonoOver.w (h.iso m).inv
486493

494+
set_option linter.dupNamespace false in
487495
@[deprecated (since := "2026-03-06")]
488496
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.iso_inv_hom_left_comp :=
489497
iso_inv_hom_left_comp
490498
@[deprecated (since := "2026-03-06")]
491499
alias _root_.CategoryTheory.Classifier.SubobjectRepresentableBy.iso_inv_hom_left_comp :=
492500
iso_inv_hom_left_comp
493501

502+
set_option linter.dupNamespace false in
494503
@[deprecated (since := "2025-12-18")]
495504
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.iso_inv_left_comp :=
496505
iso_inv_hom_left_comp
@@ -503,6 +512,7 @@ lemma isPullback {U X : C} (m : U ⟶ X) [Mono m] :
503512
(Iso.refl _) (Iso.refl _)
504513
all_goals simp [MonoOver.forget]
505514

515+
set_option linter.dupNamespace false in
506516
@[deprecated (since := "2026-03-06")]
507517
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.isPullback := isPullback
508518
@[deprecated (since := "2026-03-06")]
@@ -515,6 +525,7 @@ lemma uniq {χ' : X ⟶ Ω} {π : U ⟶ h.Ω₀}
515525
simp only [χ, Equiv.apply_symm_apply, homEquiv_eq]
516526
simpa using! Subobject.pullback_obj_mk sq.flip
517527

528+
set_option linter.dupNamespace false in
518529
@[deprecated (since := "2026-03-06")]
519530
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.uniq := uniq
520531
@[deprecated (since := "2026-03-06")]
@@ -532,6 +543,7 @@ noncomputable def isTerminalΩ₀ : IsTerminal (h.Ω₀ : C) :=
532543
rw [← cancel_mono h.Ω₀.arrow, h.uniq this,
533544
← (h.isPullback (𝟙 X)).w, Category.id_comp])
534545

546+
set_option linter.dupNamespace false in
535547
@[deprecated (since := "2026-03-06")]
536548
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.isTerminalΩ₀ := isTerminalΩ₀
537549
@[deprecated (since := "2026-03-06")]
@@ -540,6 +552,7 @@ alias _root_.CategoryTheory.Classifier.SubobjectRepresentableBy.isTerminalΩ₀
540552
/-- The unique map to the terminal object. -/
541553
noncomputable def χ₀ (U : C) : U ⟶ h.Ω₀ := h.isTerminalΩ₀.from U
542554

555+
set_option linter.dupNamespace false in
543556
@[deprecated (since := "2026-03-06")]
544557
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.χ₀ := χ₀
545558
@[deprecated (since := "2026-03-06")]
@@ -548,6 +561,7 @@ alias _root_.CategoryTheory.Classifier.SubobjectRepresentableBy.χ₀ := χ₀
548561
include h in
549562
lemma hasTerminal : HasTerminal C := h.isTerminalΩ₀.hasTerminal
550563

564+
set_option linter.dupNamespace false in
551565
@[deprecated (since := "2026-03-06")]
552566
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.hasTerminal := hasTerminal
553567
@[deprecated (since := "2026-03-06")]
@@ -559,6 +573,7 @@ variable [HasTerminal C]
559573
noncomputable def isoΩ₀ : (h.Ω₀ : C) ≅ ⊤_ C :=
560574
h.isTerminalΩ₀.conePointUniqueUpToIso (limit.isLimit _)
561575

576+
set_option linter.dupNamespace false in
562577
@[deprecated (since := "2026-03-06")]
563578
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.isoΩ₀ := isoΩ₀
564579
@[deprecated (since := "2026-03-06")]
@@ -582,6 +597,7 @@ noncomputable def classifier : Subobject.Classifier C where
582597
(by simp) (h.isTerminalΩ₀.hom_ext _ _) (by simp) (by simp)
583598
exact h.uniq this
584599

600+
set_option linter.dupNamespace false in
585601
@[deprecated (since := "2026-03-06")]
586602
alias _root.CategoryTheory.Classifier.SubobjectRepresentableBy.classifier := classifier
587603
@[deprecated (since := "2026-03-06")]

Mathlib/Data/Set/FiniteExhaustion.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ lemma _root_.Set.nonempty_finiteExhaustion_iff {s : Set α} :
8080
rw [← K.iUnion_eq]
8181
exact countable_iUnion <| fun i ↦ (K.finite i).countable
8282

83+
set_option linter.dupNamespace false in
8384
@[deprecated (since := "2026-05-24")]
8485
alias Set.nonempty_finiteExhaustion_iff := Set.nonempty_finiteExhaustion_iff
8586

Mathlib/Geometry/Manifold/VectorBundle/MDifferentiable.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ theorem mdifferentiable [ContMDiffVectorBundle 1 F Z I]
317317
e.MDifferentiable (I.prod 𝓘(𝕜, F)) (I.prod 𝓘(𝕜, F)) :=
318318
⟨e.contMDiffOn.mdifferentiableOn one_ne_zero, e.contMDiffOn_symm.mdifferentiableOn one_ne_zero⟩
319319

320+
set_option linter.dupNamespace false in
320321
@[deprecated (since := "2026-05-24")] alias Bundle.Trivialization.mdifferentiable := mdifferentiable
321322

322323
end

Mathlib/GroupTheory/Submonoid/Inverses.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ theorem _root_.IsUnit.submonoid.coe_inv [Monoid M] (x : IsUnit.submonoid M) :
5656

5757
@[deprecated (since := "2026-05-24")]
5858
alias _root_.AddSubmonoid.IsUnit.Submonoid.coe_neg := IsAddUnit.addSubmonoid.coe_neg
59+
set_option linter.dupNamespace false in
5960
@[to_additive existing, deprecated (since := "2026-05-24")]
6061
alias IsUnit.Submonoid.coe_inv := IsUnit.submonoid.coe_inv
6162

0 commit comments

Comments
 (0)