« lib/Perl/Critic/TestUtils.pm
↑ Summary
lib/Perl/Critic/Policy/Subroutines/RequireArgUnpacking.pm »
| 1 | package Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities :classification}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q{List of quoted literal words}; | |||||||||||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => q{Use 'qw()' instead}; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 92 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | return ( | ||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 92 | name => 'min_elements', | |||||||||||||||||||||||||||
| 25 | description => 'The minimum number of words in a list that will be complained about.', | ||||||||||||||||||||||||||||
| 26 | default_string => '2', | ||||||||||||||||||||||||||||
| 27 | behavior => 'integer', | ||||||||||||||||||||||||||||
| 28 | integer_minimum => 1, | ||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | name => 'strict', | ||||||||||||||||||||||||||||
| 32 | description => 'Complain even if there are non-word characters in the values.', | ||||||||||||||||||||||||||||
| 33 | default_string => '0', | ||||||||||||||||||||||||||||
| 34 | behavior => 'boolean', | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 73 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 83 | ▶ | sub default_themes { return qw( core cosmetic ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 31 | ▶ | sub applies_to { return 'PPI::Structure::List' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 22 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=18 SCAR=51.2
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 22 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Don't worry about subroutine calls | ||||||||||||||||||||||||||||
| 49 | 22 | my $sibling = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||
| 50 | 22 | ▶ | return if not $sibling; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 22 | ▶ | return if $sibling->isa('PPI::Token::Symbol'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 16 | ▶ | return if $sibling->isa('PPI::Token::Operator') and $sibling eq '->'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sibling->isa("PPI::Token::Operator") and $sibling eq "->"
MC/DC0%0/2
$sibling->isa("PPI::Token::Operator") and $sibling eq "->"
$sibling->isa("PPI::Token::Operator")
$sibling eq "->"
Truth table33%1/3
A and B
A= $sibling->isa("PPI::Token::Operator")B= $sibling eq "->"
| |||||||||||||||||||||||||||||
| 54 | 16 | ▶ | return if $sibling->isa('PPI::Token::Word') and not is_included_module_name($sibling); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sibling->isa("PPI::Token::Word") and not is_included_module_name($sibling)
MC/DC0%0/2
$sibling->isa("PPI::Token::Word") and not is_included_module_name($sibling)
$sibling->isa("PPI::Token::Word")
not is_included_module_name($sibling)
Truth table33%1/3
A and not(B)
A= $sibling->isa("PPI::Token::Word")B= not is_included_module_name($sibling)
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Get the list elements | ||||||||||||||||||||||||||||
| 57 | 0 | my $expr = $elem->schild(0); | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | return if not $expr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | my @children = $expr->schildren(); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | return if not @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 63 | 0 | for my $child ( @children ) { | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | next if $child->isa('PPI::Token::Operator') && $child eq $COMMA; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$child->isa("PPI::Token::Operator") and $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
MC/DC0%0/2
$child->isa("PPI::Token::Operator") and $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
$child->isa("PPI::Token::Operator")
$child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
Truth table0%0/3
A and B
A= $child->isa("PPI::Token::Operator")B= $child eq $Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists::COMMA
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # All elements must be literal strings, | ||||||||||||||||||||||||||||
| 67 | # and must contain 1 or more word characters. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return if not _is_literal($child); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my $string = $child->string(); | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | return if $string =~ m{ \s }xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return if $string eq $EMPTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return if not $self->{_strict} and $string !~ m{\A [\w-]+ \z}xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_strict"} or $string =~ /\A [\w-]+ \z/msx
MC/DC0%0/2
$self->{"_strict"} or $string =~ /\A [\w-]+ \z/msx
$self->{"_strict"}
$string =~ /\A [\w-]+ \z/msx
Truth table0%0/3
A or B
A= $self->{"_strict"}B= $string =~ /\A [\w-]+ \z/msx
| |||||||||||||||||||||||||||||
| 75 | 0 | $count++; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Were there enough? | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return if $count < $self->{_min_elements}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # If we get here, then all elements were literals | ||||||||||||||||||||||||||||
| 82 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub _is_literal { | ||||||||||||||||||||||||||
|
Subroutine
_is_literal: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 86 | 0 | my $elem = shift; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | return $elem->isa('PPI::Token::Quote::Single') | ||||||||||||||||||||||||||
|
Condition0%0/3
$elem->isa('PPI::Token::Quote::Single') || $elem->isa('PPI::Token::Quote::Literal')
MC/DC0%0/2
$elem->isa('PPI::Token::Quote::Single') || $elem->isa('PPI::Token::Quote::Literal')
$elem->isa('PPI::Token::Quote::Single')
$elem->isa('PPI::Token::Quote::Literal')
Truth table0%0/3
A || B
A= $elem->isa('PPI::Token::Quote::Single')B= $elem->isa('PPI::Token::Quote::Literal')
| |||||||||||||||||||||||||||||
| 88 | || $elem->isa('PPI::Token::Quote::Literal'); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 40 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||