[sheepdog] [PATCH v2 1/2] checkpatch: add more strict checking for block comments

Liu Yuan namei.unix at gmail.com
Fri Mar 22 06:24:52 CET 2013


From: Liu Yuan <tailai.ly at taobao.com>

This patch try to uniform the block comments, which gives more
consistent view to code reviewer.

 A:
    /* foo
     * bar */
 B:
    /*
     * foo
     * bar */
 C:
    /*
     * one-liner
     */
 D:
    /* one-liner
     */
 E:
    /* foo
     * bar
     * baz
     */
 A, B, C, D, E is not preferred

   /*
    * This block comments style
    * is preferred
    */

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 script/checkpatch.pl |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/script/checkpatch.pl b/script/checkpatch.pl
index f2b74da..4a6b5d6 100755
--- a/script/checkpatch.pl
+++ b/script/checkpatch.pl
@@ -1695,6 +1695,56 @@ sub process {
 			     "please, no space before tabs\n" . $herevet);
 		}
 
+# check for block comment.
+#
+# A:
+#    /* foo
+#     * bar */
+# B:
+#    /*
+#     * foo
+#     * bar */
+# C:
+#    /*
+#     * one-liner
+#     */
+# D:
+#    /* one-liner
+#     */
+# E:
+#    /* foo
+#     * bar
+#     * baz
+#     */
+#   above is not preferred
+#
+#   /*
+#    * This block comments style
+#    * is preferred
+#    */
+
+		if ($rawline =~ /^\+.*\*\/\s*$/ &&
+		    $rawline !~ /^\+.*\/\*/) {
+			if ($rawline !~ /^\+\s*\*\/\s*$/) {
+				# case A and B
+				WARN("BLOCK_COMMENT_STYLE",
+				     "[BCS] put the trailing */ on a separate line\n" . $hereprev);
+			} elsif ($prevrawline =~ /^\+\s*\/\*/ ||
+				 $rawlines[$linenr - 3] =~ /^\+\s*\/\*/) {
+				# case C and D
+				WARN("BLOCK_COMMENT_STYLE",
+				     "[BCS] don't use block comments for one liner comment\n" . $hereprev);
+			} else {
+				# case E
+				my $ln = $linenr;
+				while ($rawlines[$ln] !~ /^\+\s*\/\*/) { $ln--; }
+				if ($rawlines[$ln] !~ /^\+\s*\/\*\s*$/) {
+					WARN("BLOCK_COMMENT_STYLE",
+					     "[BCS] don't comment at first line in block comments\n" . $hereprev);
+				}
+			}
+		}
+
 # check for spaces at the beginning of a line.
 # Exceptions:
 #  1) within comments
-- 
1.7.9.5




More information about the sheepdog mailing list