2021-01-03 07:53:44

by Nicolai Fischer

[permalink] [raw]
Subject: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation

Adds a new warning in case the indentation level of the
first line of a Kconfig help message is not at least two spaces
higher than the keyword itself.
Blank lines between the message and the help keyword
are ignored.

Co-developed-by: Johannes Czekay <[email protected]>
Signed-off-by: Johannes Czekay <[email protected]>
Signed-off-by: Nicolai Fischer <[email protected]>
---

Now matches indentation of two or more spaces, instead of exactly two.


scripts/checkpatch.pl | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c86a971a3205..209880810aaa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3313,6 +3313,8 @@ sub process {
my $f;
my $is_start = 0;
my $is_end = 0;
+ my $help_indent;
+ my $help_stat_real;
for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
$f = $lines[$ln - 1];
$cnt-- if ($lines[$ln - 1] !~ /^-/);
@@ -3323,8 +3325,10 @@ sub process {

if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*(?:["'].*)?$/) {
$is_start = 1;
- } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
- $length = -1;
+ } elsif ($lines[$ln - 1] =~ /^\+(\s*)help$/) {
+ $help_indent = $1;
+ $length = 0;
+ next;
}

$f =~ s/^.//;
@@ -3332,6 +3336,13 @@ sub process {
$f =~ s/^\s+//;
next if ($f =~ /^$/);

+ if (defined $help_indent) {
+ if ($lines[$ln - 1] !~ /^\+$help_indent\ {2,}\S*/) {
+ $help_stat_real = get_stat_real($ln - 1, $ln);
+ }
+ undef $help_indent;
+ }
+
# This only checks context lines in the patch
# and so hopefully shouldn't trigger false
# positives, even though some of these are
@@ -3347,6 +3358,10 @@ sub process {
WARN("CONFIG_DESCRIPTION",
"please write a paragraph that describes the config symbol fully\n" . $herecurr);
}
+ if ($is_start && $is_end && defined $help_stat_real) {
+ WARN("CONFIG_DESCRIPTION",
+ "please indent the help text two spaces more than the keyword\n" . "$here\n$help_stat_real\n");
+ }
#print "is_start<$is_start> is_end<$is_end> length<$length>\n";
}

--
2.29.2


2021-01-04 22:11:05

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation

On Sun, 2021-01-03 at 08:50 +0100, Nicolai Fischer wrote:
> Adds a new warning in case the indentation level of the
> first line of a Kconfig help message is not at least two spaces
> higher than the keyword itself.
> Blank lines between the message and the help keyword
> are ignored.
>
> Co-developed-by: Johannes Czekay <[email protected]>
> Signed-off-by: Johannes Czekay <[email protected]>
> Signed-off-by: Nicolai Fischer <[email protected]>
> ---
>
> Now matches indentation of two or more spaces, instead of exactly two.

No, this should match exactly 2 and warn on any other use.


2021-01-05 11:28:36

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation

On Mon, 2021-01-04 at 14:09 -0800, Joe Perches wrote:
> On Sun, 2021-01-03 at 08:50 +0100, Nicolai Fischer wrote:
> > Adds a new warning in case the indentation level of the
> > first line of a Kconfig help message is not at least two spaces
> > higher than the keyword itself.
> > Blank lines between the message and the help keyword
> > are ignored.
> >
> > Co-developed-by: Johannes Czekay <[email protected]>
> > Signed-off-by: Johannes Czekay <[email protected]>
> > Signed-off-by: Nicolai Fischer <[email protected]>
> > ---
> >
> > Now matches indentation of two or more spaces, instead of exactly two.
>
> No, this should match exactly 2 and warn on any other use.

To clarify, only the first line after the help keyword needs to
have a 2 space indent more than the help keyword and the help
block may start with Kconfig keywords.

Subsequent help block lines may have more than 2 chars.

The help block line count should end when the indent is less than
the help keyword indent and is a non-blank line.

This should be valid:

help
line 1
-- reason 1
-- reason 2
continuation
-- reason 3

But this should warn only on line 1:

help
line 1 has a 3 space indent
-- reason 1
-- reason 2
continuation
-- reason 3


2021-01-05 21:16:54

by Nicolai Fischer

[permalink] [raw]
Subject: Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation



On Tue 05.01.21 09:57, Joe Perches wrote:
> On Mon, 2021-01-04 at 14:09 -0800, Joe Perches wrote:
>> On Sun, 2021-01-03 at 08:50 +0100, Nicolai Fischer wrote:
>>> Adds a new warning in case the indentation level of the
>>> first line of a Kconfig help message is not at least two spaces
>>> higher than the keyword itself.
>>> Blank lines between the message and the help keyword
>>> are ignored.
>>>
>>> Co-developed-by: Johannes Czekay <[email protected]>
>>> Signed-off-by: Johannes Czekay <[email protected]>
>>> Signed-off-by: Nicolai Fischer <[email protected]>
>>> ---
>>>
>>> Now matches indentation of two or more spaces, instead of exactly two.
>>
>> No, this should match exactly 2 and warn on any other use.
>
> To clarify, only the first line after the help keyword needs to
> have a 2 space indent more than the help keyword and the help
> block may start with Kconfig keywords.
>> Subsequent help block lines may have more than 2 chars.

Okay, thank you for the clarification.

>
> The help block line count should end when the indent is less than
> the help keyword indent and is a non-blank line.

We could do something like this

if (defined $help_indent) {
$lines[$ln - 1] =~ /^\+(\s*)\S+/;
if (length($1) < length($help_indent)) {
is_end = 1; last;
}

as an extra patch after patch 3.

Please clarify whether we should match for a smaller indent than the help
keyword or the first non-blank line after the keyword.


>
> This should be valid:
>
> help
> line 1
> -- reason 1
> -- reason 2
> continuation
> -- reason 3
>
> But this should warn only on line 1:
>
> help
> line 1 has a 3 space indent
> -- reason 1
> -- reason 2
> continuation
> -- reason 3
>
>