2020-12-14 11:04:55

by Nicolai Fischer

[permalink] [raw]
Subject: [PATCH 2/2] checkpatch: kconfig: add missing types to regex

Kconfig parsing does not recognise all type attributes.
This adds the missing 'int', 'sting' and 'hex' types.

Signed-off-by: Nicolai Fischer <[email protected]>
Co-developed-by: Johannes Czekay <[email protected]>
Signed-off-by: Johannes Czekay <[email protected]>
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5cd98f2b75f6..442298cadab7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3321,7 +3321,7 @@ sub process {
next if ($f =~ /^-/);
last if (!$file && $f =~ /^\@\@/);

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


2020-12-20 19:15:44

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex

On Mon, 2020-12-14 at 11:24 +0100, Nicolai Fischer wrote:
> Kconfig parsing does not recognise all type attributes.
> This adds the missing 'int', 'sting' and 'hex' types.
>
> Signed-off-by: Nicolai Fischer <[email protected]>
> Co-developed-by: Johannes Czekay <[email protected]>
> Signed-off-by: Johannes Czekay <[email protected]>
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -3321,7 +3321,7 @@ sub process {
> ? next if ($f =~ /^-/);
> ? last if (!$file && $f =~ /^\@\@/);
> ?
>
> - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
> + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*["']/) {

int and hex uses are not required to be followed either a " or '
For that matter, it's not required for tristate, bool or string

Likely this should be ["'$]

$ git grep -P -oh '^\s*(?:bool|tristate|int|hex|string|prompt)\b\s*\S?' -- '*/Kconfig*' | \
sed -r -e 's/^\s+//' -e 's/\s+/ /g' | \
sort | uniq -c | sort -rn
8558 tristate "
6314 bool "
2082 bool
843 tristate
308 prompt "
286 int "
106 tristate '
93 int
84 hex "
66 string "
25 hex
21 bool '
18 string
5 hex '
3 string p
2 string (
1 string '
1 int.
1 bool #
1 bool


2020-12-20 19:17:59

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex

On Mon, 2020-12-14 at 11:24 +0100, Nicolai Fischer wrote:
> Kconfig parsing does not recognise all type attributes.
> This adds the missing 'int', 'sting' and 'hex' types.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -3321,7 +3321,7 @@ sub process {
> ? next if ($f =~ /^-/);
> ? last if (!$file && $f =~ /^\@\@/);
> ?
>
> - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
> + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*["']/) {
> ? $is_start = 1;
> ? } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
> ? $length = -1;

Another thing that could be done is to enforce the "extra 2 spaces"
indent by capturing the whitespace before the help keyword:

} elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {

could be

} elsif ($lines[$ln - 1] =~ /^\+(\s*)help\s*$/) {

with $1 used to validate the extra indent.


2020-12-21 15:16:06

by Nicolai Fischer

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex


On Sun, 2020-12-20 at 20:16 +0100, Joe Perches wrote:
> On Mon, 2020-12-14 at 11:24 +0100, Nicolai Fischer wrote:
>> Kconfig parsing does not recognise all type attributes.
>> This adds the missing 'int', 'sting' and 'hex' types.
> []
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
>> @@ -3321,7 +3321,7 @@ sub process {
>>   next if ($f =~ /^-/);
>>   last if (!$file && $f =~ /^\@\@/);
>>  
>>
>> - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
>> + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*["']/) {
>>   $is_start = 1;
>>   } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
>>   $length = -1;
>
> Another thing that could be done is to enforce the "extra 2 spaces"
> indent by capturing the whitespace before the help keyword:
>
> } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
>
> could be
>
> } elsif ($lines[$ln - 1] =~ /^\+(\s*)help\s*$/) {
>
> with $1 used to validate the extra indent.
>
>


In case the indent does not match, should we display a new warning as in our previous patch?

On Tue, 2020-12-08 at 14:35 +0100, Nicolai Fischer wrote> + WARN("CONFIG_DESCRIPTION",
> + "help text is not indented 2 spaces more than the help keyword\n" . $herecurr);

2020-12-21 17:20:17

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex

On Mon, 2020-12-21 at 16:08 +0100, Nicolai Fischer wrote:
> On Sun, 2020-12-20 at 20:16 +0100, Joe Perches wrote:
> > On Mon, 2020-12-14 at 11:24 +0100, Nicolai Fischer wrote:
> > > Kconfig parsing does not recognise all type attributes.
> > > This adds the missing 'int', 'sting' and 'hex' types.
> > []
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > []
> > > @@ -3321,7 +3321,7 @@ sub process {
> > > ? next if ($f =~ /^-/);
> > > ? last if (!$file && $f =~ /^\@\@/);
> > > ?
> > >
> > > - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
> > > + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*["']/) {
> > > ? $is_start = 1;
> > > ? } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
> > > ? $length = -1;
> >
> > Another thing that could be done is to enforce the "extra 2 spaces"
> > indent by capturing the whitespace before the help keyword:
> >
> > } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
> >
> > could be
> >
> > } elsif ($lines[$ln - 1] =~ /^\+(\s*)help\s*$/) {
> >
> > with $1 used to validate the extra indent.
> >
> >
>
>
> In case the indent does not match, should we display a new warning as in our previous patch?

Sure, but in a separate patch and ensure blank lines are ignored.

+ if ($l !~ /^\ {2}/) {
+ $wrong_indent = 1;
}

The message you used:
+ WARN("CONFIG_DESCRIPTION",
+ "help text is not indented 2 spaces more than the help keyword\n" . $herecurr);

is IMO a bit oddly phrased and could/should test only
the first line after the help keyword and show the help
line using $hereprev.



2020-12-25 17:30:16

by Nicolai Fischer

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex


On 12/21/20 6:17 PM, Joe Perches wrote:
> On Mon, 2020-12-21 at 16:08 +0100, Nicolai Fischer wrote:
>> On Sun, 2020-12-20 at 20:16 +0100, Joe Perches wrote:
>>> On Mon, 2020-12-14 at 11:24 +0100, Nicolai Fischer wrote:
>>>> Kconfig parsing does not recognise all type attributes.
>>>> This adds the missing 'int', 'sting' and 'hex' types.
>>> []
>>>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>>> []
>>>> @@ -3321,7 +3321,7 @@ sub process {
>>>>   next if ($f =~ /^-/);
>>>>   last if (!$file && $f =~ /^\@\@/);
>>>>  
>>>>
>>>> - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
>>>> + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*["']/) {
>>>>   $is_start = 1;
>>>>   } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
>>>>   $length = -1;
>>>
>>> Another thing that could be done is to enforce the "extra 2 spaces"
>>> indent by capturing the whitespace before the help keyword:
>>>
>>> } elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
>>>
>>> could be
>>>
>>> } elsif ($lines[$ln - 1] =~ /^\+(\s*)help\s*$/) {
>>>
>>> with $1 used to validate the extra indent.
>>>
>>>
>>
>>
>> In case the indent does not match, should we display a new warning as in our previous patch?
>
> Sure, but in a separate patch and ensure blank lines are ignored.
>
> + if ($l !~ /^\ {2}/) {
> + $wrong_indent = 1;
> }
>
> The message you used:
> + WARN("CONFIG_DESCRIPTION",
> + "help text is not indented 2 spaces more than the help keyword\n" . $herecurr);
>
> is IMO a bit oddly phrased and could/should test only
> the first line after the help keyword and show the help
> line using $hereprev.
>
> The problem with $herecurr is, that it always contains the first line of the Kconfig option.
The loop which actually determines if the warning is to be displayed, leaves $herecurr and likewise $hereprev unaffected.

So printing $hereprev would unfortunately not be any more helpful than $herecurr.

Because $herecurr and $hereprev also contain the line number, among other things, I am not sure what would be the best way
to address this.

2020-12-25 17:45:30

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 2/2] checkpatch: kconfig: add missing types to regex

On Fri, 2020-12-25 at 18:27 +0100, Nicolai Fischer wrote:
> On 12/21/20 6:17 PM, Joe Perches wrote:
[]
> > The message you used:
> > + WARN("CONFIG_DESCRIPTION",
> > + "help text is not indented 2 spaces more than the help keyword\n" . $herecurr);
> >
> > is IMO a bit oddly phrased and could/should test only
> > the first line after the help keyword and show the help
> > line using $hereprev.
> >
> > The problem with $herecurr is, that it always contains the first line of the Kconfig option.
> The loop which actually determines if the warning is to be displayed, leaves $herecurr and likewise $hereprev unaffected.
>
> So printing $hereprev would unfortunately not be any more helpful than $herecurr.

> Because $herecurr and $hereprev also contain the line number, among other things, I am not sure what would be the best way
> to address this.

There is a mechanism to create an output message block: get_stat_real
that could be used.