Subject: | ProhibitUselessNoCritic no report if nothing suppressed (patch) |
Date: | Sun, 05 Jul 2009 10:07:18 +1000 |
To: | bug-Perl-Critic [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With the current perlcritic cvs and recent debian i386 perl 5.10.0, a
file foo.pl containing just
## no critic (BlahBlah)
processed with
perlcritic -s ProhibitUselessNoCritic foo.pl
gives no violations, where I hoped it would report on the useless
BlahBlah suppression.
In ProhibitUselessNoCritic.pm I think the none() means the policy
doesn't trigger if there's no suppressed violations. Ie. there has to
be something validly suppressed before useless suppressions are
detected.
It seems dubious that List::MoreUtils none() isn't the same as !any(),
but at any rate a change to the latter as below seems to do the trick.
Index: ProhibitUselessNoCritic.pm
===================================================================
--- ProhibitUselessNoCritic.pm (revision 3371)
+++ ProhibitUselessNoCritic.pm (working copy)
@@ -13,7 +13,7 @@
use Readonly;
-use List::MoreUtils qw< none >;
+use List::MoreUtils qw< any >;
use Perl::Critic::Utils qw{ :severities :classification hashify };
use base 'Perl::Critic::Policy';
@@ -44,7 +44,9 @@
my @suppressed_viols = $doc->suppressed_violations();
for my $ann ( $doc->annotations() ) {
- if ( none { _annotation_suppresses_violation($ann, $_) } @suppressed_viols ) {
+ # Nb. List::MoreUtils::none() returns undef, ie. false, if
+ # @suppressed_violations is empty, hence !any() instead
+ unless (any { _annotation_suppresses_violation($ann, $_) } @suppressed_viols ) {
push @violations, $self->violation($DESC, $EXPL, $ann->element());
}
}