« lib/Perl/Critic/ThemeListing.pm
↑ Summary
lib/Perl/Critic/Policy/Modules/RequireBarewordIncludes.pm »
| 1 | package Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace; | ||||||||||
| 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 charnames qw{}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 40 | ▶ | use PPI::Token::Whitespace; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 40 | our $VERSION = '1.156'; | |||||||||
| 16 | |||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||
| 18 | |||||||||||
| 19 | 40 | Readonly::Scalar my $EXPL => q{Don't use whitespace at the end of lines}; | |||||||||
| 20 | |||||||||||
| 21 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||
| 22 | 40 | Readonly::Hash my %C_STYLE_ESCAPES => | |||||||||
| 23 | ( | ||||||||||
| 24 | ord "\t" => q{\t}, | ||||||||||
| 25 | ord "\n" => q{\n}, | ||||||||||
| 26 | ord "\r" => q{\r}, | ||||||||||
| 27 | ord "\f" => q{\f}, | ||||||||||
| 28 | ord "\b" => q{\b}, | ||||||||||
| 29 | ord "\a" => q{\a}, | ||||||||||
| 30 | ord "\e" => q{\e}, | ||||||||||
| 31 | ); | ||||||||||
| 32 | ## use critic | ||||||||||
| 33 | |||||||||||
| 34 | #----------------------------------------------------------------------------- | ||||||||||
| 35 | |||||||||||
| 36 | 93 | ▶ | sub supported_parameters { return qw{ } } | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 80 | ▶ | sub default_severity { return $SEVERITY_LOWEST } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | 73 | ▶ | sub default_themes { return qw( core maintenance ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | 34 | ▶ | sub applies_to { return 'PPI::Token::Whitespace' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | #----------------------------------------------------------------------------- | ||||||||||
| 42 | |||||||||||
| 43 | 1011 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 1011 | my ( $self, $token, undef ) = @_; | |||||||||
| 45 | |||||||||||
| 46 | 1011 | ▶ | if ( $token->content() =~ m< ( (?! \n) \s )+ \n >xms ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 6 | my $extra_whitespace = $1; | |||||||||
| 48 | |||||||||||
| 49 | 6 | my $description = q{Found "}; | |||||||||
| 50 | $description .= | ||||||||||
| 51 | join | ||||||||||
| 52 | $EMPTY, | ||||||||||
| 53 | 6 | map { _escape($_) } split $EMPTY, $extra_whitespace; | |||||||||
| 54 | 6 | $description .= q{" at the end of the line}; | |||||||||
| 55 | |||||||||||
| 56 | 6 | return $self->violation( $description, $EXPL, $token ); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1005 | return; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 6 | ▶ | sub _escape { | ||||||||
|
Subroutine
_escape: called CC=3 SCAR=11.2
| |||||||||||
| 63 | 6 | my $character = shift; | |||||||||
| 64 | 6 | my $ordinal = ord $character; | |||||||||
| 65 | |||||||||||
| 66 | 6 | ▶ | if (my $c_escape = $C_STYLE_ESCAPES{$ordinal}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 3 | return $c_escape; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | # Apparently, the charnames.pm that ships with older perls does not | ||||||||||
| 72 | # support the C<viacode> function, and newer versions of the module are | ||||||||||
| 73 | # not distributed separately from perl itself So if the C<viacode> method | ||||||||||
| 74 | # is not supported, then just substitute something. | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||
| 78 | 3 | ▶ | if ( charnames->can( 'viacode' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 3 | return q/\N{/ . charnames::viacode($ordinal) . q/}/; | |||||||||
| 80 | } | ||||||||||
| 81 | else { | ||||||||||
| 82 | 0 | return '\N{WHITESPACE CHAR}'; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 40 | 1; | |||||||||
| 87 | |||||||||||
| 88 | #----------------------------------------------------------------------------- | ||||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||