mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 22:21:42 +00:00
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>
This commit is contained in:
parent
61135e9663
commit
91bfe4843d
@ -31,8 +31,10 @@ my $show_types = 0;
|
|||||||
my $fix = 0;
|
my $fix = 0;
|
||||||
my $root;
|
my $root;
|
||||||
my %debug;
|
my %debug;
|
||||||
my %ignore_type = ();
|
|
||||||
my %camelcase = ();
|
my %camelcase = ();
|
||||||
|
my %use_type = ();
|
||||||
|
my @use = ();
|
||||||
|
my %ignore_type = ();
|
||||||
my @ignore = ();
|
my @ignore = ();
|
||||||
my $help = 0;
|
my $help = 0;
|
||||||
my $configuration_file = ".checkpatch.conf";
|
my $configuration_file = ".checkpatch.conf";
|
||||||
@ -56,6 +58,7 @@ Options:
|
|||||||
--terse one line per report
|
--terse one line per report
|
||||||
-f, --file treat FILE as regular source file
|
-f, --file treat FILE as regular source file
|
||||||
--subjective, --strict enable more subjective tests
|
--subjective, --strict enable more subjective tests
|
||||||
|
--types TYPE(,TYPE2...) show only these comma separated message types
|
||||||
--ignore TYPE(,TYPE2...) ignore various comma separated message types
|
--ignore TYPE(,TYPE2...) ignore various comma separated message types
|
||||||
--max-line-length=n set the maximum line length, if exceeded, warn
|
--max-line-length=n set the maximum line length, if exceeded, warn
|
||||||
--show-types show the message "types" in the output
|
--show-types show the message "types" in the output
|
||||||
@ -120,6 +123,7 @@ GetOptions(
|
|||||||
'subjective!' => \$check,
|
'subjective!' => \$check,
|
||||||
'strict!' => \$check,
|
'strict!' => \$check,
|
||||||
'ignore=s' => \@ignore,
|
'ignore=s' => \@ignore,
|
||||||
|
'types=s' => \@use,
|
||||||
'show-types!' => \$show_types,
|
'show-types!' => \$show_types,
|
||||||
'max-line-length=i' => \$max_line_length,
|
'max-line-length=i' => \$max_line_length,
|
||||||
'root=s' => \$root,
|
'root=s' => \$root,
|
||||||
@ -150,19 +154,38 @@ if ($#ARGV < 0) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ignore = split(/,/, join(',',@ignore));
|
sub hash_save_array_words {
|
||||||
foreach my $word (@ignore) {
|
my ($hashRef, $arrayRef) = @_;
|
||||||
$word =~ s/\s*\n?$//g;
|
|
||||||
$word =~ s/^\s*//g;
|
|
||||||
$word =~ s/\s+/ /g;
|
|
||||||
$word =~ tr/[a-z]/[A-Z]/;
|
|
||||||
|
|
||||||
next if ($word =~ m/^\s*#/);
|
my @array = split(/,/, join(',', @$arrayRef));
|
||||||
next if ($word =~ m/^\s*$/);
|
foreach my $word (@array) {
|
||||||
|
$word =~ s/\s*\n?$//g;
|
||||||
|
$word =~ s/^\s*//g;
|
||||||
|
$word =~ s/\s+/ /g;
|
||||||
|
$word =~ tr/[a-z]/[A-Z]/;
|
||||||
|
|
||||||
$ignore_type{$word}++;
|
next if ($word =~ m/^\s*#/);
|
||||||
|
next if ($word =~ m/^\s*$/);
|
||||||
|
|
||||||
|
$hashRef->{$word}++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub hash_show_words {
|
||||||
|
my ($hashRef, $prefix) = @_;
|
||||||
|
|
||||||
|
if ($quiet == 0 && keys $hashRef) {
|
||||||
|
print "NOTE: $prefix message types:";
|
||||||
|
foreach my $word (sort keys $hashRef) {
|
||||||
|
print " $word";
|
||||||
|
}
|
||||||
|
print "\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hash_save_array_words(\%ignore_type, \@ignore);
|
||||||
|
hash_save_array_words(\%use_type, \@use);
|
||||||
|
|
||||||
my $dbg_values = 0;
|
my $dbg_values = 0;
|
||||||
my $dbg_possible = 0;
|
my $dbg_possible = 0;
|
||||||
my $dbg_type = 0;
|
my $dbg_type = 0;
|
||||||
@ -1367,7 +1390,9 @@ sub possible {
|
|||||||
my $prefix = '';
|
my $prefix = '';
|
||||||
|
|
||||||
sub show_type {
|
sub show_type {
|
||||||
return !defined $ignore_type{$_[0]};
|
return defined $use_type{$_[0]} if (scalar keys %use_type > 0);
|
||||||
|
|
||||||
|
return !defined $ignore_type{$_[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub report {
|
sub report {
|
||||||
@ -4190,13 +4215,8 @@ sub process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($quiet == 0 && keys %ignore_type) {
|
hash_show_words(\%use_type, "Used");
|
||||||
print "NOTE: Ignored message types:";
|
hash_show_words(\%ignore_type, "Ignored");
|
||||||
foreach my $ignore (sort keys %ignore_type) {
|
|
||||||
print " $ignore";
|
|
||||||
}
|
|
||||||
print "\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
|
if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
|
||||||
my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes";
|
my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes";
|
||||||
|
Loading…
Reference in New Issue
Block a user