Skip to content

Commit 7ccf41a

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: additional MAINTAINER section entry ordering checks
There is a preferred order for the entries in MAINTAINERS sections. See commits 3b50142 ("MAINTAINERS: sort field names for all entries") and 6680125 ("MAINTAINERS: list the section entries in the preferred order") Add checkpatch tests to try to keep that ordering. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: http://lkml.kernel.org/r/17677130b3ca62d79817e6a22546bad39d7e81b4.camel@perches.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bd93f00 commit 7ccf41a

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,14 +3062,43 @@ sub process {
30623062
#print "is_start<$is_start> is_end<$is_end> length<$length>\n";
30633063
}
30643064

3065-
# check for MAINTAINERS entries that don't have the right form
3066-
if ($realfile =~ /^MAINTAINERS$/ &&
3067-
$rawline =~ /^\+[A-Z]:/ &&
3068-
$rawline !~ /^\+[A-Z]:\t\S/) {
3069-
if (WARN("MAINTAINERS_STYLE",
3070-
"MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
3071-
$fix) {
3072-
$fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3065+
# check MAINTAINERS entries
3066+
if ($realfile =~ /^MAINTAINERS$/) {
3067+
# check MAINTAINERS entries for the right form
3068+
if ($rawline =~ /^\+[A-Z]:/ &&
3069+
$rawline !~ /^\+[A-Z]:\t\S/) {
3070+
if (WARN("MAINTAINERS_STYLE",
3071+
"MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
3072+
$fix) {
3073+
$fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3074+
}
3075+
}
3076+
# check MAINTAINERS entries for the right ordering too
3077+
my $preferred_order = 'MRLSWQBCPTFXNK';
3078+
if ($rawline =~ /^\+[A-Z]:/ &&
3079+
$prevrawline =~ /^[\+ ][A-Z]:/) {
3080+
$rawline =~ /^\+([A-Z]):\s*(.*)/;
3081+
my $cur = $1;
3082+
my $curval = $2;
3083+
$prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3084+
my $prev = $1;
3085+
my $prevval = $2;
3086+
my $curindex = index($preferred_order, $cur);
3087+
my $previndex = index($preferred_order, $prev);
3088+
if ($curindex < 0) {
3089+
WARN("MAINTAINERS_STYLE",
3090+
"Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr);
3091+
} else {
3092+
if ($previndex >= 0 && $curindex < $previndex) {
3093+
WARN("MAINTAINERS_STYLE",
3094+
"Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
3095+
} elsif ((($prev eq 'F' && $cur eq 'F') ||
3096+
($prev eq 'X' && $cur eq 'X')) &&
3097+
($prevval cmp $curval) > 0) {
3098+
WARN("MAINTAINERS_STYLE",
3099+
"Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
3100+
}
3101+
}
30733102
}
30743103
}
30753104

0 commit comments

Comments
 (0)