« blib/lib/Perl/Lint/Policy/RegularExpressions/ProhibitUnusualDelimiters.pm
↑ Summary
blib/lib/Perl/Lint/Policy/RegularExpressions/RequireBracesForMultiline.pm »
| 1 | package Perl::Lint::Policy::RegularExpressions::ProhibitUselessTopic; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Perl::Lint::Constants::Type; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | use parent "Perl::Lint::Policy"; | ||
| 6 | |||
| 7 | use constant { | ||
| 8 | DESC => 'Useless use of $_', | ||
| 9 | EXPL => '$_ should be omitted when matching a regular expression', | ||
| 10 | }; | ||
| 11 | |||
| 12 | sub evaluate { | ||
| 13 | my ($class, $file, $tokens, $src, $args) = @_; | ||
| 14 | |||
| 15 | my @violations; | ||
| 16 | for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { | ||
| 17 | $token_type = $token->{type}; | ||
| 18 | |||
| 19 | if ($token_type == SPECIFIC_VALUE) { | ||
| 20 | $token = $tokens->[++$i] or last; | ||
| 21 | $token_type = $token->{type}; | ||
| 22 | |||
| 23 | if ($token_type == REG_OK || $token_type == REG_NOT) { | ||
| 24 | $token = $tokens->[++$i] or last; | ||
| 25 | $token_type = $token->{type}; | ||
| 26 | |||
| 27 | if ($token_type != VAR && $token_type != GLOBAL_VAR) { | ||
| 28 | push @violations, { | ||
| 29 | filename => $file, | ||
| 30 | line => $token->{line}, | ||
| 31 | description => DESC, | ||
| 32 | explanation => EXPL, | ||
| 33 | policy => __PACKAGE__, | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | } | ||
| 40 | |||
| 41 | return \@violations; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||