diff options
| author | Andy Whitcroft <apw@shadowen.org> | 2007-06-08 16:47:06 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-06-08 20:23:34 -0400 |
| commit | 00df344fd06fd6ac71d0665f1ce8cc6870e4f564 (patch) | |
| tree | 78090d7216bfbb32ca2fe630fff5a5445b539862 | |
| parent | c7909234993973692414901055dfbebbca21e73f (diff) | |
update checkpatch.pl to version 0.04
This version brings a some new tests, and a host of changes to fix
false positives, of particular note:
- check for and report #if 0
- extend checking of line lengths and spacing for .pl, .sh etc
- extends the pointer type checks to multiple levels
- updates printk handling to track newlines
- adds a wrapped patch detector
- drops the leading component of the filenames
- extends switch indent handling to switch statmentes rooted in
the context
- adds foo * bar single pointer checks
This version of checkpatch.pl can be found at the following URL:
http://www.shadowen.org/~apw/public/checkpatch/checkpatch.pl-0.04
Full Changelog:
Andy Whitcroft (16):
allow checking line lengths and spacing on other source files
clean up that whitespace
sanitise the input line standardising the content of quotes
clean up pointer type * and space checks
fix up the sanitiser so it maintains the line length
apply the printk facility checks only to the first printk in a set
switch/case indent checks may anchor in the context
add a wrapped patch detector
put the #ifdef in C file checks on ice
asm volatile is acceptable
check for and report #if 0
drop the leading component of the filename as patches are -p1
use the original line when reporting operator errors
correct spelling of Joel's name
Version: 0.04
add support for struct foo * bar checks
Geert Uytterhoeven (1):
Fix checkpatch.pl name in usage template
Randy Dunlap (1):
checkpatch: produce fewer lines of output
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Cc: Joel Schopp <jschopp@austin.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rwxr-xr-x | scripts/checkpatch.pl | 274 |
1 files changed, 193 insertions, 81 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 39339529b99b..aea90d30d229 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -1,14 +1,15 @@ | |||
| 1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) | 2 | # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit) |
| 3 | # (c) 2005, Joel Scohpp <jschopp@austin.ibm.com> (the ugly bit) | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
| 4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) | 4 | # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc) |
| 5 | # Licensed under the terms of the GNU GPL License version 2 | 5 | # Licensed under the terms of the GNU GPL License version 2 |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | 8 | ||
| 9 | my $P = $0; | 9 | my $P = $0; |
| 10 | $P =~ s@.*/@@g; | ||
| 10 | 11 | ||
| 11 | my $V = '0.03'; | 12 | my $V = '0.04'; |
| 12 | 13 | ||
| 13 | use Getopt::Long qw(:config no_auto_abbrev); | 14 | use Getopt::Long qw(:config no_auto_abbrev); |
| 14 | 15 | ||
| @@ -26,7 +27,7 @@ GetOptions( | |||
| 26 | my $exit = 0; | 27 | my $exit = 0; |
| 27 | 28 | ||
| 28 | if ($#ARGV < 0) { | 29 | if ($#ARGV < 0) { |
| 29 | print "usage: patchstylecheckemail.pl [options] patchfile\n"; | 30 | print "usage: $P [options] patchfile\n"; |
| 30 | print "version: $V\n"; | 31 | print "version: $V\n"; |
| 31 | print "options: -q => quiet\n"; | 32 | print "options: -q => quiet\n"; |
| 32 | print " --no-tree => run without a kernel tree\n"; | 33 | print " --no-tree => run without a kernel tree\n"; |
| @@ -59,15 +60,15 @@ if ($tree && -f $removal) { | |||
| 59 | } | 60 | } |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | my @lines = (); | 63 | my @rawlines = (); |
| 63 | while (<>) { | 64 | while (<>) { |
| 64 | chomp; | 65 | chomp; |
| 65 | push(@lines, $_); | 66 | push(@rawlines, $_); |
| 66 | if (eof(ARGV)) { | 67 | if (eof(ARGV)) { |
| 67 | if (!process($ARGV, @lines)) { | 68 | if (!process($ARGV, @rawlines)) { |
| 68 | $exit = 1; | 69 | $exit = 1; |
| 69 | } | 70 | } |
| 70 | @lines = (); | 71 | @rawlines = (); |
| 71 | } | 72 | } |
| 72 | } | 73 | } |
| 73 | 74 | ||
| @@ -118,24 +119,57 @@ sub line_stats { | |||
| 118 | return (length($line), length($white)); | 119 | return (length($line), length($white)); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 122 | sub sanitise_line { | ||
| 123 | my ($line) = @_; | ||
| 124 | |||
| 125 | my $res = ''; | ||
| 126 | my $l = ''; | ||
| 127 | |||
| 128 | my $quote = ''; | ||
| 129 | |||
| 130 | foreach my $c (split(//, $line)) { | ||
| 131 | if ($l ne "\\" && ($c eq "'" || $c eq '"')) { | ||
| 132 | if ($quote eq '') { | ||
| 133 | $quote = $c; | ||
| 134 | $res .= $c; | ||
| 135 | $l = $c; | ||
| 136 | next; | ||
| 137 | } elsif ($quote eq $c) { | ||
| 138 | $quote = ''; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | if ($quote && $c ne "\t") { | ||
| 142 | $res .= "X"; | ||
| 143 | } else { | ||
| 144 | $res .= $c; | ||
| 145 | } | ||
| 146 | |||
| 147 | $l = $c; | ||
| 148 | } | ||
| 149 | |||
| 150 | return $res; | ||
| 151 | } | ||
| 152 | |||
| 121 | sub ctx_block_get { | 153 | sub ctx_block_get { |
| 122 | my ($linenr, $remain, $outer) = @_; | 154 | my ($linenr, $remain, $outer) = @_; |
| 123 | my $line; | 155 | my $line; |
| 124 | my $start = $linenr - 1; | 156 | my $start = $linenr - 1; |
| 125 | my $end = $linenr - 1 + $remain; | ||
| 126 | my $blk = ''; | 157 | my $blk = ''; |
| 127 | my @o; | 158 | my @o; |
| 128 | my @c; | 159 | my @c; |
| 129 | my @res = (); | 160 | my @res = (); |
| 130 | 161 | ||
| 131 | for ($line = $start; $line < $end; $line++) { | 162 | for ($line = $start; $remain > 0; $line++) { |
| 132 | $blk .= $lines[$line]; | 163 | next if ($rawlines[$line] =~ /^-/); |
| 164 | $remain--; | ||
| 165 | |||
| 166 | $blk .= $rawlines[$line]; | ||
| 133 | 167 | ||
| 134 | @o = ($blk =~ /\{/g); | 168 | @o = ($blk =~ /\{/g); |
| 135 | @c = ($blk =~ /\}/g); | 169 | @c = ($blk =~ /\}/g); |
| 136 | 170 | ||
| 137 | if (!$outer || (scalar(@o) - scalar(@c)) == 1) { | 171 | if (!$outer || (scalar(@o) - scalar(@c)) == 1) { |
| 138 | push(@res, $lines[$line]); | 172 | push(@res, $rawlines[$line]); |
| 139 | } | 173 | } |
| 140 | 174 | ||
| 141 | last if (scalar(@o) == scalar(@c)); | 175 | last if (scalar(@o) == scalar(@c)); |
| @@ -158,7 +192,7 @@ sub ctx_locate_comment { | |||
| 158 | my ($first_line, $end_line) = @_; | 192 | my ($first_line, $end_line) = @_; |
| 159 | 193 | ||
| 160 | # Catch a comment on the end of the line itself. | 194 | # Catch a comment on the end of the line itself. |
| 161 | my ($current_comment) = ($lines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); | 195 | my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@); |
| 162 | return $current_comment if (defined $current_comment); | 196 | return $current_comment if (defined $current_comment); |
| 163 | 197 | ||
| 164 | # Look through the context and try and figure out if there is a | 198 | # Look through the context and try and figure out if there is a |
| @@ -166,8 +200,8 @@ sub ctx_locate_comment { | |||
| 166 | my $in_comment = 0; | 200 | my $in_comment = 0; |
| 167 | $current_comment = ''; | 201 | $current_comment = ''; |
| 168 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { | 202 | for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { |
| 169 | my $line = $lines[$linenr - 1]; | 203 | my $line = $rawlines[$linenr - 1]; |
| 170 | ##warn " $line\n"; | 204 | #warn " $line\n"; |
| 171 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { | 205 | if ($linenr == $first_line and $line =~ m@^.\s*\*@) { |
| 172 | $in_comment = 1; | 206 | $in_comment = 1; |
| 173 | } | 207 | } |
| @@ -190,7 +224,7 @@ sub ctx_has_comment { | |||
| 190 | my ($first_line, $end_line) = @_; | 224 | my ($first_line, $end_line) = @_; |
| 191 | my $cmt = ctx_locate_comment($first_line, $end_line); | 225 | my $cmt = ctx_locate_comment($first_line, $end_line); |
| 192 | 226 | ||
| 193 | ##print "LINE: $lines[$end_line - 1 ]\n"; | 227 | ##print "LINE: $rawlines[$end_line - 1 ]\n"; |
| 194 | ##print "CMMT: $cmt\n"; | 228 | ##print "CMMT: $cmt\n"; |
| 195 | 229 | ||
| 196 | return ($cmt ne ''); | 230 | return ($cmt ne ''); |
| @@ -205,10 +239,6 @@ sub cat_vet { | |||
| 205 | return $vet; | 239 | return $vet; |
| 206 | } | 240 | } |
| 207 | 241 | ||
| 208 | sub has_non_quoted { | ||
| 209 | return ($_[0] =~ m{$_[1]} and $_[0] !~ m{\".*$_[1].*\"}); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub process { | 242 | sub process { |
| 213 | my $filename = shift; | 243 | my $filename = shift; |
| 214 | my @lines = @_; | 244 | my @lines = @_; |
| @@ -240,6 +270,7 @@ sub process { | |||
| 240 | #extract the filename as it passes | 270 | #extract the filename as it passes |
| 241 | if ($line=~/^\+\+\+\s+(\S+)/) { | 271 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 242 | $realfile=$1; | 272 | $realfile=$1; |
| 273 | $realfile =~ s@^[^/]*/@@; | ||
| 243 | $in_comment = 0; | 274 | $in_comment = 0; |
| 244 | next; | 275 | next; |
| 245 | } | 276 | } |
| @@ -262,7 +293,6 @@ sub process { | |||
| 262 | # blank context lines so we need to count that too. | 293 | # blank context lines so we need to count that too. |
| 263 | if ($line =~ /^( |\+|$)/) { | 294 | if ($line =~ /^( |\+|$)/) { |
| 264 | $realline++; | 295 | $realline++; |
| 265 | $realcnt-- if ($realcnt != 0); | ||
| 266 | 296 | ||
| 267 | |||
