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

Community::Prototypes does not recognize :prototype form for declaring prototypes #44

Open petdance opened 2 years ago

petdance commented 2 years ago

foo and baz get caught correctly. bat is ignored correctly because it's an empty prototype. bar should be caught but is not.

This looks like the same problem as https://github.com/Perl-Critic/Perl-Critic/issues/978

#!/usr/bin/perl

use warnings;
use strict;
use 5.010;

sub foo($$) {}

sub bar :prototype($$) {}

sub bat() {}

sub baz($$) {}
$ perlcritic --s Community::Prototypes foo.pl
foo.pl: Using function prototypes.
    8:sub foo($$) {}

foo.pl: Using function prototypes.
    14:sub baz($$) {}
Grinnz commented 2 years ago

I'm not sure this is worth catching. So far, :prototype doesn't tend to be used by the target audience of this policy (newbies who think ($) is a normal thing to add to a sub definition). But perhaps.

Grinnz commented 2 years ago

It would be a bit more complex to recognize, because right now it completely ignores a file using the signatures feature, as it then assumes you know what you're doing.

atoomic commented 2 years ago

I'm just hitting this issue where we enable by default function signature in most of our codebase using a custom package so was adding this to our policy.. but this is useless as the current Community::Prototypes does not recognize:prototype

# Don't use function prototypes
[Community::Prototypes]
# Upgraded severity. Default severity: 3.
# Enforced by cPLint.
severity = 4
signature_enablers = cPstrict