checksrc: warn for leading spaces before the preprocessor hash

Fix the 40+ fallouts

Closes #20282
This commit is contained in:
Daniel Stenberg 2026-01-13 09:23:21 +01:00
parent dac98ccfa2
commit f057ed05be
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
10 changed files with 55 additions and 46 deletions

View file

@ -152,6 +152,7 @@ my %warnings = (
'COMMENTNOSPACESTART' => 'no space following /*',
'COPYRIGHT' => 'file missing a copyright statement',
'CPPCOMMENTS' => '// comment detected',
"CPPSPACE" => 'space before preprocessor hash',
'DOBRACE' => 'A single space between do and open brace',
'EMPTYLINEBRACE' => 'Empty line before the open brace',
'EQUALSNOSPACE' => 'equals sign without following space',
@ -672,6 +673,11 @@ sub scanfile {
$includes{$path} = $l;
}
# detect leading space before the hash
if($l =~ /^([ \t]+)\#/) {
checkwarn("CPPSPACE",
$line, 0, $file, $l, "space before preprocessor hash");
}
# detect and strip preprocessor directives
if($l =~ /^[ \t]*\#/) {
# preprocessor line