Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s99nP-000ALJ-G3 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 May 2024 20:39:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s99nP-0052fx-6a for pgsql-hackers@arkaria.postgresql.org; Mon, 20 May 2024 20:39:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s99nO-0052fY-D3 for pgsql-hackers@lists.postgresql.org; Mon, 20 May 2024 20:39:46 +0000 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s99nG-001B1f-SU for pgsql-hackers@postgresql.org; Mon, 20 May 2024 20:39:45 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 5C2581381527; Mon, 20 May 2024 16:39:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 20 May 2024 16:39:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilmari.org; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1716237577; x=1716323977; bh=IUzJogVcFr 34xS40OhJhKIm2MgLj0wUXkCD79+o2FEA=; b=rOb2aqhdbNAxSfs5n0BeOYQm8k WI2d6Ke0KiqC0giAwlsaCC9GgiUZCSmK7UYanwAgNlmS2tZ3nXfUlPhNZ1IU/qLJ H4jHjzaCt/wl85JzNQPMtb4yUtSs1tRvOyoGvXEKp/zuGBYN2UEZcr/xyezRK/9L 63YW8u10UFBw1RH3Sz71hBLSWJJ0Kq7aytzi17d8gbVcLhQAPB1zy31A4KvYZSRY IRtAxdZC5izPx7xiMhDQ4WwE+tdv6W7Sy1yfqw6VcepHUpJOLKIHU+d1uidfw4kO i87UctW9Zcy4bOHOjpg5kr5u8udhiOfZYms88KGIbXnx08DIaW0naLnHlnyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716237577; x=1716323977; bh=IUzJogVcFr34xS40OhJhKIm2MgLj 0wUXkCD79+o2FEA=; b=RG2ZZTvVsHx8jBvVSgAEMg0GuzBthYv2t0ZPOhueKEsm Q3HFct7FxgqujWVmJkJryv8a9dLxRBgWfIr2WxtzPRE3cbLQ9xYGgGvMI12EzzJA KZhVM2sXwTu9C2EkfXFkfu9XDIis5nfmnXREH+2KimvpDslwIGL8coum+IdHDfRb WYIfRjPq2aK4QWgnZlFwZNH6/owRbx4xvwrLnHXCn7iWp5LatGs//ntFyMW3tfrD doUPPkewhnYwE6Upke3wsihwnAx3RUn507HiyGGnDo1DwezfZCoh78DMX9hwvAWn w7gGPdKuwyPwy8aijCdvG+71BpzNwRC6wNeaPacHyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeitddguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufhffjgfkfgggtgesmh dtreertderjeenucfhrhhomhepffgrghhfihhnnhcukfhlmhgrrhhiucforghnnhhsnohk vghruceoihhlmhgrrhhisehilhhmrghrihdrohhrgheqnecuggftrfgrthhtvghrnhepvd dvhfehtdefkedugfetudefhefggfegjeeijeehuefgteehgfegtdelgeetteejnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhlmhgrrhhise hilhhmrghrihdrohhrgh X-ME-Proxy: Feedback-ID: i1ff147bf:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 May 2024 16:39:36 -0400 (EDT) From: =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= To: Alexander Lakhin Cc: pgsql-hackers Subject: Re: Cleaning up perl code References: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com> Date: Mon, 20 May 2024 21:39:34 +0100 In-Reply-To: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com> (Alexander Lakhin's message of "Mon, 20 May 2024 20:00:00 +0300") Message-ID: <87ttisfcah.fsf@wibble.ilmari.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain Alexander Lakhin writes: > Hello hackers, > > Please look at a bunch of unused variables and a couple of other defects > I found in the perl code, maybe you'll find them worth fixing: Nice cleanup! Did you use some static analysis tool, or did look for them manually? If I add [Variables::ProhibitUnusedVariables] to src/tools/perlcheck/perlcriticrc, it finds a few more, see the attached patch. The scripts parsing errcodes.txt really should be refactored into using a common module, but that's a patch for another day. - ilmari --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Prohibit-unused-variables.patch From 6b096a39753338bb91add5fcf1ed963024e58c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Mon, 20 May 2024 19:55:20 +0100 Subject: [PATCH] Prohibit unused variables --- src/pl/plpgsql/src/generate-plerrcodes.pl | 6 ++---- src/pl/plpython/generate-spiexceptions.pl | 6 ++---- src/pl/tcl/generate-pltclerrcodes.pl | 6 ++---- src/tools/perlcheck/perlcriticrc | 2 ++ src/tools/pgindent/pgindent | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/pl/plpgsql/src/generate-plerrcodes.pl b/src/pl/plpgsql/src/generate-plerrcodes.pl index 1c662bc967..e969a4b33e 100644 --- a/src/pl/plpgsql/src/generate-plerrcodes.pl +++ b/src/pl/plpgsql/src/generate-plerrcodes.pl @@ -23,10 +23,8 @@ # Skip section headers next if /^Section:/; - die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; - - (my $sqlstate, my $type, my $errcode_macro, my $condition_name) = - ($1, $2, $3, $4); + my ($type, $errcode_macro, $condition_name) = + /^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die; # Skip non-errors next unless $type eq 'E'; diff --git a/src/pl/plpython/generate-spiexceptions.pl b/src/pl/plpython/generate-spiexceptions.pl index f0c5142be3..984017f212 100644 --- a/src/pl/plpython/generate-spiexceptions.pl +++ b/src/pl/plpython/generate-spiexceptions.pl @@ -23,10 +23,8 @@ # Skip section headers next if /^Section:/; - die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; - - (my $sqlstate, my $type, my $errcode_macro, my $condition_name) = - ($1, $2, $3, $4); + my ($type, $errcode_macro, $condition_name) = + /^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die; # Skip non-errors next unless $type eq 'E'; diff --git a/src/pl/tcl/generate-pltclerrcodes.pl b/src/pl/tcl/generate-pltclerrcodes.pl index fcac4d00a6..58eb6afefe 100644 --- a/src/pl/tcl/generate-pltclerrcodes.pl +++ b/src/pl/tcl/generate-pltclerrcodes.pl @@ -23,10 +23,8 @@ # Skip section headers next if /^Section:/; - die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/; - - (my $sqlstate, my $type, my $errcode_macro, my $condition_name) = - ($1, $2, $3, $4); + my ($type, $errcode_macro, $condition_name) = + /^[^\s]{5}\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/ or die; # Skip non-errors next unless $type eq 'E'; diff --git a/src/tools/perlcheck/perlcriticrc b/src/tools/perlcheck/perlcriticrc index 4739e9f4f1..6053dfcc2a 100644 --- a/src/tools/perlcheck/perlcriticrc +++ b/src/tools/perlcheck/perlcriticrc @@ -15,6 +15,8 @@ verbose = %f: %m at line %l, column %c. %e. ([%p] Severity: %s)\n # Note: for policy descriptions see https://metacpan.org/dist/Perl-Critic +[Variables::ProhibitUnusedVariables] +severity = 5 # allow octal constants with leading zeros [-ValuesAndExpressions::ProhibitLeadingZeros] diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index 48d83bc434..063ec8ce63 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -22,7 +22,7 @@ my $indent_opts = my $devnull = File::Spec->devnull; my ($typedefs_file, $typedef_str, @excludes, - $indent, $build, $diff, + $indent, $diff, $check, $help, @commits,); $help = 0; -- 2.39.2 --=-=-=--