checkpatch: update to version 0.23
cover checkpatch: update to version 0.23
This update brings a few small fixes to existing checks. Of note:
- restricts case/default checks to changed lines,
- suppresses perl errors for short patch hunks
- fixes comment handling for long hunks
Complete changelog below.
-apw
Andy Whitcroft (7):
checkpatch: case/default checks should only check changed lines
checkpatch: suppress errors triggered by short patch
checkpatch: handle comment/quote nesting correctly
checkpatch: check line endings in text format files
checkpatch: suspect indent count condition lines correctly
checkpatch: ensure we only apply checks to the lines within hunks
checkpatch: version: 0.23
scripts/checkpatch.pl | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-)
PATCH 1/7 checkpatch: case/default checks should only check changed lines
We should only be checking changes lines for the trailing statement check on case/default statements.
--- scripts/checkpatch.pl | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-)
scripts/checkpatch.pl +9 -8
@@ -1363,14 +1363,6 @@ sub process { ERROR("switch and case should be at the same indent\n$hereline$err"); } } - if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g && - $line !~ /\G(?: - (?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$| - \s*return\s+ - )/xg) - { - ERROR("trailing statements should be on next line\n" . $herecurr); - } # if/while/etc brace do not go on next line, unless defining a do while loop, # or if that brace on the next line is for something else
@@ -1986,6 +1978,15 @@ sub process { ERROR("trailing statements should be on next line\n" . $herecurr); } } +# case and default should not have general statements after them + if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g && + $line !~ /\G(?: + (?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$| + \s*return\s+ + )/xg) + { + ERROR("trailing statements should be on next line\n" . $herecurr); + } # Check for }<nl>else {, these must be at the same # indent level to be relevant to each other.
Signature · 1 line
1.6.0.rc1.258.g80295
PATCH 2/7 checkpatch: suppress errors triggered by short patch
In reply to Andy WhitcroftWhen the last hunk of a patch is short it will trigger errors from checkpatch:
Use of uninitialized value in pattern match (m//)
at /usr/local/bin/checkpatch.pl line 394.
Use of uninitialized value in concatenation (.) or string
at /usr/local/bin/checkpatch.pl line 397.
Use of uninitialized value in pattern match (m//)
Avoid touching beyond the last line. Reported by Julien Brunel.
--- scripts/checkpatch.pl | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +1 -0
@@ -408,6 +408,7 @@ sub ctx_statement_block { # context. if ($off >= $len) { for (; $remain > 0; $line++) { + last if (!defined $lines[$line]); next if ($lines[$line] =~ /^-/); $remain--; $loff = $len;
Signature · 1 line
1.6.0.rc1.258.g80295
PATCH 3/7 checkpatch: handle comment/quote nesting correctly
In reply to Andy WhitcroftEnsure that a close comment cannot incorrectly trigger in the middle of a string. Reported by Jaswinder Singh.
--- scripts/checkpatch.pl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
@@ -335,7 +335,7 @@ sub sanitise_line { $off++; next; } - if (substr($line, $off, 2) eq '*/') { + if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') { $sanitise_quote = ''; substr($res, $off, 2, "$;$;"); $off++;
Signature · 1 line
1.6.0.rc1.258.g80295
Re: [PATCH 3/7] checkpatch: handle comment/quote nesting correctly
Quoted 5 lines · Andy Whitcroft
Ensure that a close comment cannot incorrectly trigger in the middle of a string. Reported by Jaswinder Singh.
Signed-off-by Andy Whitcroft <[email protected]>Cc Jaswinder Singh <[email protected]>
Acked by Jaswinder Singh <[email protected]>
Thank you,
Jaswinder Singh.
PATCH 4/7 checkpatch: check line endings in text format files
In reply to Andy WhitcroftFirmware may be included in the kernel as .ihex files. These are inherantly text, but not source. The line ending checks are applicable to these kinds of file, allow just these checks to apply to all files.
--- scripts/checkpatch.pl | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +4 -3
@@ -1241,9 +1241,6 @@ sub process { #ignore lines being removed if ($line=~/^-/) {next;} -# check we are in a valid source file if not then ignore this hunk - next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); - #trailing whitespace if ($line =~ /^\+.*\015/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n";
@@ -1253,6 +1250,10 @@ sub process { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; ERROR("trailing whitespace\n" . $herevet); } + +# check we are in a valid source file if not then ignore this hunk + next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); + #80 column limit if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
Signature · 1 line
1.6.0.rc1.258.g80295
PATCH 5/7 checkpatch: suspect indent count condition lines correctly
In reply to Andy WhitcroftCorrect calculation of the number of lines of condition where we have suspect indent.
--- scripts/checkpatch.pl | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +2 -1
@@ -1417,7 +1417,8 @@ sub process { $s =~ s/\n./\n/gs; # Find out how long the conditional actually is. - my $cond_lines = 0 + $c =~ /\n/gs; + my @newlines = ($c =~ /\n/gs); + my $cond_lines = 1 + $#newlines; # We want to check the first line inside the block # starting at the end of the conditional, so remove:
Signature · 1 line
1.6.0.rc1.258.g80295
PATCH 6/7 checkpatch: ensure we only apply checks to the lines within hunks
In reply to Andy WhitcroftWe should only apply source checks to lines within hunks. Checks which are anchored in the context may falsly trigger in the commentory. Ensure they only match within valid hunk lines.
--- scripts/checkpatch.pl | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
@@ -1128,6 +1128,7 @@ sub process { $linenr++; my $rawline = $rawlines[$linenr - 1]; + my $hunk_line = ($realcnt != 0); #extract the line range in the file after the patch is applied if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
@@ -1238,8 +1239,8 @@ sub process { ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); } -#ignore lines being removed - if ($line=~/^-/) {next;} +# ignore non-hunk lines and lines being removed + next if (!$hunk_line || $line =~ /^-/); #trailing whitespace if ($line =~ /^\+.*\015/) {
Signature · 1 line
1.6.0.rc1.258.g80295
PATCH 7/7 checkpatch: version: 0.23
In reply to Andy Whitcroft--- scripts/checkpatch.pl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +1 -1
@@ -9,7 +9,7 @@ use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.22'; +my $V = '0.23'; use Getopt::Long qw(:config no_auto_abbrev);
Signature · 1 line
1.6.0.rc1.258.g80295