[PATCH] checkpatch: warn about multi-line comments without an empty /* line

Petr Tesarik posted 1 patch 2 years, 4 months ago
There is a newer version of this series
scripts/checkpatch.pl | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] checkpatch: warn about multi-line comments without an empty /* line
Posted by Petr Tesarik 2 years, 4 months ago
According to Documentation/process/coding-style.rst, the preferred style
for multi-line comments outside net/ and drivers/net/ is:

.. code-block:: c

        /*
         * This is the preferred style for multi-line
         * comments in the Linux kernel source code.
         * Please use it consistently.
         *
         * Description:  A column of asterisks on the left side,
         * with beginning and ending almost-blank lines.
         */

Signed-off-by: Petr Tesarik <petr@tesarici.cz>
---
 scripts/checkpatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7d16f863edf1..0fc3427a9ec9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4006,6 +4006,14 @@ sub process {
 			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
 		}
 
+# Non-networking without an initial /*
+		if ($realfile !~ m@^(drivers/net/|net/)@ &&
+		    $prevrawline =~ /^\+[ \t]*\/\*.*[^ \t]$/ &&
+		    $rawline =~ /^\+[ \t]*\*/) {
+			WARN("MULTILINE_BLOCK_COMMENT_STYLE",
+			     "multi-line block comments should start with an empty /* line\n" . $hereprev);
+		}
+
 # Block comments use * on subsequent lines
 		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
 		    $prevrawline =~ /^\+.*?\/\*/ &&		#starting /*
-- 
2.42.0
Re: [PATCH] checkpatch: warn about multi-line comments without an empty /* line
Posted by Joe Perches 2 years, 4 months ago
On Tue, 2023-09-26 at 21:20 +0200, Petr Tesarik wrote:
> According to Documentation/process/coding-style.rst, the preferred style
> for multi-line comments outside net/ and drivers/net/ is:
> 
> .. code-block:: c
> 
>         /*
>          * This is the preferred style for multi-line
>          * comments in the Linux kernel source code.
>          * Please use it consistently.
>          *
>          * Description:  A column of asterisks on the left side,
>          * with beginning and ending almost-blank lines.
>          */
> 
> Signed-off-by: Petr Tesarik <petr@tesarici.cz>
> ---
>  scripts/checkpatch.pl | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7d16f863edf1..0fc3427a9ec9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4006,6 +4006,14 @@ sub process {
>  			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
>  		}
>  
> +# Non-networking without an initial /*
> +		if ($realfile !~ m@^(drivers/net/|net/)@ &&
> +		    $prevrawline =~ /^\+[ \t]*\/\*.*[^ \t]$/ &&
> +		    $rawline =~ /^\+[ \t]*\*/) {
> +			WARN("MULTILINE_BLOCK_COMMENT_STYLE",
> +			     "multi-line block comments should start with an empty /* line\n" . $hereprev);
> +		}
> +

Nack.

There are _way_ too many uses without an initial /* blank line
that are perfectly acceptable style.

$ git grep '/\*.*' -- '*.[ch]' | \
  grep -v '/\*.*\*/' | \
  grep -v -P "/\*\s*$" | \
  grep -v '/\*\*' | \
  grep -v "SPDX-License" | \
  grep -v -P '^drivers/net|^net/' | \
  wc -l
51834
Re: [PATCH] checkpatch: warn about multi-line comments without an empty /* line
Posted by Petr Tesařík 2 years, 4 months ago
V Tue, 26 Sep 2023 21:20:06 +0200
Petr Tesarik <petr@tesarici.cz> napsáno:

> According to Documentation/process/coding-style.rst, the preferred style
> for multi-line comments outside net/ and drivers/net/ is:
> 
> .. code-block:: c
> 
>         /*
>          * This is the preferred style for multi-line
>          * comments in the Linux kernel source code.
>          * Please use it consistently.
>          *
>          * Description:  A column of asterisks on the left side,
>          * with beginning and ending almost-blank lines.
>          */
> 
> Signed-off-by: Petr Tesarik <petr@tesarici.cz>
> ---
>  scripts/checkpatch.pl | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7d16f863edf1..0fc3427a9ec9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4006,6 +4006,14 @@ sub process {
>  			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
>  		}
>  
> +# Non-networking without an initial /*
> +		if ($realfile !~ m@^(drivers/net/|net/)@ &&
> +		    $prevrawline =~ /^\+[ \t]*\/\*.*[^ \t]$/ &&
> +		    $rawline =~ /^\+[ \t]*\*/) {
> +			WARN("MULTILINE_BLOCK_COMMENT_STYLE",

Oops. This should be just BLOCK_COMMENT_STYLE, without MULTILINE; v2 is
on the way...

Petr T

> +			     "multi-line block comments should start with an empty /* line\n" . $hereprev);
> +		}
> +
>  # Block comments use * on subsequent lines
>  		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
>  		    $prevrawline =~ /^\+.*?\/\*/ &&		#starting /*