linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] checkpatch: update kconfig parsing
@ 2020-12-14 10:22 Nicolai Fischer
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-14 10:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: joe, apw, johannes.czekay, linux-kernel

This series updates the parsing of Kconfig files within checkpatch.pl
to the current state, as discussed previously.


Nicolai Fischer (2):
  checkpatch: kconfig: replace '---help---' with 'help'
  checkpatch: kconfig: add missing types to regex

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

-- 
2.28.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 0/4] checkpatch: update kconfig parsing
  2020-12-14 10:22 [PATCH 0/2] checkpatch: update kconfig parsing Nicolai Fischer
@ 2020-12-26 14:05 ` Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 1/4] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
                     ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-26 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, joe, akpm

This series updates the parsing of Kconfig files within checkpatch.pl
to the current state, as discussed previously.

The second iteration contains two more patches.
Patch 3 adds a new warning regarding the indentation as discussed.
Patch 4 aims to clarify the existing warning.

Nicolai Fischer (4):
  checkpatch: kconfig: replace '---help---' with 'help'
  checkpatch: kconfig: add missing types to regex
  checkpatch: kconfig: enforce help text indentation
  checkpatch: kconfig: clarify warning for paragraph length

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

-- 
2.29.2




^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/4] checkpatch: kconfig: replace '---help---' with 'help'
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
@ 2020-12-26 14:05   ` Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 2/4] checkpatch: kconfig: add missing types to regex Nicolai Fischer
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-26 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, joe, akpm

All '---help---' lines have been replaced by just 'help'.
Therefore it is no longer necessary to include '---' in the regex.

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
Acked-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 00085308ed9d..f6fd811c54a0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3323,7 +3323,7 @@ sub process {
 
 				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
 					$is_start = 1;
-				} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
+				} elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
 					$length = -1;
 				}
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/4] checkpatch: kconfig: add missing types to regex
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 1/4] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
@ 2020-12-26 14:05   ` Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-26 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, joe, akpm

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

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f6fd811c54a0..c86a971a3205 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.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 1/4] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
  2020-12-26 14:05   ` [PATCH v2 2/4] checkpatch: kconfig: add missing types to regex Nicolai Fischer
@ 2020-12-26 14:05   ` Nicolai Fischer
  2020-12-26 15:50     ` Joe Perches
  2020-12-26 14:05   ` [PATCH v2 4/4] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
  4 siblings, 1 reply; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-26 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, joe, akpm

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

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c86a971a3205..aa2205ee9ab8 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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 4/4] checkpatch: kconfig: clarify warning for paragraph length
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
                     ` (2 preceding siblings ...)
  2020-12-26 14:05   ` [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
@ 2020-12-26 14:05   ` Nicolai Fischer
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2020-12-26 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, joe, akpm

Currently checkpatch displays a warning if it detects a help text
of a Kconfig option which is too short. However the warning does
not contain any further information.
This adds the expected and currently detected number of lines
to the warning, which makes it more obvious why checkpatch
is warning.

Furthermore this makes it easier to quickly identify false
positives, e.g. when a help message contains a Kconfig keyword
and falsely triggers checkpatch to stop counting lines,
it will be more apparent, because the user can see how many lines
they wrote and how many of those were counted correctly.

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index aa2205ee9ab8..bc363933e0aa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3356,7 +3356,7 @@ sub process {
 			}
 			if ($is_start && $is_end && $length < $min_conf_desc_length) {
 				WARN("CONFIG_DESCRIPTION",
-				     "please write a paragraph that describes the config symbol fully\n" . $herecurr);
+				     "please write a paragraph ($length/$min_conf_desc_length lines) that describes the config symbol fully\n" . $herecurr);
 			}
 			if ($is_start && $is_end && defined $help_stat_real) {
 				WARN("CONFIG_DESCRIPTION",
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation
  2020-12-26 14:05   ` [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
@ 2020-12-26 15:50     ` Joe Perches
  0 siblings, 0 replies; 16+ messages in thread
From: Joe Perches @ 2020-12-26 15:50 UTC (permalink / raw)
  To: Nicolai Fischer, linux-kernel; +Cc: apw, johannes.czekay, linux-kernel, akpm

On Sat, 2020-12-26 at 15:05 +0100, Nicolai Fischer wrote:
> Adds a new warning in case the indentation level of the
> first line of a Kconfig help message is not two spaces
> higher than the keyword itself.
> Blank lines between the message and the help keyword
> are ignored.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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 doesn't work if the indent is more than 2 spaces.

$ cat Kconfigtest
menuconfig FOO
	bool "Enable foo" if EXPERT
	default y
	help
	   Line 1.
	   Line 2.
	   Line 3.
	   Line 4.

$ ./scripts/checkpatch.pl -f Kconfigtest
total: 0 errors, 0 warnings, 10 lines checked

Kconfigtest has no obvious style problems and is ready for submission.

Also, it may be useful to test that the indent after a block
uses a single tab more than the block start.

Look at the first block of block/Kconfig:

The indentation of bool and help uses 7 spaces but the indentation
of the help text uses a tab then 1 space.

It'd be useful to emit a warning for that.

menuconfig BLOCK
       bool "Enable the block layer" if EXPERT
       default y
       select SBITMAP
       select SRCU
       help
	 Provide block layer support for the kernel.

	 Disable this option to remove the block layer support from the
	 kernel. This may be useful for embedded devices.

	 If this option is disabled:

	   - block device files will become unusable
	   - some filesystems (such as ext3) will become unavailable.

	 Also, SCSI character devices and USB storage will be disabled since
	 they make use of various block layer definitions and facilities.

	 Say Y here unless you know you really don't want to mount disks and
	 suchlike.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 0/5] update kconfig parsing
  2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
                     ` (3 preceding siblings ...)
  2020-12-26 14:05   ` [PATCH v2 4/4] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
@ 2021-01-03  7:50   ` Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 1/5] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
                       ` (4 more replies)
  4 siblings, 5 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

This series updates the parsing of Kconfig files within checkpatch.pl
to the current state, as discussed previously.

Third iteration fixes patch 3 and adds one new patch.
Patch 5 adds a new waring regarding the indentation of a Kconfig block


Nicolai Fischer (5):
  checkpatch: kconfig: replace '---help---' with 'help'
  checkpatch: kconfig: add missing types to regex
  checkpatch: kconfig: enforce help text indentation
  checkpatch: kconfig: clarify warning for paragraph length
  checkpatch: kconfig: enforce block indentation

 scripts/checkpatch.pl | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

-- 
2.29.2




^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 1/5] checkpatch: kconfig: replace '---help---' with 'help'
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
@ 2021-01-03  7:50     ` Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 2/5] checkpatch: kconfig: add missing types to regex Nicolai Fischer
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

All '---help---' lines have been replaced by just 'help'.
Therefore it is no longer necessary to include '---' in the regex.

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
Acked-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 00085308ed9d..f6fd811c54a0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3323,7 +3323,7 @@ sub process {
 
 				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
 					$is_start = 1;
-				} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
+				} elsif ($lines[$ln - 1] =~ /^\+\s*help$/) {
 					$length = -1;
 				}
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 2/5] checkpatch: kconfig: add missing types to regex
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 1/5] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
@ 2021-01-03  7:50     ` Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

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

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f6fd811c54a0..c86a971a3205 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.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 1/5] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 2/5] checkpatch: kconfig: add missing types to regex Nicolai Fischer
@ 2021-01-03  7:50     ` Nicolai Fischer
  2021-01-04 22:09       ` Joe Perches
  2021-01-03  7:50     ` [PATCH v3 4/5] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 5/5] checkpatch: kconfig: enforce block indentation Nicolai Fischer
  4 siblings, 1 reply; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

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 <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 4/5] checkpatch: kconfig: clarify warning for paragraph length
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
                       ` (2 preceding siblings ...)
  2021-01-03  7:50     ` [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
@ 2021-01-03  7:50     ` Nicolai Fischer
  2021-01-03  7:50     ` [PATCH v3 5/5] checkpatch: kconfig: enforce block indentation Nicolai Fischer
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

Currently checkpatch displays a warning if it detects a help text
of a Kconfig option which is too short. However the warning does
not contain any further information.
This adds the expected and currently detected number of lines
to the warning, which makes it more obvious why checkpatch
is warning.

Furthermore this makes it easier to quickly identify false
positives, e.g. when a help message contains a Kconfig keyword
and falsely triggers checkpatch to stop counting lines,
it will be more apparent, because the user can see how many lines
they wrote and how many of those were counted correctly.

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 209880810aaa..805b5870803f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3356,7 +3356,7 @@ sub process {
 			}
 			if ($is_start && $is_end && $length < $min_conf_desc_length) {
 				WARN("CONFIG_DESCRIPTION",
-				     "please write a paragraph that describes the config symbol fully\n" . $herecurr);
+				     "please write a paragraph ($length/$min_conf_desc_length lines) that describes the config symbol fully\n" . $herecurr);
 			}
 			if ($is_start && $is_end && defined $help_stat_real) {
 				WARN("CONFIG_DESCRIPTION",
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 5/5] checkpatch: kconfig: enforce block indentation
  2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
                       ` (3 preceding siblings ...)
  2021-01-03  7:50     ` [PATCH v3 4/5] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
@ 2021-01-03  7:50     ` Nicolai Fischer
  4 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-03  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: joe, apw, akpm, nicolai.fischer, johannes.czekay, linux-kernel

Adds a new warning to checkpatch in case a new Kconfig block
is not indented one sigle tab more than the keyword which
starts it.

