« lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitStringySplit.pm
↑ Summary
lib/Perl/Critic/Policy/CodeLayout/RequireTidyCode.pm »
| 1 | package Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines; | ||||||||||||||||||||
| 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 PPI::Token::Whitespace; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 40 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 40 | Readonly::Scalar my $LINE_END => qr/\015{1,2}\012|[\012\015]/mxs; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => q{Use the same newline through the source}; | |||||||||||||||||||
| 20 | 40 | Readonly::Scalar my $EXPL => q{Change your newlines to be the same throughout}; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 119 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | 138 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 26 | 73 | ▶ | sub default_themes { return qw( core bugs ) } | ||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 27 | 62 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 62 | ▶ | sub violates { | ||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 32 | 62 | my ( $self, undef, $doc ) = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 62 | my $filename = $doc->filename(); | |||||||||||||||||||
| 35 | 62 | ▶ | return if !$filename; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 27 | my $fh; | |||||||||||||||||||
| 38 | 27 | ▶ | return if !open $fh, '<', $filename; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 27 | local $RS = undef; | |||||||||||||||||||
| 40 | 27 | my $source = <$fh>; | |||||||||||||||||||
| 41 | 27 | ▶ | close $fh or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 27 | my $newline; # undef until we find the first one | |||||||||||||||||||
| 44 | 27 | my $line = 1; | |||||||||||||||||||
| 45 | 27 | my @v; | |||||||||||||||||||
| 46 | 27 | ▶ | while ( $source =~ m/\G([^\012\015]*)($LINE_END)/cgmxs ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 561 | my $code = $1; | |||||||||||||||||||
| 48 | 561 | my $nl = $2; | |||||||||||||||||||
| 49 | 561 | my $col = length $code; | |||||||||||||||||||
| 50 | 561 | ▶ | $newline ||= $nl; | ||||||||||||||||||
|
Condition66%2/3
$newline ||= $nl
MC/DC0%0/2
$newline ||= $nl
$newline
$nl
Truth table66%2/3
A ||= B
A= $newlineB= $nl
| |||||||||||||||||||||
| 51 | 561 | ▶ | if ( $nl ne $newline ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 64 | my $token = PPI::Token::Whitespace->new( $nl ); | |||||||||||||||||||
| 53 | # TODO this is a terrible violation of encapsulation, but absent a | ||||||||||||||||||||
| 54 | # mechanism to override the line numbers in the violation, I do | ||||||||||||||||||||
| 55 | # not know what to do about it. | ||||||||||||||||||||
| 56 | 64 | $token->{_location} = [$line, $col, $col, $line, $filename]; | |||||||||||||||||||
| 57 | 64 | push @v, $self->violation( $DESC, $EXPL, $token ); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 561 | $line++; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | 27 | return @v; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 40 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||