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

@ -895,7 +895,7 @@ cr_connect_common(struct Curl_cfilter *cf,
}
if(0 == what) {
CURL_TRC_CF(data, cf, "Curl_socket_check: %s would block",
wants_read&&wants_write ? "writing and reading" :
wants_read && wants_write ? "writing and reading" :
wants_write ? "writing" : "reading");
if(wants_write)
connssl->io_need |= CURL_SSL_IO_NEED_SEND;

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;