From: SeongJae Park <sjpark@amazon.com>
To: <akpm@linux-foundation.org>, <apw@canonical.com>, <joe@perches.com>
Cc: SeongJae Park <sjpark@amazon.de>, <colin.king@canonical.com>,
<sj38.park@gmail.com>, <jslaby@suse.cz>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v4 1/2] checkpatch: support deprecated terms checking
Date: Thu, 11 Jun 2020 08:25:49 +0200 [thread overview]
Message-ID: <20200611062550.20113-2-sjpark@amazon.com> (raw)
In-Reply-To: <20200611062550.20113-1-sjpark@amazon.com>
From: SeongJae Park <sjpark@amazon.de>
Some terms could be deprecated for various reasons, but it is hard to
update the entire old usages. That said, we could at least encourage
new patches to use the suggested replacements. This commit adds check
of deprecated terms in the 'checkpatch.pl' for that. The script will
get deprecated terms and suggested replacements of those from
'scripts/deprecated_terms.txt' file and warn if the deprecated terms are
used. The mechanism and the format of the file are almost the same as
that of 'spelling.txt'. For the reason, this commit modularizes the
read of the 'spelling.txt' and reuses.
Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
scripts/checkpatch.pl | 60 +++++++++++++++++++++++++++---------
scripts/deprecated_terms.txt | 5 +++
2 files changed, 50 insertions(+), 15 deletions(-)
create mode 100644 scripts/deprecated_terms.txt
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 524df88f9364..c672091932bb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -57,6 +57,7 @@ my $max_line_length = 100;
my $ignore_perl_version = 0;
my $minimum_perl_version = 5.10.0;
my $min_conf_desc_length = 4;
+my $deprecated_terms_file = "$D/deprecated_terms.txt";
my $spelling_file = "$D/spelling.txt";
my $codespell = 0;
my $codespellfile = "/usr/share/codespell/dictionary.txt";
@@ -692,29 +693,40 @@ our $allowed_asm_includes = qr{(?x:
)};
# memory.h: ARM has a custom one
-# Load common spelling mistakes and build regular expression list.
-my $misspellings;
-my %spelling_fix;
+sub read_word_corrections {
+ my ($file, $fixesRef) = @_;
+ my $suspects;
-if (open(my $spelling, '<', $spelling_file)) {
- while (<$spelling>) {
- my $line = $_;
+ if (open(my $corrections, '<', $file)) {
+ while (<$corrections>) {
+ my $line = $_;
- $line =~ s/\s*\n?$//g;
- $line =~ s/^\s*//g;
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
- next if ($line =~ m/^\s*#/);
- next if ($line =~ m/^\s*$/);
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
- my ($suspect, $fix) = split(/\|\|/, $line);
+ my ($suspect, $fix) = split(/\|\|/, $line);
- $spelling_fix{$suspect} = $fix;
+ $fixesRef->{$suspect} = $fix;
+ }
+ close($corrections);
+ } else {
+ warn "No correction will be found - file '$file': $!\n";
}
- close($spelling);
-} else {
- warn "No typos will be found - file '$spelling_file': $!\n";
}
+# Load deprecated terms and build regular expression list.
+my %deprecated_terms_fix;
+read_word_corrections($deprecated_terms_file, \%deprecated_terms_fix);
+my $deprecated_terms = join("|", sort keys %deprecated_terms_fix) if keys %deprecated_terms_fix;
+
+# Load common spelling mistakes and build regular expression list.
+my $misspellings;
+my %spelling_fix;
+read_word_corrections($spelling_file, \%spelling_fix);
+
if ($codespell) {
if (open(my $spelling, '<', $codespellfile)) {
while (<$spelling>) {
@@ -2957,6 +2969,24 @@ sub process {
}
}
+# Check for deprecated terms
+ if (defined($deprecated_terms) &&
+ ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
+ while ($rawline =~ /(?:^|[^a-z@])($deprecated_terms)(?:\b|$|[^a-z@])/gi) {
+ my $deprecated_term = $1;
+ my $suggested = $deprecated_terms_fix{lc($deprecated_term)};
+ $suggested = ucfirst($suggested) if ($deprecated_term=~ /^[A-Z]/);
+ $suggested = uc($suggested) if ($deprecated_term =~ /^[A-Z]+$/);
+ my $msg_level = \&WARN;
+ $msg_level = \&CHK if ($file);
+ if (&{$msg_level}("DEPRECATED_TERM",
+ "Use of '$deprecated_term' is deprecated, please '$suggested', instead.\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($deprecated_term)($|[^A-Za-z@])/$1$suggested$3/;
+ }
+ }
+ }
+
# Check for various typo / spelling mistakes
if (defined($misspellings) &&
($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
diff --git a/scripts/deprecated_terms.txt b/scripts/deprecated_terms.txt
new file mode 100644
index 000000000000..6faa06451c3d
--- /dev/null
+++ b/scripts/deprecated_terms.txt
@@ -0,0 +1,5 @@
+# License: GPLv2
+#
+# The format of each line is:
+# deprecated||suggested
+#
--
2.17.1
next prev parent reply other threads:[~2020-06-11 6:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 6:25 [PATCH v4 0/2] Recommend denylist/allowlist instead of blacklist/whitelist SeongJae Park
2020-06-11 6:25 ` SeongJae Park [this message]
2020-07-25 13:02 ` checkpatch: support deprecated terms checking Michał Mirosław
2020-07-25 16:36 ` Joe Perches
2020-07-25 17:29 ` Joe Perches
2020-07-25 23:35 ` SeongJae Park
2020-07-26 4:27 ` Joe Perches
2020-07-26 7:18 ` SeongJae Park
2020-07-26 7:29 ` Joe Perches
2020-07-26 7:45 ` SeongJae Park
2020-07-26 14:50 ` Joe Perches
2020-07-26 15:36 ` SeongJae Park
2020-07-26 16:42 ` Joe Perches
2020-07-26 18:07 ` SeongJae Park
2020-07-26 20:33 ` Michał Mirosław
2020-07-27 6:54 ` SeongJae Park
2020-07-27 20:44 ` Andrew Morton
2020-07-27 20:49 ` Joe Perches
2020-07-28 6:22 ` SeongJae Park
2020-06-11 6:25 ` [PATCH v4 2/2] scripts/deprecated_terms: Recommend denylist/allowlist instead of blacklist/whitelist SeongJae Park
2020-06-11 6:35 ` [PATCH v4 0/2] " Joe Perches
2020-06-11 7:38 ` SeongJae Park
2020-06-11 8:16 ` Jiri Slaby
2020-06-11 8:30 ` SeongJae Park
2020-06-11 8:32 ` Jiri Slaby
2020-06-11 10:43 ` Joe Perches
2020-06-12 6:40 ` SeongJae Park
2020-06-12 7:05 ` Joe Perches
2020-06-12 14:40 ` Michael Ellerman
2020-06-14 21:29 ` Pavel Machek
2020-06-15 4:21 ` Jiri Slaby
2020-06-15 6:12 ` Pavel Machek
2020-06-15 6:46 ` SeongJae Park
2020-06-15 7:00 ` Joe Perches
2020-06-15 7:39 ` Pavel Machek
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=20200611062550.20113-2-sjpark@amazon.com \
--to=sjpark@amazon.com \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=colin.king@canonical.com \
--cc=joe@perches.com \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=sj38.park@gmail.com \
--cc=sjpark@amazon.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.