Skip to content

Commit ac3e932

Browse files
adomanigrunweg
andcommitted
feat: add some name validation for authors (#29806)
The check consists of verifying that each file has at least one Copyright holder and one Author. Co-authored-by: Michael Rothgang <rothgang@math.uni-bonn.de>
1 parent a29cbe3 commit ac3e932

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed

Mathlib/Probability/HasLaw.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/-
22
Copyright (c) 2025 Etienne Marion. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: EtienneMarion
4+
Authors: Etienne Marion
55
-/
66
import Mathlib.Probability.Density
77
import Mathlib.Probability.Moments.Variance

Mathlib/Tactic/Linter/Header.lean

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ def authorsLineChecks (line : String) (offset : String.Pos.Raw) : Array (Syntax
134134
stxs := stxs.push
135135
(toSyntax line "." offset,
136136
s!"Please, do not end the authors' line with a period.")
137-
return stxs
137+
-- If there are no previous exceptions, then we try to validate the names.
138+
if !stxs.isEmpty then
139+
return stxs
140+
if (line.drop "Authors:".length).trim.isEmpty then
141+
return #[(toSyntax line "Authors:" offset,
142+
s!"Please, add at least one author!")]
143+
else
144+
return #[]
138145

139146
/-- The main function to validate the copyright string.
140147
The input is the copyright string, the output is an array of `Syntax × String` encoding:
@@ -180,6 +187,15 @@ def copyrightHeaderChecks (copyright : String) : Array (Syntax × String) := Id.
180187
output := output.push
181188
(toSyntax copyright (copyrightAuthor.take copStart.length),
182189
s!"Copyright line should start with 'Copyright (c) YYYY'")
190+
let author := (copyrightAuthor.drop (copStart.length + 2))
191+
if output.isEmpty && author.take 1 != " " then
192+
output := output.push
193+
(toSyntax copyright (copyrightAuthor.drop (copStart.length + 2)),
194+
s!"'Copyright (c) YYYY' should be followed by a space")
195+
if output.isEmpty && #["", ".", ","].contains ((author.drop 1).take 1).trim then
196+
output := output.push
197+
(toSyntax copyright (copyrightAuthor.drop (copStart.length + 3)),
198+
s!"There should be at least one copyright author, separated from the year by exactly one space.")
183199
if !copyrightAuthor.endsWith copStop then
184200
output := output.push
185201
(toSyntax copyright (copyrightAuthor.takeRight copStop.length),

MathlibTest/Header.lean

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ open Lean Elab Command in
5555
`#check_copyright cop` takes as input the `String` `cop`, expected to be a copyright statement.
5656
It logs details of what the linter would report if the `cop` is "malformed".
5757
-/
58-
elab "#check_copyright " cop:str : command => do
59-
let cop := cop.getString
58+
elab "#check_copyright " copStx:str : command => do
59+
let cop := copStx.getString
60+
let offset := copStx.raw.getPos?.get!.increaseBy 1
6061
for (s, m) in Mathlib.Linter.copyrightHeaderChecks cop do
6162
if let some rg := s.getRange? then
62-
logInfo
63+
logInfoAt (.ofRange ({start := rg.start.offsetBy offset, stop := rg.stop.offsetBy offset}))
6364
m!"Text: `{replaceMultilineComments s.getAtomVal}`\n\
6465
Range: {(rg.start, rg.stop)}\n\
6566
Message: '{replaceMultilineComments m}'"
@@ -320,3 +321,74 @@ Authors: Name LastName
320321
and others.
321322
-/
322323
"
324+
325+
/--
326+
info: Text: `Authors:`
327+
Range: (140, 148)
328+
Message: 'The authors line should begin with 'Authors: ''
329+
-/
330+
#guard_msgs in
331+
#check_copyright
332+
"/-
333+
Copyright (c) 2024 Damiano Testa, another Name. All rights reserved.
334+
Released under Apache 2.0 license as described in the file LICENSE.
335+
Authors:
336+
-/
337+
"
338+
339+
/--
340+
info: Text: `. All rights reserved.`
341+
Range: (21, 43)
342+
Message: ''Copyright (c) YYYY' should be followed by a space'
343+
-/
344+
#guard_msgs in
345+
#check_copyright
346+
"/-
347+
Copyright (c) 2024. All rights reserved.
348+
Released under Apache 2.0 license as described in the file LICENSE.
349+
Authors: A
350+
-/
351+
"
352+
353+
/--
354+
info: Text: `. All rights reserved.`
355+
Range: (22, 44)
356+
Message: 'There should be at least one copyright author, separated from the year by exactly one space.'
357+
-/
358+
#guard_msgs in
359+
#check_copyright
360+
"/-
361+
Copyright (c) 2024 . All rights reserved.
362+
Released under Apache 2.0 license as described in the file LICENSE.
363+
Authors: A
364+
-/
365+
"
366+
367+
-- We don't do further validation of names.
368+
369+
#guard_msgs in
370+
#check_copyright
371+
"/-
372+
Copyright (c) 2024 nameinalllowercase. All rights reserved.
373+
Released under Apache 2.0 license as described in the file LICENSE.
374+
Authors: A
375+
-/
376+
"
377+
378+
#guard_msgs in
379+
#check_copyright
380+
"/-
381+
Copyright (c) 2024 First middle LastName. All rights reserved.
382+
Released under Apache 2.0 license as described in the file LICENSE.
383+
Authors: A
384+
-/
385+
"
386+
387+
#guard_msgs in
388+
#check_copyright
389+
"/-
390+
Copyright (c) 2024 First Last Name jr.. All rights reserved.
391+
Released under Apache 2.0 license as described in the file LICENSE.
392+
Authors: A
393+
-/
394+
"

0 commit comments

Comments
 (0)