diff options
author | Joe Perches <joe@perches.com> | 2013-09-11 17:23:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 18:58:45 -0400 |
commit | 91bfe4843dff4426ca3a0dd1dab8454c1534022d (patch) | |
tree | 45bd3d4f0ce6d7b8f59a956ce5728b6ff9ed871d | |
parent | 61135e966367eda5056504ffd2f7518eaf77e25b (diff) |
checkpatch: add --types option to report only specific message types
Add a --types convenience option to show only specific message types.
Combined with the --fix option, this can produce specific suggested
formatting patches to files.
Signed-off-by: Joe Perches <joe@perches.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 | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9185883f5885..3ba2db637384 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -31,8 +31,10 @@ my $show_types = 0; | |||
31 | my $fix = 0; | 31 | my $fix = 0; |
32 | my $root; | 32 | my $root; |
33 | my %debug; | 33 | my %debug; |
34 | my %ignore_type = (); | ||
35 | my %camelcase = (); | 34 | my %camelcase = (); |
35 | my %use_type = (); | ||
36 | my @use = (); | ||
37 | my %ignore_type = (); | ||
36 | my @ignore = (); | 38 | my @ignore = (); |
37 | my $help = 0; | 39 | my $help = 0; |
38 | my $configuration_file = ".checkpatch.conf"; | 40 | my $configuration_file = ".checkpatch.conf"; |
@@ -56,6 +58,7 @@ Options: | |||
56 | --terse one line per report | 58 | --terse one line per report |
57 | -f, --file treat FILE as regular source file | 59 | -f, --file treat FILE as regular source file |
58 | --subjective, --strict enable more subjective tests | 60 | --subjective, --strict enable more subjective tests |
61 | --types TYPE(,TYPE2...) show only these comma separated message types | ||
59 | --ignore TYPE(,TYPE2...) ignore various comma separated message types | 62 | --ignore TYPE(,TYPE2...) ignore various comma separated message types |
60 | --max-line-length=n set the maximum line length, if exceeded, warn | 63 | --max-line-length=n set the maximum line length, if exceeded, warn |
61 | --show-types show the message "types" in the output | 64 | --show-types show the message "types" in the output |
@@ -120,6 +123,7 @@ GetOptions( | |||
120 | 'subjective!' => \$check, | 123 | 'subjective!' => \$check, |
121 | 'strict!' => \$check, | 124 | 'strict!' => \$check, |
122 | 'ignore=s' => \@ignore, | 125 | 'ignore=s' => \@ignore, |
126 | 'types=s' => \@use, | ||
123 | 'show-types!' => \$show_types, | 127 | 'show-types!' => \$show_types, |
124 | 'max-line-length=i' => \$max_line_length, | 128 | 'max-line-length=i' => \$max_line_length, |
125 | 'root=s' => \$root, | 129 | 'root=s' => \$root, |
@@ -150,19 +154,38 @@ if ($#ARGV < 0) { | |||
150 | exit(1); | 154 | exit(1); |
151 | } | 155 | } |
152 | 156 | ||
153 | @ignore = split(/,/, join(',',@ignore)); | 157 | sub hash_save_array_words { |
154 | foreach my $word (@ignore) { | 158 | my ($hashRef, $arrayRef) = @_; |
155 | $word =~ s/\s*\n?$//g; | 159 | |
156 | $word =~ s/^\s*//g; | 160 | my @array = split(/,/, join(',', @$arrayRef)); |
157 | $word =~ s/\s+/ /g; | 161 | foreach my $word (@array) { |
158 | $word =~ tr/[a-z]/[A-Z]/; | 162 | $word =~ s/\s*\n?$//g; |
163 | $word =~ s/^\s*//g; | ||
164 | $word =~ s/\s+/ /g; | ||
165 | $word =~ tr/[a-z]/[A-Z]/; | ||
166 | |||
167 | next if ($word =~ m/^\s*#/); | ||
168 | next if ($word =~ m/^\s*$/); | ||
169 | |||
170 | $hashRef->{$word}++; | ||
171 | } | ||
172 | } | ||
159 | 173 | ||
160 | next if ($word =~ m/^\s*#/); | 174 | sub hash_show_words { |
161 | next if ($word =~ m/^\s*$/); | 175 | my ($hashRef, $prefix) = @_; |
162 | 176 | ||
163 | $ignore_type{$word}++; | 177 | if ($quiet == 0 && keys $hashRef) { |
178 | print "NOTE: $prefix message types:"; | ||
179 | foreach my $word (sort keys $hashRef) { | ||
180 | print " $word"; | ||
181 | } | ||
182 | print "\n\n"; | ||
183 | } | ||
164 | } | 184 | } |
165 | 185 | ||
186 | hash_save_array_words(\%ignore_type, \@ignore); | ||
187 | hash_save_array_words(\%use_type, \@use); | ||
188 | |||
166 | my $dbg_values = 0; | 189 | my $dbg_values = 0; |
167 | my $dbg_possible = 0; | 190 | my $dbg_possible = 0; |
168 | my $dbg_type = 0; | 191 | my $dbg_type = 0; |
@@ -1367,7 +1390,9 @@ sub possible { | |||
1367 | my $prefix = ''; | 1390 | my $prefix = ''; |
1368 | 1391 | ||
1369 | sub show_type { | 1392 | sub show_type { |
1370 | return !defined $ignore_type{$_[0]}; | 1393 | return defined $use_type{$_[0]} if (scalar keys %use_type > 0); |
1394 | |||
1395 | return !defined $ignore_type{$_[0]}; | ||
1371 | } | 1396 | } |
1372 | 1397 | ||
1373 | sub report { | 1398 | sub report { |
@@ -4190,13 +4215,8 @@ sub process { | |||
4190 | } | 4215 | } |
4191 | } | 4216 | } |
4192 | 4217 | ||
4193 | if ($quiet == 0 && keys %ignore_type) { | 4218 | hash_show_words(\%use_type, "Used"); |
4194 | print "NOTE: Ignored message types:"; | 4219 | hash_show_words(\%ignore_type, "Ignored"); |
4195 | foreach my $ignore (sort keys %ignore_type) { | ||
4196 | print " $ignore"; | ||
4197 | } | ||
4198 | print "\n\n"; | ||
4199 | } | ||
4200 | 4220 | ||
4201 | if ($clean == 0 && $fix && "@rawlines" ne "@fixed") { | 4221 | if ($clean == 0 && $fix && "@rawlines" ne "@fixed") { |
4202 | my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes"; | 4222 | my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes"; |