[PATCH v6 4/4] checkpatch: warn on empty rust doc comments

From: Hridesh MG
Date: Tue Oct 15 2024 - 11:53:11 EST


Add a check to warn if there are consecutive empty `///` lines in rust
files.

Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1109
Signed-off-by: Hridesh MG <hridesh699@xxxxxxxxx>
---
v2: https://lore.kernel.org/rust-for-linux/7877d23adba22e2f89a61efc129ecf1b0627510b.1726072795.git.hridesh699@xxxxxxxxx/
- new patch
v3: https://lore.kernel.org/rust-for-linux/bf6544faba2b53ce901b2e031f3d944babcc7018.1727606659.git.hridesh699@xxxxxxxxx/
- no changes
v6:
- added --fix support which deletes the unnecessary line
---
scripts/checkpatch.pl | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c390a9926cd5..baadc345bf87 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3911,6 +3911,15 @@ sub process {
$fixed[$fixlinenr] =~ s/\b$header\b/ucfirst(lc($header)) . 's'/e;
}
}
+
+ # check for consecutive empty rustdoc lines
+ if ($rawline =~ /^\+\s*\/\/\/$/ && $prevrawline =~ /^\+?\s*\/\/\/$/) {
+ if (WARN("RUST_DOC_EMPTY",
+ "avoid using consecutive empty rustdoc comments\n" . $herecurr) &&
+ $fix) {
+ fix_delete_line($fixlinenr, $rawline);
+ }
+ }
}

# check we are in a valid source file C or perl if not then ignore this hunk
--
2.46.1