mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
syntax-check: Don't forbid curly braces around single line condition body
This syntax rule doesn't make much sense, especially if there are so much exceptions to it. Just remove it and adjust the coding style. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b4d2cb58b2
commit
931c1d128d
@ -24,11 +24,6 @@ my $ret = 0;
|
|||||||
my $incomment = 0;
|
my $incomment = 0;
|
||||||
|
|
||||||
foreach my $file (@ARGV) {
|
foreach my $file (@ARGV) {
|
||||||
# Per-file variables for multiline Curly Bracket (cb_) check
|
|
||||||
my $cb_linenum = 0;
|
|
||||||
my $cb_code = "";
|
|
||||||
my $cb_scolon = 0;
|
|
||||||
|
|
||||||
open FILE, $file;
|
open FILE, $file;
|
||||||
|
|
||||||
while (defined (my $line = <FILE>)) {
|
while (defined (my $line = <FILE>)) {
|
||||||
@ -160,37 +155,6 @@ foreach my $file (@ARGV) {
|
|||||||
print "$file:$.: $line";
|
print "$file:$.: $line";
|
||||||
$ret = 1;
|
$ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# One line conditional statements with one line bodies should
|
|
||||||
# not use curly brackets.
|
|
||||||
if ($data =~ /^\s*(if|while|for)\b.*\{$/) {
|
|
||||||
$cb_linenum = $.;
|
|
||||||
$cb_code = $line;
|
|
||||||
$cb_scolon = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
# We need to check for exactly one semicolon inside the body,
|
|
||||||
# because empty statements (e.g. with comment only) are
|
|
||||||
# allowed
|
|
||||||
if ($cb_linenum == $. - 1 && $data =~ /^[^;]*;[^;]*$/) {
|
|
||||||
$cb_code .= $line;
|
|
||||||
$cb_scolon = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data =~ /^\s*}\s*$/ &&
|
|
||||||
$cb_linenum == $. - 2 &&
|
|
||||||
$cb_scolon) {
|
|
||||||
|
|
||||||
print "Curly brackets around single-line body:\n";
|
|
||||||
print "$file:$cb_linenum-$.:\n$cb_code$line";
|
|
||||||
$ret = 1;
|
|
||||||
|
|
||||||
# There _should_ be no need to reset the values; but to
|
|
||||||
# keep my inner peace...
|
|
||||||
$cb_linenum = 0;
|
|
||||||
$cb_scolon = 0;
|
|
||||||
$cb_code = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close FILE;
|
close FILE;
|
||||||
}
|
}
|
||||||
|
@ -258,15 +258,15 @@ comment, although use of a semicolon is not currently rejected.
|
|||||||
Curly braces
|
Curly braces
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Omit the curly braces around an ``if``, ``while``, ``for`` etc.
|
Curly braces around an ``if``, ``while``, ``for`` etc. can be omitted if the
|
||||||
body only when both that body and the condition itself occupy a
|
body and the condition itself occupy only a single line.
|
||||||
single line. In every other case we require the braces. This
|
In every other case we require the braces. This
|
||||||
ensures that it is trivially easy to identify a
|
ensures that it is trivially easy to identify a
|
||||||
single-\ *statement* loop: each has only one *line* in its body.
|
single-\ *statement* loop: each has only one *line* in its body.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
while (expr) // single line body; {} is forbidden
|
while (expr) // single line body; {} is optional
|
||||||
single_line_stmt();
|
single_line_stmt();
|
||||||
|
|
||||||
::
|
::
|
||||||
|
Loading…
Reference in New Issue
Block a user