[libvirt] [PATCHv2 1/6] build-aux:check-spacing.pl: Introduce syntax-check rule for incorrect indentation and blank first line in function body

Shi Lei shi_lei at massclouds.com
Thu Sep 13 08:55:19 UTC 2018


This patch add syntax-check rule for incorrect indentation and blank
first line in function body by changing check-spacing.pl.
For efficiency, it only checks the first line of function body.
But it's enough for most cases.

Signed-off-by: Shi Lei <shi_lei at massclouds.com>
---
 build-aux/check-spacing.pl | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/build-aux/check-spacing.pl b/build-aux/check-spacing.pl
index ca8b434..da9a58b 100755
--- a/build-aux/check-spacing.pl
+++ b/build-aux/check-spacing.pl
@@ -31,6 +31,7 @@ foreach my $file (@ARGV) {
     my $cb_linenum = 0;
     my $cb_code = "";
     my $cb_scolon = 0;
+    my $fn_linenum = 0;
 
     open FILE, $file;
 
@@ -50,6 +51,27 @@ foreach my $file (@ARGV) {
 
         next if $data =~ /^#/;
 
+        # Detect start of function block
+        if ($data =~ /^{$/) {
+            $fn_linenum = $.;
+        }
+
+        # Handle first line of function block
+        if ($fn_linenum && $fn_linenum != $.) {
+            if ($data =~ /^\s*$/) {
+                print "Blank line before content in function body:\n";
+                print "$file:$.:\n$line";
+                $ret = 1;
+            } elsif ($data !~ /^[ ]{4}\S/) {
+                unless ($data =~ /^[ ]\w+:$/ || $data =~ /^}/) {
+                    print "Incorrect indentation in function body:\n";
+                    print "$file:$.:\n$line";
+                    $ret = 1;
+                }
+            }
+            $fn_linenum = 0;
+        }
+
         # Kill contents of multi-line comments
         # and detect end of multi-line comments
         if ($incomment) {
-- 
2.17.1





More information about the libvir-list mailing list