Skip to contentSkip to conversation

checkpatch: Line spacing tests and Kconfig help

PATCH Superseded Joe Perches 1 participant 5 messages Jun 23, 2014 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joe Perches

author maintainer
#0 lore raw

cover checkpatch: Line spacing tests and Kconfig help

Add some vertical spacing tests.
Quiet Kconfig help false positives.

Joe Perches (4):
checkpatch: Add test for blank lines after function/struct/union/enum
checkpatch: Add a multiple blank lines test
checkpatch: Change blank line after declaration type to "LINE_SPACING"
checkpatch: Quiet Kconfig help message checking

 scripts/checkpatch.pl | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
author maintainer
#1 lore raw

PATCH 1/4 checkpatch: Add test for blank lines after function/struct/union/enum

Add a --strict test asking for a blank line after
function/struct/union/enum declarations.

Allow exceptions for several attributes and macro uses.

---
 scripts/checkpatch.pl | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
scripts/checkpatch.pl +15 -0
index 538105a..4bb4218 100755
@@ -2291,6 +2291,21 @@ sub process {
 			     "networking block comments put the trailing */ on a separate line\n" . $herecurr);
 		}
 
+# check for missing blank lines after struct/union declarations
+# with exceptions for various attributes and macros
+		if ($prevline =~ /^[\+ ]};?\s*$/ &&
+		    !($line =~ /^\+\s*$/ ||
+		      $line =~ /^\+\s*EXPORT_SYMBOL/ ||
+		      $line =~ /^\+\s*MODULE_/i ||
+		      $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
+		      $line =~ /^\+[a-z_]*init/ ||
+		      $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
+		      $line =~ /^\+\s*DECLARE/ ||
+		      $line =~ /^\+\s*__setup/)) {
+			CHK("LINE_SPACING",
+			    "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev);
+		}
+
 # check for missing blank lines after declarations
 		if ($sline =~ /^\+\s+\S/ &&			#Not at char 1
 			# actual declarations
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
author maintainer
#2 lore raw

PATCH 2/4 checkpatch: Add a multiple blank lines test

In reply to Joe Perches

Multiple consecutive blank lines waste screen space. Emit a --strict only message with these blank lines.

---
 scripts/checkpatch.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/checkpatch.pl +11 -0
index 4bb4218..3d6dea6 100755
@@ -1642,6 +1642,8 @@ sub process {
 
 	my $non_utf8_charset = 0;
 
+	my $last_blank_line = 0;
+
 	our @report = ();
 	our $cnt_lines = 0;
 	our $cnt_error = 0;
@@ -2306,6 +2308,15 @@ sub process {
 			    "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev);
 		}
 
+# check for multiple consecutive blank lines
+		if ($prevline =~ /^[\+ ]\s*$/ &&
+		    $line =~ /^\+\s*$/ &&
+		    $last_blank_line != ($linenr - 1)) {
+			CHK("LINE_SPACING",
+			    "Please don't use multiple blank lines\n" . $hereprev);
+			$last_blank_line = $linenr;
+		}
+
 # check for missing blank lines after declarations
 		if ($sline =~ /^\+\s+\S/ &&			#Not at char 1
 			# actual declarations
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
author maintainer
#3 lore raw

PATCH 3/4 checkpatch: Change blank line after declaration type to "LINE_SPACING"

In reply to Joe Perches

Make it consistent with the other missing or multiple blank line tests.

---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 3d6dea6..9795844 100755
@@ -2351,7 +2351,7 @@ sub process {
 		      $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
 			# indentation of previous and current line are the same
 		    (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
-			WARN("SPACING",
+			WARN("LINE_SPACING",
 			     "Missing a blank line after declarations\n" . $hereprev);
 		}
 
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
author maintainer
#4 lore raw

PATCH 4/4 checkpatch: Quiet Kconfig help message checking

In reply to Joe Perches

Editing Kconfig dependencies can emit unnecessary messages about missing or too short help entries.

Only emit the message when adding help sections to Kconfig files.

---
 scripts/checkpatch.pl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +4 -3
index 9795844..2a7a32c 100755
@@ -2051,7 +2051,7 @@ sub process {
 # Only applies when adding the entry originally, after that we do not have
 # sufficient context to determine whether it is indeed long enough.
 		if ($realfile =~ /Kconfig/ &&
-		    $line =~ /.\s*config\s+/) {
+		    $line =~ /^\+\s*config\s+/) {
 			my $length = 0;
 			my $cnt = $realcnt;
 			my $ln = $linenr + 1;
@@ -2064,10 +2064,11 @@ sub process {
 				$is_end = $lines[$ln - 1] =~ /^\+/;
 
 				next if ($f =~ /^-/);
+				last if (!$file && $f =~ /^\@\@/);
 
-				if ($lines[$ln - 1] =~ /.\s*(?:bool|tristate)\s*\"/) {
+				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate)\s*\"/) {
 					$is_start = 1;
-				} elsif ($lines[$ln - 1] =~ /.\s*(?:---)?help(?:---)?$/) {
+				} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
 					$length = -1;
 				}
 
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty