checksrc: add check for spaces around logical AND operators

Closes #15144
This commit is contained in:
Gabriel Marin 2024-10-03 19:20:09 +03:00 committed by Daniel Stenberg
parent 51724c43e3
commit a58584a881
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 16 additions and 1 deletions

View file

@ -80,6 +80,7 @@ my %warnings = (
'LONGLINE' => "Line longer than $max_column",
'SPACEBEFORELABEL' => 'labels not at the start of the line',
'MULTISPACE' => 'multiple spaces used when not suitable',
'NOSPACEAND' => 'missing space around Logical AND operator',
'NOSPACEC' => 'missing space around ternary colon operator',
'NOSPACEEQUALS' => 'equals sign without preceding space',
'NOSPACEQ' => 'missing space around ternary question mark operator',
@ -626,6 +627,20 @@ sub scanfile {
"space after open parenthesis");
}
# check spaces before Logical AND operator
if($nostr =~ /^(.*)\w&&/i) {
checkwarn("NOSPACEAND",
$line, length($1)+1, $file, $l,
"missing space before Logical AND");
}
# check spaces after Logical AND operator
if($nostr =~ /^(.*&&)\w/i) {
checkwarn("NOSPACEAND",
$line, length($1), $file, $l,
"missing space after Logical AND");
}
# check spaces before colon
if($nostr =~ /^(.*[^']\?[^'].*)(\w|\)|\]|')\:/i) {
my $m = $1;