From: Kees Cook <keescook@chromium.org>
To: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Maxim Uvarov <maxim.uvarov@linaro.org>
Subject: Re: [PATCH] checkpatch: Avoid missing typo suggestions
Date: Thu, 4 Jun 2020 15:08:22 -0700 [thread overview]
Message-ID: <202006041503.C9BFD40255@keescook> (raw)
In-Reply-To: <a3c22bbd360d2148bf097d3c55a89ea13e07b719.camel@perches.com>
On Wed, Jun 03, 2020 at 05:39:47PM -0700, Joe Perches wrote:
> On Wed, 2020-06-03 at 16:19 -0700, Kees Cook wrote:
> > My codespell dictionary has a lot of capitalized words. For example:
> >
> > MSDOS->MS-DOS
> >
> > Since checkpatch uses case-insensitive matching, I get an undefined
> > variable warning and then empty suggestions for things like this:
> >
> > Use of uninitialized value $typo_fix in concatenation (.) or string at ./scripts/checkpatch.pl line 2958.
> >
> > WARNING: 'msdos' may be misspelled - perhaps ''?
> > + struct msdos_dir_entry *de;
> >
> > This fixes the matcher to avoid the warning, but it's still a rather
> > silly suggestion:
> >
> > WARNING: 'msdos' may be misspelled - perhaps 'MS-DOS'?
> > + struct msdos_dir_entry *de;
> >
> > So I'm not really sure what to do with this ... filter out bad
> > suggestions instead?
>
> Hey Kees.
>
> Maybe this?
>
> btw: My codespell dictionary file moved to
> /usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt
Yeah, mine too. I think I may have added a symlink to my filesystem to
work around this.
> and I had to use --codespell --codespellfile=(above) so
> maybe there should be multiple lookups for this file
> like the array below.
That seems like a good idea.
>
> Are there other standard codespell dictionary locations?
> ---
> scripts/checkpatch.pl | 31 ++++++++++++++++++++++++++-----
> 1 file changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 5f00df2c3f59..52aa0dd53d80 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -59,7 +59,7 @@ my $minimum_perl_version = 5.10.0;
> my $min_conf_desc_length = 4;
> my $spelling_file = "$D/spelling.txt";
> my $codespell = 0;
> -my $codespellfile = "/usr/share/codespell/dictionary.txt";
> +my $codespellfile;
> my $conststructsfile = "$D/const_structs.checkpatch";
> my $typedefsfile = "";
> my $color = "auto";
> @@ -716,7 +716,20 @@ if (open(my $spelling, '<', $spelling_file)) {
> }
>
> if ($codespell) {
> - if (open(my $spelling, '<', $codespellfile)) {
> + if (!defined($codespellfile)) {
> + my @csfiles = ("/usr/share/codespell/dictionary.txt",
> + "/usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt");
> + foreach my $csfile (@csfiles) {
> + if (-f $csfile) {
> + $codespellfile = $csfile;
> + last;
> + }
> + }
> + }
> +
> + if (!defined($codespellfile)) {
> + warn "No codespell typos will be found - codespell dictionary not found\n";
> + } elsif (open(my $spelling, '<', $codespellfile)) {
> while (<$spelling>) {
> my $line = $_;
>
> @@ -2963,13 +2976,21 @@ sub process {
> while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
> my $typo = $1;
> my $typo_fix = $spelling_fix{lc($typo)};
> - $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
> - $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
> + $typo_fix = $spelling_fix{$typo} if (!defined($typo_fix));
> + $typo_fix = $spelling_fix{uc($typo)} if (!defined($typo_fix));
This won't catch stuff like:
Cambrige->Cambridge
because neither "cambrige" nor "CAMBRIGE" is in %spelling_fix. And the
original text is lost due to the //i. :( I'm really not sure what to do
with these things in codespell. Lower case everything? Throw away
anything not all lower case?
--
Kees Cook
next prev parent reply other threads:[~2020-06-04 22:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-03 23:19 [PATCH] checkpatch: Avoid missing typo suggestions Kees Cook
2020-06-04 0:39 ` Joe Perches
2020-06-04 6:55 ` Maxim Uvarov
2020-06-04 7:29 ` Joe Perches
2020-06-04 14:45 ` Maxim Uvarov
2020-06-04 22:08 ` Kees Cook [this message]
2020-06-05 1:02 ` Joe Perches
2020-06-05 3:05 ` Kees Cook
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=202006041503.C9BFD40255@keescook \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maxim.uvarov@linaro.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 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.