Skip to content

Commit 323c126

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: warn on CamelCase variable names
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>
1 parent 74349bc commit 323c126

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

scripts/checkpatch.pl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,8 @@ sub process {
13981398
my %suppress_export;
13991399
my $suppress_statement = 0;
14001400

1401+
my %camelcase = ();
1402+
14011403
# Pre-scan the patch sanitizing the lines.
14021404
# Pre-scan the patch looking for any __setup documentation.
14031405
#
@@ -2905,12 +2907,17 @@ sub process {
29052907
}
29062908
}
29072909

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

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

0 commit comments

Comments
 (0)