Grinnz / Perl-Critic-Community

Perl::Critic::Community - Community-inspired Perl::Critic policies
https://metacpan.org/pod/Perl::Critic::Community
Other
8 stars 10 forks source link

Rename confuses Miscellanea::ProhibitUselessNoCritic #40

Closed plicease closed 3 years ago

plicease commented 3 years ago

With the rename to Community (which I applaud), I saw Miscellanea::ProhibitUselessNoCritic violations where I hadn't before. When I removed the ## no critic (Freenode::Wantarray) I got the Community::Wantarray violation. Instead changing the ## no critic (Community::Wantarray) cleared the violations.

This is the CI fail: https://github.com/perlwasm/Wasm/pull/112/checks?check_run_id=2694106399 and this is the workaround: https://github.com/perlwasm/Wasm/pull/112/commits/62d30e1b39a61ca1b7bf552a8dddda62ba2dd358 (the commit also includes a change in the perlcritic rc file, but that wasn't required to clear the error, as per local testing)

Grinnz commented 3 years ago

Not sure I understand what the problem is. The "Freenode" policies all still work.

plicease commented 3 years ago

Sorry I intended to open this against Miscellanea::ProhibitUselessNoCritic, which is I think where the bug be.

Grinnz commented 3 years ago

Actually I think the problem is that Perl::Critic::Violations are created based on their caller, which means it doesn't see subclass policies like all of the Freenode and some of the Community policies. https://metacpan.org/release/Perl-Critic/source/lib/Perl/Critic/Violation.pm#L67

Grinnz commented 3 years ago

I don't see a supported way to fix this.

Grinnz commented 3 years ago

The subclass friendly option would of course be to use the class used to invoke the violation method of Perl::Critic::Policy, but I can't fix that from the outside, and there's no interface to fix the policy name of a violation object.

plicease commented 3 years ago

I started opening the ticket here and then I thought I switched to Perl::Critic core (which has the ProhibitUselessNoCritic policy), but I think I got my windows mixed up and submitted the ticket here. I am content to update my code anyway, but it does seem to be a bug either in Perl::Critic core, or more likely the ProhibitUselessNoCritic policy. So I opened https://github.com/Perl-Critic/Perl-Critic/issues/957 with a short example that reproduces it.