checkpatch: Accept form feeds.
authorDaniele Di Proietto <diproiettod@vmware.com>
Mon, 18 Apr 2016 20:14:29 +0000 (13:14 -0700)
committerDaniele Di Proietto <diproiettod@vmware.com>
Mon, 18 Apr 2016 21:36:20 +0000 (14:36 -0700)
CodingStyle.md says:

"Use form feeds (control+L) to divide long source files into logical
pieces.  A form feed should appear as the only character on a line."

checkpatch.py currently complains about form feed. For example, on
commit 2c06d9a927c5("ovstest: Add test-netlink-conntrack command."),
checkpatch.py returns:

    W(140): Line has non-spaces leading whitespace
    W(140): Line has trailing whitespace
    +

    W(177): Line has non-spaces leading whitespace
    W(177): Line has trailing whitespace
    +

    W(199): Line has non-spaces leading whitespace
    W(199): Line has trailing whitespace
    +

This commit suppresses the two warnings for lines with form feeds as the
only character.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
utilities/checkpatch.py

index dbdcbc8..b641560 100755 (executable)
@@ -47,6 +47,7 @@ __regex_added_line = re.compile(r'^\+{1,2}[^\+][\w\W]*')
 __regex_leading_with_whitespace_at_all = re.compile(r'^\s+')
 __regex_leading_with_spaces = re.compile(r'^ +[\S]+')
 __regex_trailing_whitespace = re.compile(r'[^\S]+$')
+__regex_single_line_feed = re.compile(r'^\f$')
 __regex_for_if_missing_whitespace = re.compile(r'(if|for|while)[\(]')
 __regex_for_if_too_much_whitespace = re.compile(r'(if|for|while)  +[\(]')
 __regex_for_if_parens_whitespace = re.compile(r'(if|for|while) \( +[\s\S]+\)')
@@ -75,8 +76,10 @@ def leading_whitespace_is_spaces(line):
     """
     if skip_leading_whitespace_check:
         return True
-    if __regex_leading_with_whitespace_at_all.search(line) is not None:
+    if (__regex_leading_with_whitespace_at_all.search(line) is not None and
+            __regex_single_line_feed.search(line) is None):
         return __regex_leading_with_spaces.search(line) is not None
+
     return True
 
 
@@ -85,7 +88,8 @@ def trailing_whitespace_or_crlf(line):
     """
     if skip_trailing_whitespace_check:
         return False
-    return __regex_trailing_whitespace.search(line) is not None
+    return (__regex_trailing_whitespace.search(line) is not None and
+            __regex_single_line_feed.search(line) is None)
 
 
 def if_and_for_whitespace_checks(line):