[PATCH 04/17] syntax-check: Don't forbid curly braces around single line condition body

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 build-aux/check-spacing.pl | 36 ------------------------------------
 docs/coding-style.rst      |  8 ++++----
 2 files changed, 4 insertions(+), 40 deletions(-)

diff --git a/build-aux/check-spacing.pl b/build-aux/check-spacing.pl
index 33377f3dd3..72901b75f9 100755
--- a/build-aux/check-spacing.pl
+++ b/build-aux/check-spacing.pl
@@ -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;
 }
diff --git a/docs/coding-style.rst b/docs/coding-style.rst
index 942caf4e09..44e5265a60 100644
--- a/docs/coding-style.rst
+++ b/docs/coding-style.rst
@@ -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();

 ::
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux