Re: [PATCH v3 2/2] checkpatch: warn on known non-plural rust doc headers

From: Benno Lossin
Date: Fri Sep 13 2024 - 15:34:57 EST


On 13.09.24 21:21, Joe Perches wrote:
> On Fri, 2024-09-13 at 09:33 +0200, Alice Ryhl wrote:
>> On Thu, Sep 12, 2024 at 9:57 PM Patrick Miller <paddymills@xxxxxxxxx> wrote:
>>> @@ -3900,6 +3900,13 @@ sub process {
>>> "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/core-api/asm-annotations.rst\n" . $herecurr);
>>> }
>>>
>>> +# check that document section headers are plural in rust files
>>> + if ($realfile =~ /\.rs$/ &&
>>> + $rawline =~ /^\+\s*\/\/\/\s+#+\s+(Example|Invariant|Guarantee|Panic)\s*$/) {

@Patrick, could you also add `Error` to this list?

>>> + WARN("RUST_DOC_HEADER",
>>> + "Rust doc headers should be plural\n" . $herecurr);
>
> While OK my suggestion would be to add a $fix option
> and be case insensitive
>
> if ($realfile =~ /\.rs$/ &&
> $rawline =~ /^\+\s*\/\/\/\s+#+\s+(Example|Invariant|Guarantee|Panic)\s*$/i) {
> if (WARN("RUST_DOC_HEADER",
> "Rust doc header '$1' should be plural\n" . $herecurr) &&
> $fix) {
> $fixed[$fixlinenr] = s/\b$1\b/ucfirst(lc($1))/e;
> }
>
> And if there are going to be more rust specific tests,
> there should be a rust specific block to avoid continual
> tests of $realfile =~ /\.rs$/

Yes please, we're already planning more checks.

---
Cheers,
Benno