From nobody Tue Feb 10 15:29:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633096903; cv=none; d=zohomail.com; s=zohoarc; b=eCCVW0ymYWckCzzeTZC2qpQvvHFsHBKuvmupWmceOjH6AKQeimOS450+RWy7QrFsLmVf4c3W8hkMWaS24BK4QnMpb7u1qXzvtohuVEI6a2IOQqOWl4T5+lLgwAGUrhh+OxlF4iEWaDmiX0VAmyKmQcxqhgIG/q8djtvCQYgGVAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633096903; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=H47diNviI07NFTzvMrkpZpdMT9dl8Sxt9rAeC//mqFY=; b=IwHpm7DT1C4dO+5gERQ1L8GshEEYKKWnJaQs6jObMtnL6qz+z536Hrn50FDP6b/o1wFeLkFzIprvsWD88+bnOvi2PkHRevPQH2ztMLNxuzHeSttg9yMCTGLh4k9DLyAhgkSYTcw0/cn6XwVrf9a3OvOeRcVtzTzj6FCc6RNvtaY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633096903290378.7781957946812; Fri, 1 Oct 2021 07:01:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-R4z7OAQjNwKhmJsV3kiomA-1; Fri, 01 Oct 2021 10:01:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83A09814614; Fri, 1 Oct 2021 14:01:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBC8710016FF; Fri, 1 Oct 2021 14:01:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 96FA64EA2A; Fri, 1 Oct 2021 14:01:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 191E1FV6014518 for ; Fri, 1 Oct 2021 10:01:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3ACE460E1C; Fri, 1 Oct 2021 14:01:15 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.193.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5403260CD1; Fri, 1 Oct 2021 14:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633096902; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=H47diNviI07NFTzvMrkpZpdMT9dl8Sxt9rAeC//mqFY=; b=hFit+4d8rNJ+6gvAQEY/xBIiKIJel9Mh1T9omS3T+DNNXktRvH8G+YccDLAoO7dlwmtNKw fHvEKe4n+QTarwpD8LimwCl4d5GmWwrb9c1aAt3KEv45deLrkM/0nmjX2mfDCU49E7GNC1 6Cop7oRgYxEChB/4U545kx4fNzYUC9s= X-MC-Unique: R4z7OAQjNwKhmJsV3kiomA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH] [RFC] scripts: Check spelling Date: Fri, 1 Oct 2021 16:00:18 +0200 Message-Id: <20211001140018.16179-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633096920914100001 Content-Type: text/plain; charset="utf-8" This is a wrapper for codespell [1], a spell checker for source code. Codespell does not compare words to a dictionary, but rather works by checking words against a list of common typos, making it produce fewer false positives than other solutions. The script in this patch works around the lack of per-directory ignore lists and some oddities regarding capitalization in ignore lists. [1] (https://github.com/codespell-project/codespell/) RFC: Is there interest in having something like this in CI? Examples of spelling mistakes that were found using codespell: 4ad3c95f4bef5c7c9657de470fb74a4d14c8a331, 785a11cec8693de7df024aae68975dd1799b646a, 1452317b5c727eb17178942012f57f0c37631ae4. Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- scripts/check-spelling.py | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 scripts/check-spelling.py diff --git a/scripts/check-spelling.py b/scripts/check-spelling.py new file mode 100755 index 0000000000..01371c0d1e --- /dev/null +++ b/scripts/check-spelling.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 + +import argparse +import re +import subprocess +import os + + +IGNORE_LIST =3D [ + # ignore all translation files + ("/po/", []), + + # ignore this script + ("/scripts/check-spelling.py", []), + + # 3rd-party: keycodemapdb + ("/src/keycodemapdb/", []), + + # 3rd-party: VirtualBox SDK + ("/src/vbox/vbox_CAPI", [ + "aAdd", + "aCount", + "aLocation", + "aNumber", + "aParent", + "progess"]), + + # 3rd-party: qemu + ("/tests/qemucapabilitiesdata/caps_", "encyption"), + + # other + ("/", ["msdos", "MSDOS", "wan", "WAN", "hda", "HDA", "inout"]), + ("/NEWS.rst", ["crashers"]), + ("/docs/gitdm/companies/others", "Archiv"), + ("/docs/glib-adoption.rst", ["preferrable"]), + ("/docs/js/main.js", "whats"), + ("/examples/polkit/libvirt-acl.rules", ["userA", "userB", "userC"]), + ("/src/libvirt-domain.c", "PTD"), + ("/src/libxl/libxl_logger.c", ["purposedly"]), + ("/src/nwfilter/nwfilter_dhcpsnoop.c", "ether"), + ("/src/nwfilter/nwfilter_ebiptables_driver.c", "parm"), + ("/src/nwfilter/nwfilter_learnipaddr.c", "ether"), + ("/src/qemu/qemu_agent.c", "crypted"), + ("/src/qemu/qemu_agent.h", "crypted"), + ("/src/security/apparmor/libvirt-lxc", "devic"), + ("/src/security/apparmor/libvirt-qemu", "readby"), + ("/src/storage_file/storage_file_probe.c", "conectix"), + ("/src/util/virnetdevmacvlan.c", "calld"), + ("/src/util/virtpm.c", "parm"), + ("/tests/qemuagenttest.c", "IST"), + ("/tests/storagepoolxml2xml", "cant"), + ("/tests/sysinfodata/", ["sie"]), + ("/tests/testutils.c", ["nIn"]), + ("/tests/vircgroupdata/ovirt-node-6.6.mounts", "hald"), + ("/tests/virhostcpudata/", ["sie"]), + ("/tools/virt-host-validate-common.c", ["sie"]), +] + + +def check_spelling(directory): + """Returns list of tuple(filename, line number, word, suggestion).""" + process =3D subprocess.run( + ["codespell", directory], + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.PIPE, + universal_newlines=3DTrue) + + if process.returncode not in (0, 65): + exit("error: unexpected returncode %s" % process.returncode) + + if process.stderr: + exit("error: unexpected output to stderr: \"%s\"" % process.stderr) + + line_pattern =3D re.compile("^(.*):(.*): (.*) =3D=3D> (.*)$") + for line in process.stdout.split("\n"): + line =3D line.strip().replace(directory, "") + if not line: + continue + match =3D line_pattern.match(line) + if not match: + exit("error: unexpected line: \"%s\"" % line) + yield match.groups() + + +def ignore(filename, linenumber, word, suggestion): + # Ignore abbreviations and ad-hoc variable names + if len(word) <=3D 2: + return True + + for f, w in IGNORE_LIST: + if not filename.startswith(f): + continue + if word in w or not w: + return True + return False + + +def main(): + parser =3D argparse.ArgumentParser(description=3D"Check spelling") + parser.add_argument( + "dir", + help=3D"Path to source directory", + type=3Dos.path.realpath) + args =3D parser.parse_args() + + findings =3D [f for f in check_spelling(args.dir) if not ignore(*f)] + if findings: + template =3D "(\"{0}\", \"{2}\"),\t# line {1}, \"{3}\"?" + for finding in findings: + print(template.format(*finding)) + exit("error: %s spelling errors" % len(findings)) + + +if __name__ =3D=3D "__main__": + main() --=20 2.31.1