From: Julia Lawall <julia.lawall@inria.fr>
To: Joe Perches <joe@perches.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 00/30] fix typos in comments
Date: Tue, 15 Mar 2022 08:11:30 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.22.394.2203150803540.2907@hadrien> (raw)
In-Reply-To: <b9c4dba1af41d8ef618267a1bd2a8497b3aa51a9.camel@perches.com>
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
On Mon, 14 Mar 2022, Joe Perches wrote:
> Care to describe _how_ coccinelle was helpful in finding
> these typos in comments?
First, Coccinelle can bind a metavariable to the comments before, within
and after anohter kind of term. So I collected the comments before,
within, and after statements and declarations.
Second, I also used Coccinelle to collect all of the identifiers
referenced in the same file, and discarded all of these words from
consideration.
Otherwise, it's the python library enchant for a dictionary, and some
hacks to reduce the number of false positives, including dropping words
that occur multiple times. The results are still maybe 90% false
positives, though.
The semantic patch is attached. It gives around 30K results for the
current linux-next.
julia
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-python; name=nlp2.py, Size: 255 bytes --]
from __future__ import print_function
from nltk.stem import *
from sys import argv
import enchant
d = enchant.Dict("en_US")
with open(argv[1]) as f:
for line in f:
word = line.split()[0]
if not(d.check(word)):
print(word)
[-- Attachment #3: Type: text/plain, Size: 2839 bytes --]
@initialize:ocaml@
@@
let seen = Hashtbl.create 101
let bseen = Hashtbl.create 101
let wseen = Hashtbl.create 101
let ids = Hashtbl.create 101
exception NotOK
let okw = ["aren";"isn";"wasn";"doesn";"didn";"weren";"shouldn";"couldn";"wouldn";"hasn";"haven";"linux";"hotplug";"cpu";"ifdef";"ifndef";"endif";"struct"]
let add i =
(if not (Hashtbl.mem ids i) then Hashtbl.add ids i ());
let pieces = Str.split (Str.regexp "_") i in
List.iter
(fun i -> if not (Hashtbl.mem ids i) then Hashtbl.add ids i ())
pieces;
false
let hasvowel s =
let vowels = ['a';'e';'i';'o';'u';'y';'A';'E';'I';'O';'U';'Y'] in
try
String.iter
(fun c ->
if List.mem c vowels
then raise NotOK)
s;
false
with NotOK -> true
let only_letters s =
let islower c = 'a' <= c && c <= 'z' in
let isupper c = 'A' <= c && c <= 'Z' in
try
String.iteri
(fun i c ->
let ok =
if i = 0
then islower c || isupper c
else islower c in
if not ok
then raise NotOK)
s;
true
with NotOK -> false
let check bad loc p c =
if not(Hashtbl.mem seen c)
then
begin
Hashtbl.add seen c ();
let pieces = Str.split (Str.regexp "\\b") c in
List.iter
(fun word ->
if String.length word <= 2 || not(only_letters word) || Hashtbl.mem ids word || List.mem word !bad || not(hasvowel word)
then ()
else
let word = String.uncapitalize_ascii word in
if List.mem word okw
then ()
else
let res =
try Hashtbl.find wseen word
with Not_found ->
let cmd =
Printf.sprintf "python spell.py %s" word in
let v = Common.cmd_to_list cmd in
Hashtbl.add wseen word v;
v in
List.iter
(fun wd ->
bad := word :: !bad;
Common.hashadd bseen word (loc,word,p))
res)
pieces
end
@script:ocaml@
@@
Hashtbl.clear seen
@identifier@
identifier i : script:ocaml() { add i };
@@
i
@r1@
comments c;
statement S;
position p;
@@
S@c@p
@script:ocaml@
c << r1.c;
p << r1.p;
@@
let bad = ref [] in
List.iter
(function c->
let (cb,ci,ca) = c in
List.iter (check bad "before" p) cb;
List.iter (check bad "within" p) ci;
List.iter (check bad "after" p) ca)
c
@r2@
comments c;
declaration d;
position p;
@@
d@c@p
@script:ocaml@
c << r2.c;
p << r2.p;
@@
let bad = ref [] in
List.iter
(function c->
let (cb,ci,ca) = c in
List.iter (check bad "before" p) cb;
List.iter (check bad "within" p) ci;
List.iter (check bad "after" p) ca)
c
@finalize:ocaml@
bseen << merge.bseen;
@@
List.iter
(fun bseen ->
Hashtbl.iter
(fun word l ->
match !l with
[(loc,word,p)] ->
Coccilib.print_main
(Printf.sprintf "problem with %s comment word: %s" loc word)
p
| _ -> ())
bseen)
bseen
next prev parent reply other threads:[~2022-03-15 7:11 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 11:53 Julia Lawall
2022-03-14 11:53 ` [PATCH 01/30] drm/amd/pm: " Julia Lawall
2022-03-15 15:48 ` Alex Deucher
2022-03-14 11:53 ` [PATCH 02/30] scsi: lpfc: " Julia Lawall
2022-03-14 11:53 ` [PATCH 03/30] ath6kl: " Julia Lawall
2022-03-18 15:39 ` Kalle Valo
2022-03-14 11:53 ` [PATCH 04/30] kernfs: " Julia Lawall
2022-03-14 11:53 ` [PATCH 05/30] x86/platform/uv: " Julia Lawall
2022-03-14 18:03 ` Ernst, Justin
2022-03-14 11:53 ` [PATCH 06/30] drm/bridge: analogix_dp: " Julia Lawall
2022-03-14 11:53 ` [PATCH 07/30] staging: rtl8723bs: " Julia Lawall
2022-03-14 11:53 ` [PATCH 08/30] leds: pca963x: " Julia Lawall
2022-03-14 11:53 ` [PATCH 09/30] media: i2c: ov5695: " Julia Lawall
2022-04-14 8:48 ` Sakari Ailus
2022-03-14 11:53 ` [PATCH 10/30] mt76: mt7915: " Julia Lawall
2022-03-14 11:53 ` [PATCH 11/30] usb: gadget: udc: " Julia Lawall
2022-03-14 11:53 ` [PATCH 12/30] drivers: net: packetengines: " Julia Lawall
2022-03-14 17:06 ` Jakub Kicinski
2022-03-14 17:13 ` Julia Lawall
2022-03-14 11:53 ` [PATCH 13/30] UBI: block: " Julia Lawall
2022-03-14 11:53 ` [PATCH 14/30] clk: ti: clkctrl: " Julia Lawall
2022-03-15 22:48 ` Stephen Boyd
2022-03-14 11:53 ` [PATCH 15/30] clk: qcom: sm6125-gcc: " Julia Lawall
2022-03-15 22:49 ` Stephen Boyd
2022-03-14 11:53 ` [PATCH 16/30] drm/sti: " Julia Lawall
2022-03-14 14:59 ` Alain Volmat
2022-03-14 11:53 ` [PATCH 17/30] scsi: elx: libefc_sli: " Julia Lawall
2022-03-14 11:53 ` [PATCH 18/30] devres: " Julia Lawall
2022-03-14 11:53 ` [PATCH 19/30] rtlwifi: rtl8821ae: " Julia Lawall
2022-03-15 0:29 ` Pkshih
2022-03-16 15:31 ` Kalle Valo
2022-03-14 11:53 ` [PATCH 20/30] airo: " Julia Lawall
2022-03-14 11:53 ` [PATCH 21/30] spi: sun4i: " Julia Lawall
2022-03-14 14:35 ` Chen-Yu Tsai
2022-03-14 11:53 ` [PATCH 22/30] RDMA/hw/qib/qib_iba7220: " Julia Lawall
2022-03-15 0:14 ` Jason Gunthorpe
2022-03-14 11:53 ` [PATCH 23/30] drm/amdgpu/dc: " Julia Lawall
2022-03-15 15:51 ` Alex Deucher
2022-03-14 11:53 ` [PATCH 24/30] scsi: qla2xxx: " Julia Lawall
2022-03-14 11:53 ` [PATCH 25/30] treewide: " Julia Lawall
2022-03-14 11:53 ` [PATCH 26/30] s390/pkey: " Julia Lawall
2022-03-14 11:53 ` [PATCH 27/30] can: ucan: " Julia Lawall
2022-03-14 12:05 ` Marc Kleine-Budde
2022-03-14 13:03 ` Julia Lawall
2022-03-14 13:36 ` Marc Kleine-Budde
2022-03-14 11:53 ` [PATCH 28/30] mfd: bd9576: " Julia Lawall
2022-03-15 10:13 ` Vaittinen, Matti
2022-03-22 7:28 ` Lee Jones
2022-03-14 11:53 ` [PATCH 29/30] drm/amdgpu: " Julia Lawall
2022-03-15 15:50 ` Alex Deucher
2022-03-14 11:53 ` [PATCH 30/30] perf/core: " Julia Lawall
2022-03-17 3:09 ` Ian Rogers
2022-03-14 20:30 ` [PATCH 00/30] " patchwork-bot+netdevbpf
2022-03-15 4:33 ` Martin K. Petersen
2022-03-15 5:35 ` Joe Perches
2022-03-15 7:11 ` Julia Lawall [this message]
2022-03-15 13:40 ` (subset) " Mark Brown
2022-03-19 3:56 ` Martin K. Petersen
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=alpine.DEB.2.22.394.2203150803540.2907@hadrien \
--to=julia.lawall@inria.fr \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.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®