mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 03:47:47 +00:00
tools: extend checkpatch.pl for frr_{with,each}
For frr_each, just fix some existing warnings; for frr_with_* add a warning indicating that braces should always be used. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
6421f2c6d9
commit
ba28659f1c
@ -3351,7 +3351,7 @@ sub process {
|
|||||||
|
|
||||||
# if/while/etc brace do not go on next line, unless defining a do while loop,
|
# if/while/etc brace do not go on next line, unless defining a do while loop,
|
||||||
# or if that brace on the next line is for something else
|
# or if that brace on the next line is for something else
|
||||||
if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
|
if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)frr_(each|with)[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
|
||||||
my $pre_ctx = "$1$2";
|
my $pre_ctx = "$1$2";
|
||||||
|
|
||||||
my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
|
my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
|
||||||
@ -3397,7 +3397,7 @@ sub process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check relative indent for conditionals and blocks.
|
# Check relative indent for conditionals and blocks.
|
||||||
if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
|
if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)frr_(each|with)[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
|
||||||
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
|
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
|
||||||
ctx_statement_block($linenr, $realcnt, 0)
|
ctx_statement_block($linenr, $realcnt, 0)
|
||||||
if (!defined $stat);
|
if (!defined $stat);
|
||||||
@ -5177,6 +5177,31 @@ sub process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defined $suppress_ifbraces{$linenr - 1} &&
|
||||||
|
$line =~ /\b(frr_with_)/) {
|
||||||
|
my ($level, $endln, @chunks) =
|
||||||
|
ctx_statement_full($linenr, $realcnt, $-[0]);
|
||||||
|
|
||||||
|
# Check the condition.
|
||||||
|
my ($cond, $block) = @{$chunks[0]};
|
||||||
|
#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
|
||||||
|
if (defined $cond) {
|
||||||
|
substr($block, 0, length($cond), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($level == 0 && $block !~ /^\s*\{/) {
|
||||||
|
my $herectx = $here . "\n";
|
||||||
|
my $cnt = statement_rawlines($block);
|
||||||
|
|
||||||
|
for (my $n = 0; $n < $cnt; $n++) {
|
||||||
|
$herectx .= raw_line($linenr, $n) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
WARN("BRACES",
|
||||||
|
"braces {} are mandatory for frr_with_* blocks\n" . $herectx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# check for single line unbalanced braces
|
# check for single line unbalanced braces
|
||||||
if ($sline =~ /^.\s*\}\s*else\s*$/ ||
|
if ($sline =~ /^.\s*\}\s*else\s*$/ ||
|
||||||
$sline =~ /^.\s*else\s*\{\s*$/) {
|
$sline =~ /^.\s*else\s*\{\s*$/) {
|
||||||
|
Loading…
Reference in New Issue
Block a user