]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
syntax-check: Don't forbid curly braces around single line condition body
authorPeter Krempa <pkrempa@redhat.com>
Thu, 10 Sep 2020 13:37:33 +0000 (15:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 15 Sep 2020 13:20:23 +0000 (15:20 +0200)
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>
build-aux/check-spacing.pl
docs/coding-style.rst

index 33377f3dd363511b4e534004b8004830f0715e1a..72901b75f9989162572974b468b50e2b9aa229c0 100755 (executable)
@@ -24,11 +24,6 @@ my $ret = 0;
 my $incomment = 0;
 
 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;
 
     while (defined (my $line = <FILE>)) {
@@ -160,37 +155,6 @@ foreach my $file (@ARGV) {
             print "$file:$.: $line";
             $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;
 }
index 942caf4e0979d99dee99136b45cc226d109e6e12..44e5265a6042124a7d25b698ffa2a83f9cae265a 100644 (file)
@@ -258,15 +258,15 @@ comment, although use of a semicolon is not currently rejected.
 Curly braces
 ------------
 
-Omit the curly braces around an ``if``, ``while``, ``for`` etc.
-body only when both that body and the condition itself occupy a
-single line. In every other case we require the braces. This
+Curly braces around an ``if``, ``while``, ``for`` etc. can be omitted if the
+body and the condition itself occupy only a single line.
+In every other case we require the braces. This
 ensures that it is trivially easy to identify a
 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();
 
 ::