Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 64929
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: ovid [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.111
Fixed in: (no value)



Subject: ProhibitUnusedVars isn't finding all unused variables.
Saving this to the file critic.pl: my %val; while ( my ( $k, $v ) = each %hash ) { my $k = $v; } And running this: perlcritic --single-policy ProhibitUnusedVariables critic.pl Results in: "%val" is declared but not used at line 1, column 1. Unused variables clutter code and make it harder to read. (Severity: 3) The %hash and the first $k are not found. The following has an unused variable which is not detected: sub foo { my $x = 1; } The following will also fail to find either unused variable: sub foo { my $x; } sub bar { my $x; } Cheers, Ovid
Subject: Re: [rt.cpan.org #64929] ProhibitUnusedVars isn't finding all unused variables.
Date: Thu, 20 Jan 2011 19:02:12 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
As stated in the doc for this Policy, it's pretty dumb right now. It won't even complain about { my $x = 5 }
On Thu Jan 20 20:02:25 2011, clonezone wrote: Show quoted text
> As stated in the doc for this Policy, it's pretty dumb right now. It > won't even complain about > > { my $x = 5 }
My apologies. You can close this out if you like. I'm used to Perl::Critic policies which "just work" and I should have paid more attention.
Subject: Re: [rt.cpan.org #64929] ProhibitUnusedVars isn't finding all unused variables.
Date: Fri, 21 Jan 2011 07:21:14 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 1/21/11 12:49 AM, Curtis 'Ovid' Poe via RT wrote: Show quoted text
> My apologies. You can close this out if you like. I'm used to > Perl::Critic policies which "just work" and I should have paid more > attention.
No, it should stay open, but as a wishlist item. This Policy was written as a "it's better than nothing" exercise. It should be readily extendable to handle constant assignment, but we've got to watch out for things like Scope::Guard. Going deeper as in your examples requires a bit more effort.
I've been hacking around with this. Whether I will get something useful is another question. Exceptions (meaning, unused variables that should not be considered violations) appear to be: * Scope::Guard and friends (thinks for the reminder!); * Subroutine argument unpacking (because of unused arguments); * Taking a reference on creation, i.e. \( my $foo = 'bar' ). Ideas for other exceptions are welcome. It would be nice to test against CPAN, but unfortunately warnings::unused seems to produce false negatives sometimes, and at least slightly more often with -c. In terms of a single file this is rare, but in terms of CPAN there are scads of them. Tom
The revised policy as it now stands is committed to http://perlcritic.tigris.org/svn/perlcritic/branches/rt64929. The actual code went in as SVN revision 4034.
On Tue Feb 08 21:06:11 2011, WYANT wrote: Show quoted text
> The revised policy as it now stands is committed to > http://perlcritic.tigris.org/svn/perlcritic/branches/rt64929. The actual > code went in as SVN revision 4034.
A lot has happened since this. There were legitimate concerns that a rewrite "with teeth" would cause false positives. So the code has been broken out and released as Perl-Critic-Policy-Variables-ProhibitUnusedVarsStricter. Branch rt64929 has been deleted.