From: Patrick Miller <paddymills@proton.me>
To: "Andy Whitcroft" <apw@canonical.com>,
"Joe Perches" <joe@perches.com>,
"Dwaipayan Ray" <dwaipayanray1@gmail.com>,
"Lukas Bulwahn" <lukas.bulwahn@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Cc: Patrick Miller <paddymills@proton.me>, Hridesh MG <hridesh699@gmail.com>
Subject: [PATCH v5 2/2] checkpatch: warn on known non-plural rust doc headers and empty doc comments
Date: Wed, 02 Oct 2024 02:29:03 +0000 [thread overview]
Message-ID: <20241002022749.390836-2-paddymills@proton.me> (raw)
In-Reply-To: <20241002022749.390836-1-paddymills@proton.me>
[-- Attachment #1: Type: text/plain, Size: 3556 bytes --]
Adds a check for documentation in rust file. Warns if certain known
documentation headers are not plural.
The rust maintainers prefer document headers to be plural. This is to
enforce consistency among the documentation as well as to protect against
errors when additions are made. For example, if the header said "Example"
because there was only 1 example, if a second example was added, making
the header plural could easily be missed and the maintainers prefer to
not have to remind people to fix their documentation.
This revision also merges Hridesh MG's [1] patch to check for consecutive
empty doc comments. This checks and warns against consecutive empty `///`
lines in rust files.
[1]: https://lore.kernel.org/rust-for-linux/CALiyAo=ZdFy0bR03NndODmE7vP_JRzxs52-z=iXKQbO_Z6rtYg@mail.gmail.com/T/#u
Signed-off-by: Patrick Miller <paddymills@proton.me>
Co-developed-by: Hridesh MG <hridesh699@gmail.com>
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Suggested-by: Trevor
Gross <tmgross@umich.edu>
Link: https://github.com/Rust-for-Linux/linux/issues/1110
Link: https://github.com/Rust-for-Linux/linux/issues/1109
---
v1: https://lore.kernel.org/rust-for-linux/2024090628-bankable-refusal-5f20@gregkh/T/#t
v2: https://lore.kernel.org/rust-for-linux/92be0b48-cde9-4241-8ef9-7fe4d7c42466@proton.me/T/#t
- fixed whitespace that was formatted due to editor settings
v3: https://lore.kernel.org/rust-for-linux/da34f89c-f94c-43aa-946c-57fec3597974@proton.me/T/#t
- move && to previous line and remove whitespace in WARN per Joe Perches
- reformat following C coding style
v4: https://lore.kernel.org/rust-for-linux/20240914181618.837227-2-paddymills@proton.me/
- add @fix option (credit: Joe Perches)
- add Error to list of checked section headers
- make check for rust file its own if statement because more rust
checks are planned
v5:
- merged Hridesh MG's patch[2] to check against consecutive rustdoc comments
- revised Hridesh MG's
patch to match against $prevrawline being new
or existing
- added fix to Hridesh MG's patch
[2]: https://lore.kernel.org/rust-for-linux/CALiyAo=ZdFy0bR03NndODmE7vP_JRzxs52-z=iXKQbO_Z6rtYg@mail.gmail.com/T/#m5afd633dc96ba366bbfd3d168c43d3a2a53b9198
scripts/checkpatch.pl | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 39032224d504..080b0eebde0a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3900,6 +3900,26 @@ sub process {
"Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/core-api/asm-annotations.rst\n" . $herecurr);
}
+# checks for rust files
+ if ($realfile =~ /\.rs$/) {
+# check that document section headers are plural in rust files
+ if ($rawline =~ /^\+\s*\/\/\/\s+#+\s+(Example|Error|Guarantee|Invariant|Panic)\s*$/i) {
+ if (WARN("RUST_DOC_HEADER",
+
"Rust doc section names should be plural\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] = s/\b$1\b/ucfirst(lc($1))/e;
+ }
+ }
+# check for consecutive empty doc comment 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
next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
--
2.46.2
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]
next prev parent reply other threads:[~2024-10-02 2:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 2:28 [PATCH v5 1/2] docs: rust: make section names plural Patrick Miller
2024-10-02 2:29 ` Patrick Miller [this message]
2024-10-02 11:56 ` [PATCH v5 2/2] checkpatch: warn on known non-plural rust doc headers and empty doc comments Miguel Ojeda
2024-10-02 12:28 ` Joe Perches
2024-10-02 12:31 ` Hridesh Mg
2024-10-02 12:46 ` Miguel Ojeda
2025-05-26 18:44 ` [PATCH v5 1/2] docs: rust: make section names plural Miguel Ojeda
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=20241002022749.390836-2-paddymills@proton.me \
--to=paddymills@proton.me \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apw@canonical.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dwaipayanray1@gmail.com \
--cc=gary@garyguo.net \
--cc=hridesh699@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).