From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Cleaning up perl code
Date: Mon, 20 May 2024 21:39:34 +0100
Message-ID: <87ttisfcah.fsf@wibble.ilmari.org> (raw)
In-Reply-To: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com>
References: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com>
Alexander Lakhin <exclusion@gmail.com> 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
Attachments:0001-Prohibit-unused-variables.patch (text/x-diff, 3.2K) download
From 6b096a39753338bb91add5fcf1ed963024e58c15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
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.plindex 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.plindex 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.plindex 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/perlcriticrcindex 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/pgindentindex 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: ilmari@ilmari.org, exclusion@gmail.com
Subject: Re: Cleaning up perl code
In-Reply-To: <87ttisfcah.fsf@wibble.ilmari.org>
References: <70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com> <87ttisfcah.fsf@wibble.ilmari.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox