« Policy/CodeLayout/ProhibitIfIfSameLine.pm
↑ Summary
Policy/ValuesAndExpressions/UnexpandedSpecialLiteral.pm »
| 1 | # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # version. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | package Perl::Critic::Policy::Compatibility::ProhibitUnixDevNull; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 41 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 41 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 41 | ▶ | use List::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 41 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 41 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 41 | ▶ | use Perl::Critic::Pulp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 41 | our $VERSION = 100; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 41 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 41 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 41 | ▶ | use constant default_themes => qw(pulp bugs); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 41 | ▶ | use constant applies_to => qw(PPI::Token::Quote | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 41 | PPI::Token::QuoteLike::Words); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # See Perl_do_openn() for IsSPACE allowed leading, after mode and trailing. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # No layers in a two-arg open, only < > >> etc. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 41 | ▶ | use constant _DEV_NULL_RE => qr{^\s* | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | (\+?(<|>>?)\s*)? | ||||||||||||||||||||||||||||||||||||||||||
| 39 | /dev/null | ||||||||||||||||||||||||||||||||||||||||||
| 40 | \s*$ | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 41 | }sxo; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 41 | my %equality_operators = (eq => 1, ne => 1); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | ▶ | if ($elem->isa('PPI::Token::QuoteLike::Words')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | return unless List::Util::first {$_ eq '/dev/null'} $elem->literal; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | } else { # PPI::Token::Quote | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | my $str = $elem->string; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | return unless $str =~ _DEV_NULL_RE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Allow ... eq 'dev/null' or 'dev/null' eq ... | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # Could think about the filetest operators too. -e '/dev/null' is | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # probably a portability check, but believe still better to have | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # File::Spec->devnull there. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | foreach my $adj ($elem->sprevious_sibling, $elem->snext_sibling) { | |||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | if ($adj | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$adj and $adj->isa("PPI::Token::Operator") and $equality_operators{$adj}
$adj and $adj->isa("PPI::Token::Operator")
MC/DC66%2/3
$adj and $adj->isa("PPI::Token::Operator") and $equality_operators{$adj}
$adj
$adj->isa("PPI::Token::Operator")
$equality_operators{$adj}
Truth table75%3/4
A and B and C
A= $adjB= $adj->isa("PPI::Token::Operator")C= $equality_operators{$adj}
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | && $adj->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||||||||||||||||
| 64 | && $equality_operators{$adj}) { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | return $self->violation | |||||||||||||||||||||||||||||||||||||||||
| 71 | ('For maximum portability use File::Spec->devnull instead of "/dev/null"', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | '', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | $elem); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 41 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||||||||||||||||