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: 49636
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

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



Subject: ProhibitUselessNoCritic not of user-disabled policies
Date: Sat, 12 Sep 2009 09:53:01 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
When a policy is explicitly disabled in .perlcriticrc with [-Foo], ProhibitUselessNoCritic will report as useless an annotation of that policy, ## no critic (Foo) It'd be good if ProhibitUselessNoCritic recognised that Foo didn't suppress anything because I'd asked not to use it. Whenever Foo is not run it's of course not possible to tell if that annotation is useful or useless. More than likely it's useful to the users using the policy, and on that basis needn't be reported as anything bad to other people. The couple of lines below get the effect I wanted. Is the Perl::Critic object and/or the UserProfile communicated to the policy object? I couldn't spot it so I put it through a global variable just to see how it went.
Index: lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm =================================================================== --- lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm (revision 3613) +++ lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm (working copy) @@ -12,9 +12,8 @@ use warnings; use Readonly; +use List::MoreUtils qw< any >; -use List::MoreUtils qw< none >; - use Perl::Critic::Utils qw{ :severities :classification hashify }; use base 'Perl::Critic::Policy'; @@ -40,13 +39,24 @@ # If for some reason $doc is not a P::C::Document, then all bets are off return if not $doc->isa('Perl::Critic::Document'); + # where can this properly be had from ? + my $userprofile = $Perl::Critic::UserProfile::INSTANCE; + my @violations = (); my @suppressed_viols = $doc->suppressed_violations(); for my $ann ( $doc->annotations() ) { - if ( none { _annotation_suppresses_violation($ann, $_) } @suppressed_viols ) { - push @violations, $self->violation($DESC, $EXPL, $ann->element()); - } + # ok if $ann suppressed something + next if any {_annotation_suppresses_violation($ann,$_)} + @suppressed_viols; + + # ok if any of $ann was explicitly disabled by the user; cannot know + # if an annotation is useful or useless if one or more of its policies + # were not run + next if any {$userprofile->policy_is_disabled($_)} + $ann->disabled_policies; + + push @violations, $self->violation($DESC, $EXPL, $ann->element()); } return @violations; Index: lib/Perl/Critic/UserProfile.pm =================================================================== --- lib/Perl/Critic/UserProfile.pm (revision 3613) +++ lib/Perl/Critic/UserProfile.pm (working copy) @@ -25,6 +25,8 @@ our $VERSION = '1.104'; +our $INSTANCE; + #----------------------------------------------------------------------------- sub new { @@ -32,6 +34,7 @@ my ( $class, %args ) = @_; my $self = bless {}, $class; $self->_init( %args ); + $INSTANCE = $self; return $self; }
I understand your thinking, but I feel this would partially defeat the purpose of the ProhibitUselessNoCritic Policy. Your idea suggests that useless "no critic" markers primarily happen due to bug fixes in Perl-Critic. But they can also happen if your team changes their Policies over time. So ProhibitUselessNoCritic helps you to quickly find unnecessary markers when your team decides to disable or reconfigure a Policy half way through development. If "other" people are critiquing your code with a different configuration, then all bets are off anyway. You have no idea what Policies they may or may not have. So the analysis is really only relevant to the person or team that wrote the code and created the Perl-Critic configuration. We always suggest NOT shipping any Perl-Critic tests in your distribution, or disabling them by default somehow. Does that add any clarity? Or have I misunderstood your request?
Subject: Re: [rt.cpan.org #49636] ProhibitUselessNoCritic not of user-disabled policies
Date: Mon, 21 Sep 2009 10:40:46 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Ryan Thalhammer via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > If "other" people are critiquing your code with a different > configuration, then all bets are off anyway.
That's a bit harsh isn't it? My "no critic"s are supposed to mean that I know the code tickles a certain policy, but I know what I'm doing and that neither I nor anyone else need be troubled by the violations. In the end I disabled the policy in question in my config (I think it was ProhibitEscapedCharacters) believing it doesn't help me. But the "no critic"s are still correct and helpful for others, so I shouldn't have to go through and strip them all out should I? And if I strip them out I don't have to add them all back later when I realize the policy was a good idea after all :-), do I?
Subject: Re: [rt.cpan.org #49636] ProhibitUselessNoCritic not of user-disabled policies
Date: Mon, 21 Sep 2009 07:19:33 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
The point of this policy is to get rid of as many no critic directives as possible. If you don't like the policy, disable it.
Subject: Re: [rt.cpan.org #49636] ProhibitUselessNoCritic not of user-disabled policies
Date: Tue, 22 Sep 2009 08:03:21 +1000
To: bug-Perl-Critic [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Elliot Shank via RT" <bug-Perl-Critic@rt.cpan.org> writes: Show quoted text
> > get rid of as many no critic directives
I want to get rid of useless ones too. But I want to keep the useful ones. ProhibitUselessNoCritic shouldn't report on useful directives. In practice I believe that must mean those which under the circumstances of the run that it can't be confident are in fact useless.
Subject: Re: [rt.cpan.org #49636] ProhibitUselessNoCritic not of user-disabled policies
Date: Mon, 21 Sep 2009 21:10:46 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Kevin Ryde via RT wrote: Show quoted text
> I want to get rid of useless ones too. But I want to keep the useful > ones. ProhibitUselessNoCritic shouldn't report on useful directives. > In practice I believe that must mean those which under the circumstances > of the run that it can't be confident are in fact useless.
Say I've got a few violations of a policy. Over time, I write more code that violates it until I get fed up with it and just turn it off. P::C should now complain about the useless directives.
Subject: Re: [rt.cpan.org #49636] ProhibitUselessNoCritic not of user-disabled policies
Date: Tue, 22 Sep 2009 12:57:21 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On Sep 21, 2009, at 3:03 PM, Kevin Ryde via RT wrote: Show quoted text
> > I want to get rid of useless ones too. But I want to keep the useful > ones. ProhibitUselessNoCritic shouldn't report on useful directives. > In practice I believe that must mean those which under the > circumstances > of the run that it can't be confident are in fact useless.
I think we just disagree on the definition of "useless." To me (and Elliot, I believe) a useless directive is one that doesn't actually suppress any violations, given a particular configuration. But it seems that you feel a useless directive is one that doesn't suppress any violations under any possible configuration. I understand both points of view, but personally, I feel the former is much more useful than the latter. Also, the latter view is logically impossible because we cannot know what all the possible configurations are. It is true that ProhibitUselessNoCritic imposes a maintenance cost on your code -- when you change your Perl-Critic configuration, you may have to add/change/remove "no critic" directives. But that is also the whole point of the Policy. We believe it is less expensive to just add/change/remove the directives than it is to have everyone on the team looking at a bunch of "no critic" directives and thinking about why each one is there. So unless I've completely misunderstood your request, I think this is non-issue. -Jeff
Could I suggest a possible way forward. In the .perlcriticrc it should be possible to 'hard disable' or 'soft disable' a policy. If it is hard disabled then it is as if that policy did not exist, and so the 'Useless' message will appear. However, if a particular policy is marked in the user's configuration as soft-disabled then it won't fire any warnings, but it will be taken into account in the check of 'Useless' annotations. The intention is for soft disabled policies to be those which are temporarily turned off (perhaps waiting for a bug fix in Perl::Critic) but not so disliked by the user that he or she wants to remove all the code annotations for them.