Co-developed-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
---
 scripts/checkpatch.pl | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 805b5870803f..8a82ea5c2eb3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3306,7 +3306,8 @@ sub process {
 		    # 'choice' is usually the last thing on the line (though
 		    # Kconfig supports named choices), so use a word boundary
 		    # (\b) rather than a whitespace character (\s)
-		    $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
+		    $line =~ /^\+(\s*)(?:config|menuconfig|choice)\b/) {
+			my $base_indent = $1;
 			my $length = 0;
 			my $cnt = $realcnt;
 			my $ln = $linenr + 1;
@@ -3315,6 +3316,7 @@ sub process {
 			my $is_end = 0;
 			my $help_indent;
 			my $help_stat_real;
+			my $block_stat_real;
 			for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
 				$f = $lines[$ln - 1];
 				$cnt-- if ($lines[$ln - 1] !~ /^-/);
@@ -3323,7 +3325,10 @@ sub process {
 				next if ($f =~ /^-/);
 				last if (!$file && $f =~ /^\@\@/);
 
-				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|int|hex|string|prompt)\s*(?:["'].*)?$/) {
+				if ($lines[$ln - 1] =~ /^\+(\s*)(?:bool|tristate|int|hex|string|prompt)\s*(?:["'].*)?$/) {
+					if ($1 !~ /^$base_indent\t$/) {
+						$block_stat_real = get_stat_real($linenr, $ln);
+					}
 					$is_start = 1;
 				} elsif ($lines[$ln - 1] =~ /^\+(\s*)help$/) {
 					$help_indent = $1;
@@ -3358,6 +3363,10 @@ sub process {
 				WARN("CONFIG_DESCRIPTION",
 				     "please write a paragraph ($length/$min_conf_desc_length lines) that describes the config symbol fully\n" . $herecurr);
 			}
+			if ($is_start && $is_end && defined $block_stat_real) {
+				WARN("CONFIG_DESCRIPTION",
+				     "please indent the block a single tab more than the start\n" . "$here\n$block_stat_real\n");
+			}
 			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");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation
  2021-01-03  7:50     ` [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
@ 2021-01-04 22:09       ` Joe Perches
  2021-01-05  8:57         ` Joe Perches
  0 siblings, 1 reply; 16+ messages in thread
From: Joe Perches @ 2021-01-04 22:09 UTC (permalink / raw)
  To: Nicolai Fischer, linux-kernel; +Cc: apw, akpm, johannes.czekay, linux-kernel

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 <johannes.czekay@fau.de>
> Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
> Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
> ---
> 
> Now matches indentation of two or more spaces, instead of exactly two.

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



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation
  2021-01-04 22:09       ` Joe Perches
@ 2021-01-05  8:57         ` Joe Perches
  2021-01-05 15:49           ` Nicolai Fischer
  0 siblings, 1 reply; 16+ messages in thread
From: Joe Perches @ 2021-01-05  8:57 UTC (permalink / raw)
  To: Nicolai Fischer, linux-kernel; +Cc: apw, akpm, johannes.czekay, linux-kernel

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 <johannes.czekay@fau.de>
> > Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
> > Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
> > ---
> > 
> > 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



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation
  2021-01-05  8:57         ` Joe Perches
@ 2021-01-05 15:49           ` Nicolai Fischer
  0 siblings, 0 replies; 16+ messages in thread
From: Nicolai Fischer @ 2021-01-05 15:49 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: apw, akpm, johannes.czekay, linux-kernel



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 <johannes.czekay@fau.de>
>>> Signed-off-by: Johannes Czekay <johannes.czekay@fau.de>
>>> Signed-off-by: Nicolai Fischer <nicolai.fischer@fau.de>
>>> ---
>>>
>>> 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
> 
> 



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-01-05 15:50 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 10:22 [PATCH 0/2] checkpatch: update kconfig parsing Nicolai Fischer
2020-12-26 14:05 ` [PATCH v2 0/4] " Nicolai Fischer
2020-12-26 14:05   ` [PATCH v2 1/4] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
2020-12-26 14:05   ` [PATCH v2 2/4] checkpatch: kconfig: add missing types to regex Nicolai Fischer
2020-12-26 14:05   ` [PATCH v2 3/4] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
2020-12-26 15:50     ` Joe Perches
2020-12-26 14:05   ` [PATCH v2 4/4] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
2021-01-03  7:50   ` [PATCH v3 0/5] update kconfig parsing Nicolai Fischer
2021-01-03  7:50     ` [PATCH v3 1/5] checkpatch: kconfig: replace '---help---' with 'help' Nicolai Fischer
2021-01-03  7:50     ` [PATCH v3 2/5] checkpatch: kconfig: add missing types to regex Nicolai Fischer
2021-01-03  7:50     ` [PATCH v3 3/5] checkpatch: kconfig: enforce help text indentation Nicolai Fischer
2021-01-04 22:09       ` Joe Perches
2021-01-05  8:57         ` Joe Perches
2021-01-05 15:49           ` Nicolai Fischer
2021-01-03  7:50     ` [PATCH v3 4/5] checkpatch: kconfig: clarify warning for paragraph length Nicolai Fischer
2021-01-03  7:50     ` [PATCH v3 5/5] checkpatch: kconfig: enforce block indentation Nicolai Fischer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).