mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>
Cc: Randy Dunlap <rdunlap@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] checkpatch: Add test for repeated words
Date: Mon, 27 Jul 2020 00:33:42 -0700	[thread overview]
Message-ID: <cda9b566ad67976e1acd62b053de50ee44a57250.camel@perches.com> (raw)
In-Reply-To: <16aa5f86f2f899a9156305ead4b7042449278eea.camel@perches.com>

Try to avoid adding repeated words either on the
same line or consecutive comment lines in a block

e.g.:

duplicated word in comment block

	/*
	 * this is a comment block where the last word of the previous
	 * previous line is also the first word of the next line
	 */

and simple duplication

	/* test this this again */

Inspired-by: Randy Dunlap (rdunlap@infradead.org>
Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e9fde28eb0de..c6ef76b72bf3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -591,6 +591,8 @@ our @mode_permission_funcs = (
 	["__ATTR", 2],
 );
 
+my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
+
 #Create a search pattern for all these functions to speed up a loop below
 our $mode_perms_search = "";
 foreach my $entry (@mode_permission_funcs) {
@@ -3340,6 +3342,42 @@ sub process {
 			}
 		}
 
+# check for repeated words separated by a single space
+		if ($rawline =~ /^\+/) {
+			while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
+
+				my $first = $1;
+				my $second = $2;
+
+				if ($first =~ /(?:struct|union|enum)/) {
+					pos($rawline) += length($first) + length($second) + 1;
+					next;
+				}
+
+				next if ($first ne $second);
+				next if ($first eq 'long');
+
+				if (WARN("REPEATED_WORD",
+					 "Possible repeated word: '$first'\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
+				}
+			}
+
+			# if it's a repeated word on consecutive lines in a comment block
+			if ($prevline =~ /$;+\s*$/ &&
+			    $prevrawline =~ /($word_pattern)\s*$/) {
+				my $last_word = $1;
+				if ($rawline =~ /^\+\s*\*\s*$last_word /) {
+					if (WARN("REPEATED_WORD",
+						 "Possible repeated word: '$last_word'\n" . $hereprev) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
+					}
+				}
+			}
+		}
+
 # check for space before tabs.
 		if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
 			my $herevet = "$here\n" . cat_vet($rawline) . "\n";



  reply	other threads:[~2020-07-27  7:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-26  0:38 [PATCH 0/9] powerpc: delete duplicated words Randy Dunlap
2020-07-26  0:38 ` [PATCH 1/9] powerpc: book3s: mmu-hash.h: delete duplicated word Randy Dunlap
2020-07-26  0:38 ` [PATCH 2/9] powerpc: book3s: radix-4k.h: " Randy Dunlap
2020-07-26  0:38 ` [PATCH 3/9] powerpc: cputime.h: " Randy Dunlap
2020-07-26  0:38 ` [PATCH 4/9] powerpc: epapr_hcalls.h: delete duplicated words Randy Dunlap
2020-07-26  0:38 ` [PATCH 5/9] powerpc: hw_breakpoint.h: delete duplicated word Randy Dunlap
2020-07-26  0:38 ` [PATCH 6/9] powerpc: ppc_asm.h: " Randy Dunlap
2020-07-26  0:38 ` [PATCH 7/9] powerpc: reg.h: " Randy Dunlap
2020-07-26  0:38 ` [PATCH 8/9] powerpc: smu.h: " Randy Dunlap
2020-07-26  0:38 ` [PATCH 9/9] powerpc: powernv: pci.h: " Randy Dunlap
2020-07-26 14:29 ` [PATCH 0/9] powerpc: delete duplicated words Christophe Leroy
2020-07-26 17:23   ` Randy Dunlap
2020-07-26 17:49     ` Joe Perches
2020-07-26 19:08       ` Randy Dunlap
2020-07-26 20:48         ` Joe Perches
2020-07-27  6:51         ` Joe Perches
2020-07-27  7:33           ` Joe Perches [this message]
2020-07-28  0:03             ` [PATCH] checkpatch: Add test for repeated words Randy Dunlap
2020-07-28  1:25               ` Joe Perches
2020-07-26 23:55     ` [PATCH 0/9] powerpc: delete duplicated words Michael Ellerman
2020-07-27  7:26 ` Michael Ellerman

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=cda9b566ad67976e1acd62b053de50ee44a57250.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    /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

all inboxes | Powered by JetHome®