linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Check block comments outside of net
@ 2013-04-09 11:19 Matthijs Kooijman
  2013-04-09 11:26 ` [PATCH v2] " Matthijs Kooijman
  2013-04-09 11:32 ` [PATCH] " Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Matthijs Kooijman @ 2013-04-09 11:19 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: Paul Zimmerman, linux-kernel

There was some code checking block comments in net/ and drivers/net/,
but nothing to check the regular block comment style.

The end of a block comment is the same as inside net, so that check can
just be generalized.

The start of block comment must not have any comment after the leading
/*, which requires a new check.

Tested with:

$ cat test.c
/* foo */

/*
 * foo
 */

/* foo
 */

/* foo
 * bar */

/**
 * foo
 * bar
 */

/****************************
 * some long block comment
 ****************************/

struct foo {
        int bar;        /* another test */
};

$ ./scripts/checkpatch.pl -f test.c
WARNING: block comments put the leading /* on a separate line
+
+/* foo

WARNING: block comments put the leading /* on a separate line
+
+/* foo

WARNING: block comments put the trailing */ on a separate line
+ * bar */

WARNING: block comments put the leading /* on a separate line
+
+/**

WARNING: block comments put the leading /* on a separate line
+
+/****************************

total: 0 errors, 5 warnings, 25 lines checked

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
---


Note that this patch rejects /** comments, since those are not mentioned
in Codingstyle. They are used in practice though (around 1000 occurences
in kernel/ alone), so perhaps they should be allowed and documented?

Also, the new check only fires when the previous line is empty, just
like the start of block comment check for net/. However, I couldn't find
any documentation on why this restriction is needed?


 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b28cc38..64080ad 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1884,13 +1884,21 @@ sub process {
 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
 		}
 
-		if ($realfile =~ m@^(drivers/net/|net/)@ &&
-		    $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
+		if ($realfile !~ m@^(drivers/net/|net/)@ &&
+		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
+		    $rawline !~ /^\+[ \t]*\/\*[ \t]*$/ &&	#blank /*
+		    $rawline =~ /^\+[ \t]*\/\*.+$/ &&
+		    $prevrawline =~ /^\+[ \t]*$/) {
+			WARN("BLOCK_COMMENT_STYLE",
+			     "block comments use an empty /* line\n" . $hereprev);
+		}
+
+		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
 		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
 		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
 		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
-			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
-			     "networking block comments put the trailing */ on a separate line\n" . $herecurr);
+			WARN("BLOCK_COMMENT_STYLE",
+			     "block comments put the trailing */ on a separate line\n" . $herecurr);
 		}
 
 # check for spaces at the beginning of a line.
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] checkpatch: Check block comments outside of net
  2013-04-09 11:19 [PATCH] checkpatch: Check block comments outside of net Matthijs Kooijman
@ 2013-04-09 11:26 ` Matthijs Kooijman
  2013-04-09 11:32 ` [PATCH] " Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Matthijs Kooijman @ 2013-04-09 11:26 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: Paul Zimmerman, linux-kernel

There was some code checking block comments in net/ and drivers/net/,
but nothing for regular comments.

The end of a block comment is the same as inside net, so that check can
just be generalized.

The start of block comment must not have any comment after the leading
/*, which requires a new check.

Tested with:

$ cat test.c
/* foo */

/*
 * foo
 */

/* foo
 */

/* foo
 * bar */

/**
 * foo
 * bar
 */

/****************************
 * some long block comment
 ****************************/

struct foo {
        int bar;        /* another test */
};

$ ./scripts/checkpatch.pl -f test.c
WARNING: block comments put the leading /* on a separate line
+
+/* foo

WARNING: block comments put the leading /* on a separate line
+
+/* foo

WARNING: block comments put the trailing */ on a separate line
+ * bar */

