Alexander Lakhin <exclus...@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
>From 6b096a39753338bb91add5fcf1ed963024e58c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilm...@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.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