[sheepdog] [PATCH RFC] checkpatch: add more strict checking for block comments
Liu Yuan
namei.unix at gmail.com
Tue Mar 19 13:09:50 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..d9d067e 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 =~ /^\+[ \t]*.*\*\/[ \t]*$/ &&
+ $rawline !~ /^\+[\S \t]*\/\*/) {
+ if ($rawline !~ /^\+[ \t]*\*\/[ \t]*$/) {
+ # case A and B
+ WARN("BLOCK_COMMENT_STYLE",
+ "[BCS] put the trailing */ on a separate line\n" . $hereprev);
+ } elsif ($prevrawline =~ /^\+[ \t]*\/\*/ ||
+ $rawlines[$linenr - 3] =~ /^\+[ \t]*\/\*/) {
+ # 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] !~ /^\+[ \t]*\/\*/) { $ln--; }
+ if ($rawlines[$ln] !~ /^\+[ \t]*\/\*[ \t]*$/) {
+ 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