mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthijs Kooijman <matthijs@stdin.nl>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: Paul Zimmerman <Paul.Zimmerman@synopsys.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] checkpatch: Check block comments outside of net
Date: Tue, 9 Apr 2013 13:26:03 +0200	[thread overview]
Message-ID: <20130409112603.GH13691@login.drsnuggles.stderr.nl> (raw)
In-Reply-To: <20130409111958.GG13691@login.drsnuggles.stderr.nl>

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


  reply	other threads:[~2013-04-09 11:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 11:19 [PATCH] " Matthijs Kooijman
2013-04-09 11:26 ` Matthijs Kooijman [this message]
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
2013-04-10  9:05     ` [PATCH v4] " Matthijs Kooijman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130409112603.GH13691@login.drsnuggles.stderr.nl \
    --to=matthijs@stdin.nl \
    --cc=Paul.Zimmerman@synopsys.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®