Perl-Critic / Perl-Critic

The leading static analyzer for Perl. Configurable, extensible, powerful.
http://perlcritic.com
Other
181 stars 103 forks source link

Miscellanea::ProhibitUselessNoCritic flags legitimate ## no critic (Freenode...) with after rename #957

Open plicease opened 3 years ago

plicease commented 3 years ago

With config:

severity = 1
only = 1

[Freenode::Wantarray]

this perl script passes perlcritic:

sub foo {
  wantarray ? (1,2,3) : 3;  ## no critic (Freenode::Wantarray)
}

with this config:

severity = 1
only = 1

[Freenode::Wantarray]
[Miscellanea::ProhibitUselessNoCritic]

it fails

starscream% perlcritic foo.pl 
Useless '## no critic' annotation at line 2, column 29.  This annotation can be removed.  (Severity: 2)

@Grinnz point out this line, which may be the culprit:

https://metacpan.org/release/Perl-Critic/source/lib/Perl/Critic/Violation.pm#L67

Grinnz commented 3 years ago

I think the problem is that it gets the policy name from caller(), which doesn't know when it's being called from a superclass. An inheritance friendly method would be to check the invocant of Perl::Critic::Policy::violation.