WARNING: block comments put the leading /* on a separate line
+
+/**

WARNING: block comments put the leading /* on a separate line
+
+/****************************

total: 0 errors, 5 warnings, 25 lines checked
Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
---
 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Note that this patch rejects /** comments, since those are not mentioned
in Codingstyle. They are used in practice though (around 1000 occurences
in kernel/ alone), so perhaps they should be allowed and documented?

Also, the new check only fires when the previous line is empty, just
like the start of block comment check for net/. However, I couldn't find
any documentation on why this restriction is needed?

v2 makes a change to the error message and adds a comment I forgot to
commit when creating this patch.

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b28cc38..458cdbf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1884,13 +1884,21 @@ sub process {
 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
 		}
 
-		if ($realfile =~ m@^(drivers/net/|net/)@ &&
-		    $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
+		if ($realfile !~ m@^(drivers/net/|net/)@ &&
+		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
+		    $rawline !~ /^\+[ \t]*\/\*[ \t]*$/ &&	#blank /*
+		    $rawline =~ /^\+[ \t]*\/\*.+$/ &&		#non blank /*
+		    $prevrawline =~ /^\+[ \t]*$/) {
+			WARN("BLOCK_COMMENT_STYLE",
+			     "block comments put the leading /* on a separate line\n" . $hereprev);
+		}
+
+		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
 		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
 		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
 		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
-			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
-			     "networking block comments put the trailing */ on a separate line\n" . $herecurr);
+			WARN("BLOCK_COMMENT_STYLE",
+			     "block comments put the trailing */ on a separate line\n" . $herecurr);
 		}
 
 # check for spaces at the beginning of a line.
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] checkpatch: Check block comments outside of net
  2013-04-09 11:19 [PATCH] checkpatch: Check block comments outside of net Matthijs Kooijman
  2013-04-09 11:26 ` [PATCH v2] " Matthijs Kooijman
@ 2013-04-09 11:32 ` Joe Perches
  2013-04-09 11:37   ` Matthijs Kooijman
  2013-04-10  8:59   ` [PATCH v3] checkpatch: check " Matthijs Kooijman
  1 sibling, 2 replies; 6+ messages in thread
From: Joe Perches @ 2013-04-09 11:32 UTC (permalink / raw)
  To: Matthijs Kooijman; +Cc: Andy Whitcroft, Paul Zimmerman, linux-kernel

On Tue, 2013-04-09 at 13:19 +0200, Matthijs Kooijman wrote:
> There was some code checking block comments in net/ and drivers/net/,
> but nothing to check the regular block comment style.
[]
> Note that this patch rejects /** comments, since those are not mentioned
> in Codingstyle. They are used in practice though (around 1000 occurences
> in kernel/ alone), so perhaps they should be allowed and documented?

Those are kernel-doc comments and must be allowed.
see Documentation/kernel-doc-nano-HOWTO.txt

> Also, the new check only fires when the previous line is empty, just
> like the start of block comment check for net/. However, I couldn't find
> any documentation on why this restriction is needed?

I'm not that concerned about block comment style.
Maybe others are.

Please make it a --strict (CHK) only test for now.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] checkpatch: Check block comments outside of net
  2013-04-09 11:32 ` [PATCH] " Joe Perches
@ 2013-04-09 11:37   ` Matthijs Kooijman
  2013-04-10  8:59   ` [PATCH v3] checkpatch: check " Matthijs Kooijman
  1 sibling, 0 replies; 6+ messages in thread
From: Matthijs Kooijman @ 2013-04-09 11:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, Paul Zimmerman, linux-kernel

Hi Joe,

On Tue, Apr 09, 2013 at 04:32:54AM -0700, Joe Perches wrote:
> > Note that this patch rejects /** comments, since those are not mentioned
> > in Codingstyle. They are used in practice though (around 1000 occurences
> > in kernel/ alone), so perhaps they should be allowed and documented?
> 
> Those are kernel-doc comments and must be allowed.
> see Documentation/kernel-doc-nano-HOWTO.txt
I just realized that as well, I'll send an updated patch.

> > Also, the new check only fires when the previous line is empty, just
> > like the start of block comment check for net/. However, I couldn't find
> > any documentation on why this restriction is needed?
> 
> I'm not that concerned about block comment style.
> Maybe others are.
I'm not entirely sure if this is a answer to my question? Or are you
saying you don't really care about this and thus don't know the answer?
:-)

> Please make it a --strict (CHK) only test for now.
Ok.

Gr.

Matthijs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3] checkpatch: check block comments outside of net
  2013-04-09 11:32 ` [PATCH] " Joe Perches
  2013-04-09 11:37   ` Matthijs Kooijman
@ 2013-04-10  8:59   ` Matthijs Kooijman
  2013-04-10  9:05     ` [PATCH v4] " Matthijs Kooijman
  1 sibling, 1 reply; 6+ messages in thread
From: Matthijs Kooijman @ 2013-04-10  8:59 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, Paul Zimmerman, linux-kernel

There was some code checking block comments in net/ and drivers/net/,
but nothing for regular comments.

The end of a block comment is the same as inside net, so that check can
just be generalized.

The start of block comment must not have any comment after the leading
/*, which requires a new check.

Tested with:

$ cat test.c
/* foo */

/*
 * foo
 */

/* foo
 */

/* foo
 * bar */

/**
 * foo
 * bar
 */

/****************************
 * some long block comment
 ****************************/

struct foo {
        int bar;        /* another test */
};

