From nobody Wed Nov 27 04:40:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701677947; cv=none; d=zohomail.com; s=zohoarc; b=My1WjKdRWsGIALu2PzAogDT2Uoq1TqESN4YyfXvkA8onracbnWSM0re+4WCWfvFrtTVroFCMBD/S00AwcCESCXs5JmPAKLrVmV62BcVJKj1lbP+cTLNcmFti3Wf1STWDmwrcG0lwBBv9Ca4Gyb2iu4WZPhjzzDiLD15WQ3nqMHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701677947; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0KEaZjuVBRTrlfn/9my9JZiAF515YTzDuGTI5YUVGNM=; b=aQV1V4YjgV0L3+Ul+VA5d7NNPJro+679E5YH/pajV5YZUjuWyiOX8bOJRwjEy9klXTvxRRGIUGiXCGxGJfNft2XtWs30AsI3+zyOVy2BLWMRzkvCOVJeR+T/wrbTsmxFUWiY/xMWw0cMkUjJSsnAhVlUGqdMkx13J17IpVxKzC4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170167794724148.807197545083795; Mon, 4 Dec 2023 00:19:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rA49I-0003w1-2w; Mon, 04 Dec 2023 03:17:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rA49D-0003vV-U5; Mon, 04 Dec 2023 03:17:49 -0500 Received: from mgamail.intel.com ([198.175.65.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rA49A-0008Ln-Jx; Mon, 04 Dec 2023 03:17:46 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 00:17:17 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga001.jf.intel.com with ESMTP; 04 Dec 2023 00:17:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701677865; x=1733213865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FseLNrhRJQO2dldXL9Brgo7JAYGGDCtpqUTWRwEyuAo=; b=VkPyfF8QuNSWA80I3pcfiPCGDWvZGaJqzpYhoOvRcLkOrXRaccrZ46rj OnHme3PToMXM1EsoUrUSXXHte+AnANjszub4QlyiZvF8ij94axzuarUjt tDaSGHEpRaIG9M8qTkFM6zodN7F3/wCM5O3b3dvtY22T/ElGIlPnddXq7 5sYDXSRYO+A6d+eyqvE2F9DWDHyB39IuwTMGU/YyMx84RPP9QVvKiaCjX e1ur2d6Vmy/roPAX0bpDJgGaygv1uqYvkx5a2lrelQEmP3052anifkx0Q cr1zcj1CR5Dx+Gefe2hm3M9lw3mc1VVVTdjlIK8211I0UC041ArRyvbzZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10913"; a="581574" X-IronPort-AV: E=Sophos;i="6.04,249,1695711600"; d="scan'208";a="581574" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10913"; a="804829701" X-IronPort-AV: E=Sophos;i="6.04,249,1695711600"; d="scan'208";a="804829701" From: Zhao Liu To: Michael Tokarev , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Thomas Huth , Richard Henderson , qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Zhenyu Wang , Zhao Liu Subject: [RFC 2/3] scripts/checkpatch: Add --codespell and --codespellfile options Date: Mon, 4 Dec 2023 16:29:16 +0800 Message-Id: <20231204082917.2430223-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204082917.2430223-1-zhao1.liu@linux.intel.com> References: <20231204082917.2430223-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=198.175.65.11; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1701677949239100003 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Add two spelling check options (--codespell and --codespellfile) to enhance spelling check through dictionary, which copied the Linux kernel's implementation in checkpatch.pl. Signed-off-by: Zhao Liu --- scripts/checkpatch.pl | 66 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 755a1f683866..20ee07f016ca 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -38,7 +38,10 @@ my $summary_file =3D 0; my $root; my %debug; my $help =3D 0; +my $codespell =3D 0; my $spelling_file =3D "$D/spelling.txt"; +my $codespellfile =3D "/usr/share/codespell/dictionary.txt"; +my $user_codespellfile =3D ""; =20 sub help { my ($exitcode) =3D @_; @@ -70,6 +73,9 @@ Options: is all off) --test-only=3DWORD report only warnings/errors containing WORD literally + --codespell Use the codespell dictionary for spelling/typ= os + (default:$codespellfile) + --codespellfile Use this codespell dictionary --color[=3DWHEN] Use colors 'always', 'never', or only when = output is a terminal ('auto'). Default is 'auto'. -h, --help, --version display this help and exit @@ -102,15 +108,37 @@ GetOptions( 'summary!' =3D> \$summary, 'mailback!' =3D> \$mailback, 'summary-file!' =3D> \$summary_file, - 'debug=3Ds' =3D> \%debug, 'test-only=3Ds' =3D> \$tst_only, + 'codespell!' =3D> \$codespell, + 'codespellfile=3Ds' =3D> \$user_codespellfile, 'color=3Ds' =3D> \$color, 'no-color' =3D> sub { $color =3D 'never'; }, 'h|help' =3D> \$help, 'version' =3D> \$help ) or help(1); =20 +if ($user_codespellfile) { + # Use the user provided codespell file unconditionally + $codespellfile =3D $user_codespellfile; +} elsif (!(-f $codespellfile)) { + # If /usr/share/codespell/dictionary.txt is not present, try to find it + # under codespell's install directory: /data/dictionary.t= xt + if (($codespell || $help) && which("python3") ne "") { + my $python_codespell_dict =3D << "EOF"; + +import os.path as op +import codespell_lib +codespell_dir =3D op.dirname(codespell_lib.__file__) +codespell_file =3D op.join(codespell_dir, 'data', 'dictionary.txt') +print(codespell_file, end=3D'') +EOF + + my $codespell_dict =3D `python3 -c "$python_codespell_dict" 2> /dev/null= `; + $codespellfile =3D $codespell_dict if (-f $codespell_dict); + } +} + help(0) if ($help); =20 my $exit =3D 0; @@ -364,6 +392,30 @@ if (open(my $spelling, '<', $spelling_file)) { warn "No typos will be found - file '$spelling_file': $!\n"; } =20 +if ($codespell) { + if (open(my $spelling, '<', $codespellfile)) { + while (<$spelling>) { + my $line =3D $_; + + $line =3D~ s/\s*\n?$//g; + $line =3D~ s/^\s*//g; + + next if ($line =3D~ m/^\s*#/); + next if ($line =3D~ m/^\s*$/); + next if ($line =3D~ m/, disabled/i); + + $line =3D~ s/,.*$//; + + my ($suspect, $fix) =3D split(/->/, $line); + + $spelling_fix{$suspect} =3D $fix; + } + close($spelling); + } else { + warn "No codespell typos will be found - file '$codespellfile': $!\n"; + } +} + $misspellings =3D join("|", sort keys %spelling_fix) if keys %spelling_fix; =20 # This can be modified by sub possible. Since it can be empty, be careful @@ -506,6 +558,18 @@ sub top_of_kernel_tree { return 1; } =20 +sub which { + my ($bin) =3D @_; + + foreach my $path (split(/:/, $ENV{PATH})) { + if (-e "$path/$bin") { + return "$path/$bin"; + } + } + + return ""; +} + sub expand_tabs { my ($str) =3D @_; =20 --=20 2.34.1