« Policy/Documentation/ProhibitVerbatimMarkup.pm
↑ Summary
Policy/Documentation/RequireFinalCut.pm »
| 1 | # Copyright 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # This file is part of Perl-Critic-Pulp. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Perl-Critic-Pulp is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # perlcritic -s RequireFilenameMarkup RequireFilenameMarkup.pm | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # unmarked /usr/local | ||||||||||||||||||||||||||||
| 22 | # perlcritic -s RequireFilenameMarkup /usr/share/perl5/XML/Twig.pm | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | package Perl::Critic::Policy::Documentation::RequireFilenameMarkup; | ||||||||||||||||||||||||||||
| 26 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 40 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 40 | ▶ | use Pod::Escapes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 34 | # use Smart::Comments; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 40 | ▶ | use constant default_themes => qw(pulp cosmetic); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 40 | ▶ | use constant applies_to => 'PPI::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 41 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 41 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||
| 45 | ### RequireFilenameMarkup on: $elem->content | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 41 | my $parser = Perl::Critic::Pulp::PodParser::RequireFilenameMarkup->new | |||||||||||||||||||||||||||
| 48 | (policy => $self); | ||||||||||||||||||||||||||||
| 49 | 41 | $parser->parse_from_elem ($elem); | |||||||||||||||||||||||||||
| 50 | 41 | return $parser->violations; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | package Perl::Critic::Pulp::PodParser::RequireFilenameMarkup; | ||||||||||||||||||||||||||||
| 54 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 40 | ▶ | use Pod::ParseLink; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 40 | ▶ | use base 'Perl::Critic::Pulp::PodParser'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 41 | ▶ | sub command { | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 41 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 41 | $self->SUPER::command(@_); # for $self->{'in_begin'} | |||||||||||||||||||||||||||
| 62 | 41 | $self->command_as_textblock(@_); | |||||||||||||||||||||||||||
| 63 | 41 | return ''; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 79 | ▶ | sub textblock { | ||||||||||||||||||||||||||
|
Subroutine
textblock: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||
| 67 | 79 | my ($self, $text, $linenum, $pod_para) = @_; | |||||||||||||||||||||||||||
| 68 | ### textblock: "linenum=$linenum" | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 79 | ▶ | if (($self->{'allow_next'}||0) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{'allow_next'} || 0
MC/DC0%0/1
$self->{'allow_next'} || 0
$self->{'allow_next'}
Truth table50%1/2
A
A= $self->{'allow_next'}
| |||||||||||||||||||||||||||||
| 71 | 0 | $self->{'allow_next'}--; | |||||||||||||||||||||||||||
| 72 | 0 | return ''; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # process outside =begin, and inside =begin which is ":" markup | ||||||||||||||||||||||||||||
| 76 | 79 | ▶ | unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
MC/DC0%0/2
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
$self->{"in_begin"} eq ""
$self->{"in_begin"} =~ /^:/
Truth table33%1/3
A or B
A= $self->{"in_begin"} eq ""B= $self->{"in_begin"} =~ /^:/
| |||||||||||||||||||||||||||||
| 77 | 0 | return ''; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 79 | my $interpolated = $self->interpolate($text, $linenum); | |||||||||||||||||||||||||||
| 81 | ### $text | ||||||||||||||||||||||||||||
| 82 | ### $interpolated | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 79 | ▶ | while ($interpolated =~ m{(^ | (?<=[\([:space:]])) # BOL or preceding space | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | ( | ||||||||||||||||||||||||||||
| 86 | /(bin|etc|dev|opt|proc|tmp|usr|var) | ||||||||||||||||||||||||||||
| 87 | ($ # EOL | ||||||||||||||||||||||||||||
| 88 | |(?=[)[:space:]]) # or following space | ||||||||||||||||||||||||||||
| 89 | |/\S*) # or /chars | ||||||||||||||||||||||||||||
| 90 | | | ||||||||||||||||||||||||||||
| 91 | [cC]:\\\S* | ||||||||||||||||||||||||||||
| 92 | ) | ||||||||||||||||||||||||||||
| 93 | }mgx) { | ||||||||||||||||||||||||||||
| 94 | 36 | my $before = $1; | |||||||||||||||||||||||||||
| 95 | 36 | my $match = $2; | |||||||||||||||||||||||||||
| 96 | 36 | $match =~ s/[.,;:]+$//; | |||||||||||||||||||||||||||
| 97 | 36 | my $pos = pos($interpolated) - length($match); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 36 | $self->violation_at_linenum_and_textpos | |||||||||||||||||||||||||||
| 100 | ("Filename without F<> or other markup \"$match\"\n", | ||||||||||||||||||||||||||||
| 101 | $linenum, $interpolated, $pos); | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 12 | ▶ | sub interior_sequence { | ||||||||||||||||||||||||||
|
Subroutine
interior_sequence: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 106 | 12 | my ($self, $cmd, $text, $pod_seq) = @_; | |||||||||||||||||||||||||||
| 107 | ### $cmd | ||||||||||||||||||||||||||||
| 108 | ### $text | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 12 | ▶ | if ($cmd eq 'E') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 3 | my $char = Pod::Escapes::e2char($text); | |||||||||||||||||||||||||||
| 112 | 3 | ▶ | if (! defined $char) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | ### oops, unrecognised E<> ... | ||||||||||||||||||||||||||||
| 114 | 0 | return 'X'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 3 | return $char; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 9 | ▶ | if ($cmd eq 'L') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 5 | my ($display, $inferred, $name, $section, $type) | |||||||||||||||||||||||||||
| 120 | = Pod::ParseLink::parselink ($text); | ||||||||||||||||||||||||||||
| 121 | ### $display | ||||||||||||||||||||||||||||
| 122 | ### $inferred | ||||||||||||||||||||||||||||
| 123 | ### $name | ||||||||||||||||||||||||||||
| 124 | 5 | return $inferred; # the display part, or the name part if no display | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | ### X,C keep only the newlines: $text | ||||||||||||||||||||||||||||
| 128 | 4 | $text =~ tr/\n//cd; | |||||||||||||||||||||||||||
| 129 | 4 | return $text; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 40 | 1; | |||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||