Skip to content

Commit 91bfe48

Browse files
JoePerchestorvalds
authored andcommitted
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>
1 parent 61135e9 commit 91bfe48

1 file changed

Lines changed: 38 additions & 18 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
my $fix = 0;
3232
my $root;
3333
my %debug;
34-
my %ignore_type = ();
3534
my %camelcase = ();
35+
my %use_type = ();
36+
my @use = ();
37+
my %ignore_type = ();
3638
my @ignore = ();
3739
my $help = 0;
3840
my $configuration_file = ".checkpatch.conf";
@@ -56,6 +58,7 @@ sub help {
5658
--terse one line per report
5759
-f, --file treat FILE as regular source file
5860
--subjective, --strict enable more subjective tests
61+
--types TYPE(,TYPE2...) show only these comma separated message types
5962
--ignore TYPE(,TYPE2...) ignore various comma separated message types
6063
--max-line-length=n set the maximum line length, if exceeded, warn
6164
--show-types show the message "types" in the output
@@ -120,6 +123,7 @@ sub help {
120123
'subjective!' => \$check,
121124
'strict!' => \$check,
122125
'ignore=s' => \@ignore,
126+
'types=s' => \@use,
123127
'show-types!' => \$show_types,
124128
'max-line-length=i' => \$max_line_length,
125129
'root=s' => \$root,
@@ -150,19 +154,38 @@ sub help {
150154
exit(1);
151155
}
152156

153-
@ignore = split(/,/, join(',',@ignore));
154-
foreach my $word (@ignore) {
155-
$word =~ s/\s*\n?$//g;
156-
$word =~ s/^\s*//g;
157-
$word =~ s/\s+/ /g;
158-
$word =~ tr/[a-z]/[A-Z]/;
157+
sub hash_save_array_words {
158+
my ($hashRef, $arrayRef) = @_;
159+
160+
my @array = split(/,/, join(',', @$arrayRef));
161+
foreach my $word (@array) {
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+
}
159173

160-
next if ($word =~ m/^\s*#/);
161-
next if ($word =~ m/^\s*$/);
174+
sub hash_show_words {
175+
my ($hashRef, $prefix) = @_;
162176

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+
}
164184
}
165185

186+
hash_save_array_words(\%ignore_type, \@ignore);
187+
hash_save_array_words(\%use_type, \@use);
188+
166189
my $dbg_values = 0;
167190
my $dbg_possible = 0;
168191
my $dbg_type = 0;
@@ -1367,7 +1390,9 @@ sub possible {
13671390
my $prefix = '';
13681391

13691392
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]};
13711396
}
13721397

13731398
sub report {
@@ -4190,13 +4215,8 @@ sub process {
41904215
}
41914216
}
41924217

4193-
if ($quiet == 0 && keys %ignore_type) {
4194-
print "NOTE: Ignored message types:";
4195-
foreach my $ignore (sort keys %ignore_type) {
4196-
print " $ignore";
4197-
}
4198-
print "\n\n";
4199-
}
4218+
hash_show_words(\%use_type, "Used");
4219+
hash_show_words(\%ignore_type, "Ignored");
42004220

42014221
if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
42024222
my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes";

0 commit comments

Comments
 (0)