lib/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 14 / 14 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 98.8% 85 / 86 CC 11 SCAR 14.8
CC
11
Cov
100%
violates
9.0
_is_extended_regex
3.0
BEGIN
1.0
CRAP 4.4
« lib/Perl/Critic/Policy/InputOutput/RequireCheckedSyscalls.pm ↑ Summary lib/Perl/Critic/Policy/ControlStructures/ProhibitNegativeExpressionsInUnlessAndUntilConditions.pm »
1 package Perl::Critic::Policy::CodeLayout::ProhibitHardTabs;
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 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw( :severities );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.156';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Hard tabs used};
16 40 Readonly::Scalar my $EXPL => [ 20 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 # The following regex should probably be "qr{^ .* [^\t]+ \t}xms" but it doesn't
21 # match when I expect it to. I haven't figured out why, so I used "\S" to
22 # approximately mean "not a tab", and that seemed to work.
23  
24 40 Readonly::Scalar my $NON_LEADING_TAB_REGEX => qr{^ .* \S+ \t }xms;
25  
26 #-----------------------------------------------------------------------------
27  
28 101 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
29 return (
30 {
31 101 name => 'allow_leading_tabs',
32 description => 'Allow hard tabs before first non-whitespace character.',
33 default_string => '1',
34 behavior => 'boolean',
35 },
36 );
37 }
38  
39 84 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
40 83 ▶sub default_themes { return qw( core cosmetic pbp ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
41 41 ▶sub applies_to { return 'PPI::Token' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
42  
43 #-----------------------------------------------------------------------------
44  
45 2385 ▶sub violates {
Subroutine violates: called CC=9 SCAR=22.0
Pod documented
46 2385 my ( $self, $elem, undef ) = @_;
47 2385 ▶ $elem =~ m{ \t }xms || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem =~ / \t /msx or return 19 2366 2385
48  
49 # The __DATA__ element is exempt
50 19 ▶ return if $elem->parent->isa('PPI::Statement::Data');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->parent->isa("PPI::Statement::Data") 1 18 19
51  
52 # If allowed, permit leading tabs in situations where whitespace s not significant.
53 18 ▶ if ( $self->_allow_leading_tabs() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_allow_leading_tabs) 12 6 18
54  
55 12 ▶ return if $elem->location->[1] == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $elem->location->[1] == 1 4 8 12
56  
57 8 ▶ return if _is_extended_regex($elem)
Branch: 1 branch
BranchTrueFalseTotal
if _is_extended_regex($elem) and not $elem =~ /$NON_LEADING_TAB_REGEX/ 2 6 8
Condition100%3/3
_is_extended_regex($elem) and not $elem =~ /$NON_LEADING_TAB_REGEX/
!ll&&!rl&&r
512
MC/DC100%2/2
_is_extended_regex($elem) and not $elem =~ /$NON_LEADING_TAB_REGEX/
_is_extended_regex($elem) not $elem =~ /$NON_LEADING_TAB_REGEX/
Truth table100%3/3
A and not(B)
A= _is_extended_regex($elem)B= not $elem =~ /$NON_LEADING_TAB_REGEX/
ABresult
0X0
100
111
58 && $elem !~ $NON_LEADING_TAB_REGEX;
59  
60 6 ▶ return if $elem->isa('PPI::Token::QuoteLike::Words')
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::QuoteLike::Words") and not $elem =~ /$NON_LEADING_TAB_REGEX/ 1 5 6
Condition100%3/3
$elem->isa("PPI::Token::QuoteLike::Words") and not $elem =~ /$NON_LEADING_TAB_REGEX/
!ll&&!rl&&r
411
MC/DC100%2/2
$elem->isa("PPI::Token::QuoteLike::Words") and not $elem =~ /$NON_LEADING_TAB_REGEX/
$elem->isa("PPI::Token::QuoteLike::Words") not $elem =~ /$NON_LEADING_TAB_REGEX/
Truth table100%3/3
A and not(B)
A= $elem->isa("PPI::Token::QuoteLike::Words")B= not $elem =~ /$NON_LEADING_TAB_REGEX/
ABresult
0X0
100
111
61 && $elem !~ $NON_LEADING_TAB_REGEX;
62 }
63  
64 # If we get here, then it must be a violation...
65 11 return $self->violation( $DESC, $EXPL, $elem );
66 }
67  
68 #-----------------------------------------------------------------------------
69  
70 18 ▶sub _allow_leading_tabs {
Subroutine _allow_leading_tabs: called CC=1 SCAR=0.0
71 18 my ( $self ) = @_;
72 18 return $self->{_allow_leading_tabs};
73 }
74  
75 #-----------------------------------------------------------------------------
76  
77 8 ▶sub _is_extended_regex {
Subroutine _is_extended_regex: called CC=3 SCAR=11.0
78 8 my ($elem) = @_;
79  
80 8 ▶ $elem->isa('PPI::Token::Regexp')
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Regexp") or $elem->isa("PPI::Token::QuoteLike::Regexp") or return 5 3 8
Condition100%3/3
$elem->isa("PPI::Token::Regexp") or $elem->isa("PPI::Token::QuoteLike::Regexp")
l!l&&r!l&&!r
323
MC/DC100%2/2
$elem->isa("PPI::Token::Regexp") or $elem->isa("PPI::Token::QuoteLike::Regexp")
$elem->isa("PPI::Token::Regexp") $elem->isa("PPI::Token::QuoteLike::Regexp")
Truth table100%3/3
A or B
A= $elem->isa("PPI::Token::Regexp")B= $elem->isa("PPI::Token::QuoteLike::Regexp")
ABresult
1X1
011
000
81 || $elem->isa('PPI::Token::QuoteLike::Regexp')
82 || return;
83  
84 # Look for the /x modifier near the end
85 5 return $elem =~ m{\b [gimso]* x [gimso]* $}xms;
86 }
87  
88 40 1;
89  
90 __END__
« lib/Perl/Critic/Policy/InputOutput/RequireCheckedSyscalls.pm ↑ Summary lib/Perl/Critic/Policy/ControlStructures/ProhibitNegativeExpressionsInUnlessAndUntilConditions.pm »