checksrc: Added checks for colon operator in ternary expressions
Closes #14990
This commit is contained in:
parent
635253caa0
commit
cff75acfec
@ -56,51 +56,52 @@ my %warnings_extended = (
|
|||||||
|
|
||||||
my %warnings = (
|
my %warnings = (
|
||||||
'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
|
'ASSIGNWITHINCONDITION' => 'assignment within conditional expression',
|
||||||
'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
|
'ASTERISKNOSPACE' => 'pointer declared without space before asterisk',
|
||||||
'ASTERISKSPACE' => 'pointer declared with space after asterisk',
|
'ASTERISKSPACE' => 'pointer declared with space after asterisk',
|
||||||
'BADCOMMAND' => 'bad !checksrc! instruction',
|
'BADCOMMAND' => 'bad !checksrc! instruction',
|
||||||
'BANNEDFUNC' => 'a banned function was used',
|
'BANNEDFUNC' => 'a banned function was used',
|
||||||
'BANNEDPREPROC' => 'a banned symbol was used on a preprocessor line',
|
'BANNEDPREPROC' => 'a banned symbol was used on a preprocessor line',
|
||||||
'BRACEELSE' => '} else on the same line',
|
'BRACEELSE' => '} else on the same line',
|
||||||
'BRACEPOS' => 'wrong position for an open brace',
|
'BRACEPOS' => 'wrong position for an open brace',
|
||||||
'BRACEWHILE' => 'A single space between open brace and while',
|
'BRACEWHILE' => 'A single space between open brace and while',
|
||||||
'COMMANOSPACE' => 'comma without following space',
|
'COMMANOSPACE' => 'comma without following space',
|
||||||
'COMMENTNOSPACEEND' => 'no space before */',
|
'COMMENTNOSPACEEND' => 'no space before */',
|
||||||
'COMMENTNOSPACESTART' => 'no space following /*',
|
'COMMENTNOSPACESTART' => 'no space following /*',
|
||||||
'COPYRIGHT' => 'file missing a copyright statement',
|
'COPYRIGHT' => 'file missing a copyright statement',
|
||||||
'CPPCOMMENTS' => '// comment detected',
|
'CPPCOMMENTS' => '// comment detected',
|
||||||
'DOBRACE' => 'A single space between do and open brace',
|
'DOBRACE' => 'A single space between do and open brace',
|
||||||
'EMPTYLINEBRACE' => 'Empty line before the open brace',
|
'EMPTYLINEBRACE' => 'Empty line before the open brace',
|
||||||
'EQUALSNOSPACE' => 'equals sign without following space',
|
'EQUALSNOSPACE' => 'equals sign without following space',
|
||||||
'EQUALSNULL' => 'if/while comparison with == NULL',
|
'EQUALSNULL' => 'if/while comparison with == NULL',
|
||||||
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
|
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
|
||||||
'FOPENMODE' => 'fopen needs a macro for the mode string',
|
'FOPENMODE' => 'fopen needs a macro for the mode string',
|
||||||
'INCLUDEDUP', => 'same file is included again',
|
'INCLUDEDUP', => 'same file is included again',
|
||||||
'INDENTATION' => 'wrong start column for code',
|
'INDENTATION' => 'wrong start column for code',
|
||||||
'LONGLINE' => "Line longer than $max_column",
|
'LONGLINE' => "Line longer than $max_column",
|
||||||
'SPACEBEFORELABEL' => 'labels not at the start of the line',
|
'SPACEBEFORELABEL' => 'labels not at the start of the line',
|
||||||
'MULTISPACE' => 'multiple spaces used when not suitable',
|
'MULTISPACE' => 'multiple spaces used when not suitable',
|
||||||
'NOSPACEEQUALS' => 'equals sign without preceding space',
|
'NOSPACEC' => 'missing space around ternary colon operator',
|
||||||
'NOSPACEQ' => 'missing space around ternary question mark operator',
|
'NOSPACEEQUALS' => 'equals sign without preceding space',
|
||||||
'NOSPACETHAN' => 'missing space around less or greater than',
|
'NOSPACEQ' => 'missing space around ternary question mark operator',
|
||||||
'NOTEQUALSZERO', => 'if/while comparison with != 0',
|
'NOSPACETHAN' => 'missing space around less or greater than',
|
||||||
'ONELINECONDITION' => 'conditional block on the same line as the if()',
|
'NOTEQUALSZERO', => 'if/while comparison with != 0',
|
||||||
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
|
'ONELINECONDITION' => 'conditional block on the same line as the if()',
|
||||||
'PARENBRACE' => '){ without sufficient space',
|
'OPENCOMMENT' => 'file ended with a /* comment still "open"',
|
||||||
'RETURNNOSPACE' => 'return without space',
|
'PARENBRACE' => '){ without sufficient space',
|
||||||
'SEMINOSPACE' => 'semicolon without following space',
|
'RETURNNOSPACE' => 'return without space',
|
||||||
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
|
'SEMINOSPACE' => 'semicolon without following space',
|
||||||
'SNPRINTF' => 'use of snprintf',
|
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
|
||||||
'SPACEAFTERPAREN' => 'space after open parenthesis',
|
'SNPRINTF' => 'use of snprintf',
|
||||||
'SPACEBEFORECLOSE' => 'space before a close parenthesis',
|
'SPACEAFTERPAREN' => 'space after open parenthesis',
|
||||||
'SPACEBEFORECOMMA' => 'space before a comma',
|
'SPACEBEFORECLOSE' => 'space before a close parenthesis',
|
||||||
'SPACEBEFOREPAREN' => 'space before an open parenthesis',
|
'SPACEBEFORECOMMA' => 'space before a comma',
|
||||||
'SPACESEMICOLON' => 'space before semicolon',
|
'SPACEBEFOREPAREN' => 'space before an open parenthesis',
|
||||||
'SPACESWITCHCOLON' => 'space before colon of switch label',
|
'SPACESEMICOLON' => 'space before semicolon',
|
||||||
'TABS' => 'TAB characters not allowed',
|
'SPACESWITCHCOLON' => 'space before colon of switch label',
|
||||||
'TRAILINGSPACE' => 'Trailing whitespace on the line',
|
'TABS' => 'TAB characters not allowed',
|
||||||
'TYPEDEFSTRUCT' => 'typedefed struct',
|
'TRAILINGSPACE' => 'Trailing whitespace on the line',
|
||||||
'UNUSEDIGNORE' => 'a warning ignore was not used',
|
'TYPEDEFSTRUCT' => 'typedefed struct',
|
||||||
|
'UNUSEDIGNORE' => 'a warning ignore was not used',
|
||||||
);
|
);
|
||||||
|
|
||||||
sub readskiplist {
|
sub readskiplist {
|
||||||
@ -625,12 +626,37 @@ sub scanfile {
|
|||||||
"space after open parenthesis");
|
"space after open parenthesis");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# check spaces before colon
|
||||||
|
if($nostr =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
|
||||||
|
my $m = $1;
|
||||||
|
my $e = $nostr;
|
||||||
|
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that suround colon
|
||||||
|
$e =~ s/':'//g; # ignore these
|
||||||
|
if($e =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
|
||||||
|
checkwarn("NOSPACEC",
|
||||||
|
$line, length($m)+1, $file, $l,
|
||||||
|
"missing space before colon");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# check spaces after colon
|
||||||
|
if($nostr =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
|
||||||
|
my $m = $1;
|
||||||
|
my $e = $nostr;
|
||||||
|
$e =~ s/'(.)':'(.)'/$1:$2/g; # eliminate chars quotes that suround colon
|
||||||
|
$e =~ s/':'//g; # ignore these
|
||||||
|
if($e =~ /^(.*[^'"]\?[^'"].*)\:(\w|\)|\]|')/i) {
|
||||||
|
checkwarn("NOSPACEC",
|
||||||
|
$line, length($m)+1, $file, $l,
|
||||||
|
"missing space after colon");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# check spaces before question mark
|
# check spaces before question mark
|
||||||
if($nostr =~ /^(.*)(\w|\)|\]|')\?/i) {
|
if($nostr =~ /^(.*)(\w|\)|\]|')\?/i) {
|
||||||
my $m = $1;
|
my $m = $1;
|
||||||
my $e = $nostr;
|
my $e = $nostr;
|
||||||
$e =~ s/'?'//g; # ignore these
|
$e =~ s/'?'//g; # ignore these
|
||||||
if($e =~ /^(.*)(\w|\)|')\?/i) {
|
if($e =~ /^(.*)(\w|\)|\]|')\?/i) {
|
||||||
checkwarn("NOSPACEQ",
|
checkwarn("NOSPACEQ",
|
||||||
$line, length($m)+1, $file, $l,
|
$line, length($m)+1, $file, $l,
|
||||||
"missing space before question mark");
|
"missing space before question mark");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user