checkpatch: Attempt to validate patch email subject lines
Joe Perches
maintainerRFC PATCH 1/1 checkpatch: Attempt to validate patch email subject lines
Patch subject lines should follow the form described in Documentation/process/submitting-patches.rst, so attempt to validate the "Subject: " lines.
Signed-off-by Joe Perches <[email protected]>
---
I tested it against the LKML "Subject:" lines I had around (attached as subjects.gz).
I believe it's OK as many of those subjects aren't really patches but acks and such.
Dunno if this works all that well, but perhaps it's a start.
Feedback welcomed.
scripts/checkpatch.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
scripts/checkpatch.pl +27 -0
@@ -860,6 +860,25 @@ sub is_SPDX_License_valid { return 1; } +sub validate_patch_subject { + my ($line) = @_; + + $line =~ s/^Subject:\s*//i; + + return 0 if ($line =~ /^\s*\[\s*git\s+pull\s*\]/i); + + # remove [RFC] or [TRIVIAL] prefix + $line =~ s/^\[\s*(?i:RFC|TRIVIAL)\s*\]\s*//; + + # not ok if unlike [<rfc|trivial> PATCH <some tree> <vN> <x/y>] + return -1 if (0 == $line =~ s/^\[(?:(?i:rfc\s+trivial|rfc|trivial\s+rfc|trivial)\s+)?PATCH(?:\s+(?i:(?i:v\d+\s+[a-z-]+|v\d+|[a-z-]+)\s*))?(?:\s*\d+\/\d+)?\]\s+//); + + # not ok if doesn't have 'subsystem:' + return -2 if (0 == $line =~ s/[\w\/\.\-]+:\s+//); + + return 0; +} + my $camelcase_seeded = 0; sub seed_camelcase_includes { return if ($camelcase_seeded);
@@ -2648,6 +2667,14 @@ sub process { "A patch subject line should describe the change not the tool that found it\n" . $herecurr); } +# Check email subject [PATCH] style + if ($in_header_lines && + $line =~ /^Subject:/i && + (my $error = validate_patch_subject($line)) < 0) { + WARN("PATCH_SUBJECT", + "A patch subject line should use the form described in 'Documentation/process/submitting-patches.rst'\n" . $herecurr); + } + # Check for unwanted Gerrit info if ($in_commit_log && $line =~ /^\s*change-id:/i) { ERROR("GERRIT_CHANGE_ID",