« Policy/Compatibility/ProhibitUnixDevNull.pm
↑ Summary
Policy/ValuesAndExpressions/ProhibitBarewordDoubleColon.pm »
| 1 | # Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # This file is part of Perl-Critic-Pulp. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Change "12 Jul 2013 23:37:26 -0700" making __PACKAGE__ etc quoted by => | ||||||||||||||||||||||||||||
| 20 | # across newline. | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | # http://perl5.git.perl.org/perl.git/commit/21791330af556dc082f3ef837d772ba9a4d0b197 | ||||||||||||||||||||||||||||
| 23 | # http://perl5.git.perl.org/perl.git/patch/21791330af556dc082f3ef837d772ba9a4d0b197 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | package Perl::Critic::Policy::ValuesAndExpressions::UnexpandedSpecialLiteral; | ||||||||||||||||||||||||||||
| 27 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 40 | ▶ | use List::Util qw(min max); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 40 | ▶ | use Perl::Critic::Utils qw(is_perl_builtin | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | is_perl_builtin_with_no_arguments | ||||||||||||||||||||||||||||
| 35 | 40 | precedence_of); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_MEDIUM; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 40 | ▶ | use constant default_themes => qw(pulp bugs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 40 | ▶ | use constant applies_to => ('PPI::Token::Word'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 40 | my %specials = ('__FILE__' => 1, | |||||||||||||||||||||||||||
| 45 | '__LINE__' => 1, | ||||||||||||||||||||||||||||
| 46 | '__PACKAGE__' => 1); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 34 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 34 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||
| 50 | 34 | ▶ | $specials{$elem} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 24 | ▶ | if (elem_is_quoted_by_big_comma ($elem)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 11 | return $self->violation | |||||||||||||||||||||||||||
| 54 | ("$elem is the literal string '$elem' on the left of a =>", | ||||||||||||||||||||||||||||
| 55 | '', $elem); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 13 | ▶ | if (elem_is_solo_subscript ($elem)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 5 | return $self->violation | |||||||||||||||||||||||||||
| 59 | ("$elem is the literal string '$elem' in a hash subscript", | ||||||||||||||||||||||||||||
| 60 | '', $elem); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 8 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Perl::Critic::Utils::is_hash_key() does a similar thing to the following | ||||||||||||||||||||||||||||
| 66 | # tests, identifying something on the left of "=>", or in a "{}" subscript. | ||||||||||||||||||||||||||||
| 67 | # But here want those two cases separately since the subscript is only a | ||||||||||||||||||||||||||||
| 68 | # violation if $elem also has no siblings. (Separate cases allow a custom | ||||||||||||||||||||||||||||
| 69 | # error message too.) | ||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||
| 71 | # { __FILE__ => 123 } | ||||||||||||||||||||||||||||
| 72 | # ( __FILE__ => 123 ) | ||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||
| 74 | 24 | ▶ | sub elem_is_quoted_by_big_comma { | ||||||||||||||||||||||||||
|
Subroutine
elem_is_quoted_by_big_comma: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 24 | my ($elem) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 24 | my $next = $elem; | |||||||||||||||||||||||||||
| 78 | 24 | for (;;) { | |||||||||||||||||||||||||||
| 79 | 35 | ▶ | $next = $next->next_sibling | ||||||||||||||||||||||||||
|
Condition100%2/2
$next->next_sibling || (return 0)
MC/DC100%1/1
$next->next_sibling || (return 0)
$next->next_sibling
Truth table100%2/2
A
A= $next->next_sibling
| |||||||||||||||||||||||||||||
| 80 | || return 0; # nothing following | ||||||||||||||||||||||||||||
| 81 | 27 | ▶ | if ($next->isa('PPI::Token::Whitespace') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next->isa("PPI::Token::Whitespace") and not $next->content =~ /\n/
MC/DC100%2/2
$next->isa("PPI::Token::Whitespace") and not $next->content =~ /\n/
$next->isa("PPI::Token::Whitespace")
not $next->content =~ /\n/
Truth table100%3/3
A and not(B)
A= $next->isa("PPI::Token::Whitespace")B= not $next->content =~ /\n/
| |||||||||||||||||||||||||||||
| 82 | && $next->content !~ /\n/) { | ||||||||||||||||||||||||||||
| 83 | 11 | next; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 16 | ▶ | return ($next->isa('PPI::Token::Operator') && $next->content eq '=>'); | ||||||||||||||||||||||||||
|
Condition100%3/3
$next->isa('PPI::Token::Operator') && $next->content eq '=>'
MC/DC100%2/2
$next->isa('PPI::Token::Operator') && $next->content eq '=>'
$next->isa('PPI::Token::Operator')
$next->content eq '=>'
Truth table100%3/3
A && B
A= $next->isa('PPI::Token::Operator')B= $next->content eq '=>'
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # $hash{__FILE__} | ||||||||||||||||||||||||||||
| 90 | # | ||||||||||||||||||||||||||||
| 91 | # PPI::Structure::Subscript { ... } | ||||||||||||||||||||||||||||
| 92 | # PPI::Statement::Expression | ||||||||||||||||||||||||||||
| 93 | # PPI::Token::Word '__PACKAGE__' | ||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | # and not multi subscript like $hash{__FILE__,123} | ||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||
| 97 | # PPI::Structure::Subscript { ... } | ||||||||||||||||||||||||||||
| 98 | # PPI::Statement::Expression | ||||||||||||||||||||||||||||
| 99 | # PPI::Token::Word '__PACKAGE__' | ||||||||||||||||||||||||||||
| 100 | # PPI::Token::Operator ',' | ||||||||||||||||||||||||||||
| 101 | # PPI::Token::Number '123' | ||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||
| 103 | 13 | ▶ | sub elem_is_solo_subscript { | ||||||||||||||||||||||||||
|
Subroutine
elem_is_solo_subscript: called CC=6 SCAR=18.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 13 | my ($elem) = @_; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # must be sole elem | ||||||||||||||||||||||||||||
| 107 | 13 | ▶ | if ($elem->snext_sibling) { return 0; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($elem->sprevious_sibling) { return 0; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 8 | ▶ | my $parent = $elem->parent || return 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$elem->parent || (return 0)
MC/DC0%0/1
$elem->parent || (return 0)
$elem->parent
Truth table50%1/2
A
A= $elem->parent
| |||||||||||||||||||||||||||||
| 111 | 8 | ▶ | $parent->isa('PPI::Statement::Expression') || return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 6 | ▶ | my $grandparent = $parent->parent || return 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$parent->parent || (return 0)
MC/DC0%0/1
$parent->parent || (return 0)
$parent->parent
Truth table50%1/2
A
A= $parent->parent
| |||||||||||||||||||||||||||||
| 114 | 6 | return $grandparent->isa('PPI::Structure::Subscript'); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 40 | 1; | |||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||