diff options
| author | Joe Perches <joe@perches.com> | 2014-08-06 19:11:03 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 21:01:28 -0400 |
| commit | 194f66fc9567367b3fa2dcbc1b87b091330ef186 (patch) | |
| tree | 27bd72733caf8ea7af51659780d461ddeba79b1a /scripts | |
| parent | c00df19a5026f2cb08f1770dcc29226512f4d099 (diff) | |
checkpatch: add an index variable for fixed lines
Make the fix code a bit easier to read.
This should also start to allow an easier mechanism to insert/delete
lines eventually too.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fc72d64cd2d4..f905d7b50530 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -583,6 +583,8 @@ $chk_signoff = 0 if ($file); | |||
| 583 | my @rawlines = (); | 583 | my @rawlines = (); |
| 584 | my @lines = (); | 584 | my @lines = (); |
| 585 | my @fixed = (); | 585 | my @fixed = (); |
| 586 | my $fixlinenr = -1; | ||
| 587 | |||
| 586 | my $vname; | 588 | my $vname; |
| 587 | for my $filename (@ARGV) { | 589 | for my $filename (@ARGV) { |
| 588 | my $FILE; | 590 | my $FILE; |
| @@ -611,6 +613,7 @@ for my $filename (@ARGV) { | |||
| 611 | @rawlines = (); | 613 | @rawlines = (); |
| 612 | @lines = (); | 614 | @lines = (); |
| 613 | @fixed = (); | 615 | @fixed = (); |
| 616 | $fixlinenr = -1; | ||
| 614 | } | 617 | } |
| 615 | 618 | ||
| 616 | exit($exit); | 619 | exit($exit); |
| @@ -1801,8 +1804,10 @@ sub process { | |||
| 1801 | 1804 | ||
| 1802 | $realcnt = 0; | 1805 | $realcnt = 0; |
| 1803 | $linenr = 0; | 1806 | $linenr = 0; |
| 1807 | $fixlinenr = -1; | ||
| 1804 | foreach my $line (@lines) { | 1808 | foreach my $line (@lines) { |
| 1805 | $linenr++; | 1809 | $linenr++; |
| 1810 | $fixlinenr++; | ||
| 1806 | my $sline = $line; #copy of $line | 1811 | my $sline = $line; #copy of $line |
| 1807 | $sline =~ s/$;/ /g; #with comments as spaces | 1812 | $sline =~ s/$;/ /g; #with comments as spaces |
| 1808 | 1813 | ||
| @@ -1933,7 +1938,7 @@ sub process { | |||
| 1933 | if (WARN("BAD_SIGN_OFF", | 1938 | if (WARN("BAD_SIGN_OFF", |
| 1934 | "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) && | 1939 | "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) && |
| 1935 | $fix) { | 1940 | $fix) { |
| 1936 | $fixed[$linenr - 1] = | 1941 | $fixed[$fixlinenr] = |
| 1937 | "$ucfirst_sign_off $email"; | 1942 | "$ucfirst_sign_off $email"; |
| 1938 | } | 1943 | } |
| 1939 | } | 1944 | } |
| @@ -1941,7 +1946,7 @@ sub process { | |||
| 1941 | if (WARN("BAD_SIGN_OFF", | 1946 | if (WARN("BAD_SIGN_OFF", |
| 1942 | "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) && | 1947 | "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) && |
| 1943 | $fix) { | 1948 | $fix) { |
| 1944 | $fixed[$linenr - 1] = | 1949 | $fixed[$fixlinenr] = |
| 1945 | "$ucfirst_sign_off $email"; | 1950 | "$ucfirst_sign_off $email"; |
| 1946 | } | 1951 | } |
| 1947 | 1952 | ||
| @@ -1950,7 +1955,7 @@ sub process { | |||
| 1950 | if (WARN("BAD_SIGN_OFF", | 1955 | if (WARN("BAD_SIGN_OFF", |
| 1951 | "Use a single space after $ucfirst_sign_off\n" . $herecurr) && | 1956 | "Use a single space after $ucfirst_sign_off\n" . $herecurr) && |
| 1952 | $fix) { | 1957 | $fix) { |
| 1953 | $fixed[$linenr - 1] = | 1958 | $fixed[$fixlinenr] = |
| 1954 | "$ucfirst_sign_off $email"; | 1959 | "$ucfirst_sign_off $email"; |
| 1955 | } | 1960 | } |
| 1956 | } | 1961 | } |
| @@ -2089,14 +2094,14 @@ sub process { | |||
| 2089 | if (ERROR("DOS_LINE_ENDINGS", | 2094 | if (ERROR("DOS_LINE_ENDINGS", |
| 2090 | "DOS line endings\n" . $herevet) && | 2095 | "DOS line endings\n" . $herevet) && |
| 2091 | $fix) { | 2096 | $fix) { |
| 2092 | $fixed[$linenr - 1] =~ s/[\s\015]+$//; | 2097 | $fixed[$fixlinenr] =~ s/[\s\015]+$//; |
| 2093 | } | 2098 | } |
| 2094 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { | 2099 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { |
| 2095 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 2100 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
| 2096 | if (ERROR("TRAILING_WHITESPACE", | 2101 | if (ERROR("TRAILING_WHITESPACE", |
| 2097 | "trailing whitespace\n" . $herevet) && | 2102 | "trailing whitespace\n" . $herevet) && |
| 2098 | $fix) { | 2103 | $fix) { |
| 2099 | $fixed[$linenr - 1] =~ s/\s+$//; | 2104 | $fixed[$fixlinenr] =~ s/\s+$//; |
| 2100 | } | 2105 | } |
| 2101 | 2106 | ||
| 2102 | $rpt_cleaners = 1; | 2107 | $rpt_cleaners = 1; |
| @@ -2235,7 +2240,7 @@ sub process { | |||
| 2235 | if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", | 2240 | if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", |
| 2236 | "unnecessary whitespace before a quoted newline\n" . $herecurr) && | 2241 | "unnecessary whitespace before a quoted newline\n" . $herecurr) && |
| 2237 | $fix) { | 2242 | $fix) { |
| 2238 | $fixed[$linenr - 1] =~ s/^(\+.*\".*)\s+\\n/$1\\n/; | 2243 | $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/; |
| 2239 | } | 2244 | } |
| 2240 | 2245 | ||
| 2241 | } | 2246 | } |
| @@ -2272,7 +2277,7 @@ sub process { | |||
| 2272 | if (ERROR("CODE_INDENT", | 2277 | if (ERROR("CODE_INDENT", |
| 2273 | "code indent should use tabs where possible\n" . $herevet) && | 2278 | "code indent should use tabs where possible\n" . $herevet) && |
| 2274 | $fix) { | 2279 | $fix) { |
| 2275 | $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; | 2280 | $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; |
| 2276 | } | 2281 | } |
| 2277 | } | 2282 | } |
| 2278 | 2283 | ||
| @@ -2282,9 +2287,9 @@ sub process { | |||
| 2282 | if (WARN("SPACE_BEFORE_TAB", | 2287 | if (WARN("SPACE_BEFORE_TAB", |
| 2283 | "please, no space before tabs\n" . $herevet) && | 2288 | "please, no space before tabs\n" . $herevet) && |
| 2284 | $fix) { | 2289 | $fix) { |
| 2285 | while ($fixed[$linenr - 1] =~ | 2290 | while ($fixed[$fixlinenr] =~ |
| 2286 | s/(^\+.*) {8,8}+\t/$1\t\t/) {} | 2291 | s/(^\+.*) {8,8}+\t/$1\t\t/) {} |
| 2287 | while ($fixed[$linenr - 1] =~ | 2292 | while ($fixed[$fixlinenr] =~ |
| 2288 | s/(^\+.*) +\t/$1\t/) {} | 2293 | s/(^\+.*) +\t/$1\t/) {} |
| 2289 | } | 2294 | } |
| 2290 | } | 2295 | } |
| @@ -2318,7 +2323,7 @@ sub process { | |||
| 2318 | if (CHK("PARENTHESIS_ALIGNMENT", | 2323 | if (CHK("PARENTHESIS_ALIGNMENT", |
| 2319 | "Alignment should match open parenthesis\n" . $hereprev) && | 2324 | "Alignment should match open parenthesis\n" . $hereprev) && |
| 2320 | $fix && $line =~ /^\+/) { | 2325 | $fix && $line =~ /^\+/) { |
| 2321 | $fixed[$linenr - 1] =~ | 2326 | $fixed[$fixlinenr] =~ |
| 2322 | s/^\+[ \t]*/\+$goodtabindent/; | 2327 | s/^\+[ \t]*/\+$goodtabindent/; |
| 2323 | } | 2328 | } |
| 2324 | } | 2329 | } |
| @@ -2329,7 +2334,7 @@ sub process { | |||
| 2329 | if (CHK("SPACING", | 2334 | if (CHK("SPACING", |
| 2330 | "No space is necessary after a cast\n" . $herecurr) && | 2335 | "No space is necessary after a cast\n" . $herecurr) && |
| 2331 | $fix) { | 2336 | $fix) { |
| 2332 | $fixed[$linenr - 1] =~ | 2337 | $fixed[$fixlinenr] =~ |
| 2333 | s/(\(\s*$Type\s*\))[ \t]+/$1/; | 2338 | s/(\(\s*$Type\s*\))[ \t]+/$1/; |
| 2334 | } | 2339 | } |
| 2335 | } | 2340 | } |
| @@ -2433,7 +2438,7 @@ sub process { | |||
| 2433 | if (WARN("LEADING_SPACE", | 2438 | if (WARN("LEADING_SPACE", |
| 2434 | "please, no spaces at the start of a line\n" . $herevet) && | 2439 | "please, no spaces at the start of a line\n" . $herevet) && |
| 2435 | $fix) { | 2440 | $fix) { |
| 2436 | $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; | 2441 | $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; |
| 2437 | } | 2442 | } |
| 2438 | } | 2443 | } |
| 2439 | 2444 | ||
| @@ -2798,10 +2803,10 @@ sub process { | |||
| 2798 | if (ERROR("C99_COMMENTS", | 2803 | if (ERROR("C99_COMMENTS", |
| 2799 | "do not use C99 // comments\n" . $herecurr) && | 2804 | "do not use C99 // comments\n" . $herecurr) && |
| 2800 | $fix) { | 2805 | $fix) { |
| 2801 | my $line = $fixed[$linenr - 1]; | 2806 | my $line = $fixed[$fixlinenr]; |
| 2802 | if ($line =~ /\/\/(.*)$/) { | 2807 | if ($line =~ /\/\/(.*)$/) { |
| 2803 | my $comment = trim($1); | 2808 | my $comment = trim($1); |
| 2804 | $fixed[$linenr - 1] =~ s@\/\/(.*)$@/\* $comment \*/@; | 2809 | $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@; |
| 2805 | } | 2810 | } |
| 2806 | } | 2811 | } |
| 2807 | } | 2812 | } |
| @@ -2860,7 +2865,7 @@ sub process { | |||
| 2860 | "do not initialise globals to 0 or NULL\n" . | 2865 | "do not |
