diff options
Diffstat (limited to 'lib/checksrc.pl')
-rwxr-xr-x | lib/checksrc.pl | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/checksrc.pl b/lib/checksrc.pl index 498da94b..78b9cef5 100755 --- a/lib/checksrc.pl +++ b/lib/checksrc.pl @@ -52,7 +52,7 @@ my %warnings_extended = ( my %warnings = ( 'LONGLINE' => "Line longer than $max_column", 'TABS' => 'TAB characters not allowed', - 'TRAILINGSPACE' => 'Trailing white space on the line', + 'TRAILINGSPACE' => 'Trailing whitespace on the line', 'CPPCOMMENTS' => '// comment detected', 'SPACEBEFOREPAREN' => 'space before an open parenthesis', 'SPACEAFTERPAREN' => 'space after open parenthesis', @@ -82,6 +82,9 @@ my %warnings = ( 'SNPRINTF' => 'use of snprintf', 'ONELINECONDITION' => 'conditional block on the same line as the if()', 'TYPEDEFSTRUCT' => 'typedefed struct', + 'DOBRACE' => 'A single space between do and open brace', + 'BRACEWHILE' => 'A single space between open brace and while', + 'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression', ); sub readskiplist { @@ -397,7 +400,7 @@ sub scanfile { checkwarn("TABS", $line, length($1), $file, $l, "Contains TAB character", 1); } - # detect trailing white space + # detect trailing whitespace if($l =~ /^(.*)[ \t]+\z/) { checkwarn("TRAILINGSPACE", $line, length($1), $file, $l, "Trailing whitespace"); @@ -439,7 +442,7 @@ sub scanfile { # crude attempt to detect // comments without too many false # positives - if($l =~ /^([^"\*]*)[^:"]\/\//) { + if($l =~ /^(([^"\*]*)[^:"]|)\/\//) { checkwarn("CPPCOMMENTS", $line, length($1), $file, $l, "\/\/ comment"); } @@ -468,6 +471,14 @@ sub scanfile { } } + # check spaces in 'do {' + if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) { + checkwarn("DOBRACE", $line, length($1) + 2, $file, $l, "one space after do before brace"); + } + # check spaces in 'do {' + elsif($nostr =~ /^( *)\}( *)while/ && length($2) != 1) { + checkwarn("BRACEWHILE", $line, length($1) + 2, $file, $l, "one space between brace and while"); + } if($nostr =~ /^((.*\s)(if) *\()(.*)\)(.*)/) { my $pos = length($1); my $postparen = $5; @@ -715,6 +726,12 @@ sub scanfile { "typedef'ed struct"); } + if($nostr =~ /(.*)! +(\w|\()/) { + checkwarn("EXCLAMATIONSPACE", + $line, length($1)+1, $file, $ol, + "space after exclamation mark"); + } + # check for more than one consecutive space before open brace or # question mark. Skip lines containing strings since they make it hard # due to artificially getting multiple spaces |