Skip to content

Commit

Permalink
checkpatch: warn on CamelCase variable names
Browse files Browse the repository at this point in the history
Store the camelcase variables in a hash and only emit a warning on the
first use of each new variable.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Joe Perches authored and Linus Torvalds committed Dec 18, 2012
1 parent 74349bc commit 323c126
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,8 @@ sub process {
my %suppress_export;
my $suppress_statement = 0;

my %camelcase = ();

# Pre-scan the patch sanitizing the lines.
# Pre-scan the patch looking for any __setup documentation.
#
Expand Down Expand Up @@ -2905,12 +2907,17 @@ sub process {
}
}

#studly caps, commented out until figure out how to distinguish between use of existing and adding new
# if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
# print "No studly caps, use _\n";
# print "$herecurr";
# $clean = 0;
# }
#CamelCase
while ($line =~ m{($Constant|$Lval)}g) {
my $var = $1;
if ($var !~ /$Constant/ &&
$var =~ /[A-Z]\w*[a-z]|[a-z]\w*[A-Z]/ &&
!defined $camelcase{$var}) {
$camelcase{$var} = 1;
WARN("CAMELCASE",
"Avoid CamelCase: <$var>\n" . $herecurr);
}
}

#no spaces allowed after \ in define
if ($line=~/\#\s*define.*\\\s$/) {
Expand Down

0 comments on commit 323c126

Please sign in to comment.