$ ./scripts/checkpatch.pl --strict -f test.c
CHECK: block comments put the leading /* on a separate line
+
+/* foo

CHECK: block comments put the leading /* on a separate line
+
+/* foo

CHECK: block comments put the trailing */ on a separate line
+ * bar */

total: 0 errors, 0 warnings, 3 checks, 25 lines checked

test.c has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>

---

v2: change the error message for consistency
    add a comment
v3: allow /*{2,} as well
    convert to CHK

I've also allowed /******************** since that seems to be used in
a lot of places as well.
---
 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b28cc38..64021da 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1884,13 +1884,21 @@ sub process {
 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
 		}
 
-		if ($realfile =~ m@^(drivers/net/|net/)@ &&
-		    $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
+		if ($realfile !~ m@^(drivers/net/|net/)@ &&
+		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
+		    $rawline !~ /^\+[ \t]*\/\*\*?[ \t]*$/ &&	#blank /* or /**
+		    $rawline =~ /^\+[ \t]*\/\*.+$/ &&		#non blank /*
+		    $prevrawline =~ /^\+[ \t]*$/) {
+			CHK("BLOCK_COMMENT_STYLE",
+			     "block comments put the leading /* on a separate line\n" . $hereprev);
+		}
+
+		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
 		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
 		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
 		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
-			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
-			     "networking block comments put the trailing */ on a separate line\n" . $herecurr);
+			CHK("BLOCK_COMMENT_STYLE",
+			     "block comments put the trailing */ on a separate line\n" . $herecurr);
 		}
 
 # check for spaces at the beginning of a line.
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4] checkpatch: check block comments outside of net
  2013-04-10  8:59   ` [PATCH v3] checkpatch: check " Matthijs Kooijman
@ 2013-04-10  9:05     ` Matthijs Kooijman
  0 siblings, 0 replies; 6+ messages in thread
From: Matthijs Kooijman @ 2013-04-10  9:05 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft, Paul Zimmerman, linux-kernel

There was some code checking block comments in net/ and drivers/net/,
but nothing for regular comments.

The end of a block comment is the same as inside net, so that check can
just be generalized.

The start of block comment must not have any comment after the leading
/*, which requires a new check.

Tested with:

$ cat test.c
/* foo */

/*
 * foo
 */

/* foo
 */

/* foo
 * bar */

/**
 * foo
 * bar
 */

/****************************
 * some long block comment
 ****************************/

struct foo {
        int bar;        /* another test */
};

$ ./scripts/checkpatch.pl --strict -f test.c
CHECK: block comments put the leading /* on a separate line
+
+/* foo

CHECK: block comments put the leading /* on a separate line
+
+/* foo

CHECK: block comments put the trailing */ on a separate line
+ * bar */

total: 0 errors, 0 warnings, 3 checks, 25 lines checked

test.c has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>

---

v2: change the error message for consistency
    add a comment
v3: allow /** as well
v4: allow /*{2,} as well
    convert to CHK

I've also allowed /******************** since that seems to be used in
a lot of places as well.

v3 was wrong, it only allowed /** (even though it advertised allowing
/*** as well....). Sorry for the noise...
---
 scripts/checkpatch.pl | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b28cc38..b0a9211 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1884,13 +1884,21 @@ sub process {
 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
 		}
 
-		if ($realfile =~ m@^(drivers/net/|net/)@ &&
-		    $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
+		if ($realfile !~ m@^(drivers/net/|net/)@ &&
+		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
+		    $rawline !~ /^\+[ \t]*\/\*{1,}[ \t]*$/ &&	#blank /* (or more stars)
+		    $rawline =~ /^\+[ \t]*\/\*.+$/ &&		#non blank /*
+		    $prevrawline =~ /^\+[ \t]*$/) {
+			CHK("BLOCK_COMMENT_STYLE",
+			     "block comments put the leading /* on a separate line\n" . $hereprev);
+		}
+
+		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
 		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
 		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
 		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
-			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
-			     "networking block comments put the trailing */ on a separate line\n" . $herecurr);
+			CHK("BLOCK_COMMENT_STYLE",
+			     "block comments put the trailing */ on a separate line\n" . $herecurr);
 		}
 
 # check for spaces at the beginning of a line.
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-10  9:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-09 11:19 [PATCH] checkpatch: Check block comments outside of net Matthijs Kooijman
2013-04-09 11:26 ` [PATCH v2] " Matthijs Kooijman
2013-04-09 11:32 ` [PATCH] " Joe Perches
2013-04-09 11:37   ` Matthijs Kooijman
2013-04-10  8:59   ` [PATCH v3] checkpatch: check " Matthijs Kooijman
2013-04-10  9:05     ` [PATCH v4] " Matthijs Kooijman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).