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

Liu Yuan namei.unix at gmail.com
Mon Mar 25 07:01:41 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 |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/script/checkpatch.pl b/script/checkpatch.pl
index f2b74da..ccdc58a 100755
--- a/script/checkpatch.pl
+++ b/script/checkpatch.pl
@@ -1695,6 +1695,54 @@ 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 ($line =~ /^\+/ && $rawline =~ /\*\/$/ && $rawline !~ /\/\*/) {
+			if ($rawline !~ /^\+\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 >= 0) { $ln--; }
+				if ($rawlines[$ln] !~ /^\+\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