Re: Checking for space before ending comment tag

From: Joe Perches
Date: Sat Mar 19 2022 - 22:46:35 EST


Maybe this is better as it can fix them too.

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 577e029987011..70afa4ff2addf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3868,6 +3868,22 @@ sub process {
}
}

+# Single line comment style - warn when '/*comment */' or '/* comment*/'
+ if ($line =~ /^\+.*$;/ &&
+ $rawline =~ m@/\*.+\*/@ &&
+ (($rawline =~ m@/\* @ && $rawline =~ m@\w\*/@) ||
+ ($rawline =~ m@/\*\w@ && $rawline =~ m@ \*/@))) {
+ if (WARN("COMMENT_STYLE",
+ "Single line comments should use a space after /* and before */\n" . $herecurr) &&
+ $fix) {
+ $rawline =~ m@/\*.+\*/@;
+ my $comment = substr($rawline, $-[0], $+[0] - $-[0]);
+ my $newcomment = trim(substr($comment, 2, -2));
+ $fixed[$fixlinenr] =~
+ s@\Q$comment\E@/\* $newcomment \*/@;
+ }
+ }
+
# Block comment styles
# Networking with an initial /*
if ($realfile =~ m@^(drivers/net/|net/)@ &&