Policy/Documentation/ProhibitParagraphTwoDots.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 8 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 17 / 17 Podpod 100% 1 / 1 totaltotal 97.8% 91 / 93 SCAR 17.9
CC
6
Cov
99%
textblock
4.0
interior_sequence
3.0
BEGIN
1.0
CRAP 6.0
« Policy/Modules/ProhibitModuleShebang.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitFiletest_f.pm »
1 # Copyright 2011, 2012, 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 ProhibitParagraphTwoDots ProhibitParagraphTwoDots.pm
20 # perlcritic -s ProhibitParagraphTwoDots /usr/share/perl5/HTML/FormatText/WithLinks.pm
21  
22 # Maybe foo.Z<>. to disguise two dots?
23  
24  
25 package Perl::Critic::Policy::Documentation::ProhibitParagraphTwoDots;
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  
32 # uncomment this to run the ### lines
33 #use Smart::Comments;
34  
35 40 our $VERSION = 99;
36  
37 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOWEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 sub violates {
43 29 ▶ my ($self, $elem, $document) = @_;
Subroutine violates: called CC=1 SCAR=0.0
Pod documented
44 ### ProhibitParagraphTwoDots on: $elem->content
45  
46 29 my $parser = Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots->new
47 (policy => $self);
48 29 $parser->parse_from_elem ($elem);
49 29 return $parser->violations;
50 }
51  
52 package Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots;
53 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 40 ▶use Pod::ParseLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 40 ▶use base 'Perl::Critic::Pulp::PodParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 sub command {
59 31 ▶ my $self = shift;
Subroutine command: called CC=1 SCAR=0.0
60 31 $self->SUPER::command(@_); # maintain 'in_begin'
61 31 return $self->command_as_textblock(@_);
62 }
63  
64 sub textblock {
65 51 ▶ my ($self, $text, $linenum, $pod_para) = @_;
Subroutine textblock: called CC=4 SCAR=13.9
66 ### textblock: "linenum=$linenum"
67  
68 # "=begin :foo" is markup, check it. Other =begin is not markup.
69 51 ▶ unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/) 1 50 51
Condition66%2/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
l!l&&r!l&&!r
5001
MC/DC50%1/2
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
$self->{"in_begin"} eq "" $self->{"in_begin"} =~ /^:/
Truth table66%2/3
A or B
A= $self->{"in_begin"} eq ""B= $self->{"in_begin"} =~ /^:/
ABresult
1X1
011
000
70 1 return '';
71 }
72  
73 50 my $str = $self->interpolate($text, $linenum);
74 ### $text
75 ### $str
76  
77 50 ▶ if ($str =~ /(?<!\.)(\.\.\s*)$/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?<!\.)(\.\.\s*)$/gs) 13 37 50
78 13 $text =~ /(\s*)$/;
79 13 my $pos = length($text) - length($1); # end of $text
80 ### $pos
81 13 $self->violation_at_linenum_and_textpos
82 ("Paragraph ends with two dots (stray extra?)", $linenum, $text, $pos);
83 }
84 50 return '';
85 }
86 sub interior_sequence {
87 7 ▶ my ($self, $cmd, $text, $pod_seq) = @_;
Subroutine interior_sequence: called CC=3 SCAR=11.0
88 7 ▶ if ($cmd eq 'X') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd eq 'X') { } 1 6 7
elsif ($cmd eq 'L') { } 3 3 6
89 # index entry, no text output, but keep newlines for linenum
90 1 $text =~ tr/\n//cd;
91  
92 } elsif ($cmd eq 'L') {
93 3 my ($display, $inferred, $name, $section, $type)
94 = Pod::ParseLink::parselink ($text);
95 ### $display
96 ### $inferred
97 ### $name
98 3 return $inferred; # the display part, or the name part if no display
99 }
100 4 return $text;
101 }
102  
103 40 1;
104 __END__
105  
106 =for stopwords Ryde
107  
108 =head1 NAME
109  
110 Perl::Critic::Policy::Documentation::ProhibitParagraphTwoDots - don't end a paragraph with two dots
111  
112 =head1 DESCRIPTION
113  
114 This policy is part of the L<C<Perl::Critic::Pulp>|Perl::Critic::Pulp>
115 add-on. It asks you not to end a POD paragraph with two dots,
116  
117 Some thing.. # bad
118  
119 This is a surprisingly easy typo, but of course is entirely cosmetic and on
120 that basis this policy is lowest severity and under the "cosmetic" theme
121 (see L<Perl::Critic/POLICY THEMES>).
122  
123 Three or more dots as an ellipsis is fine,
124  
125 And some more of this ... # ok
126  
127 and anything within a paragraph is fine,
128  
129 Numbers 1 .. 10 are handled. # ok
130  
131 Only text paragraphs are checked. Verbatim paragraphs can end with anything
132 at all
133  
134 This is an example,
135  
136 example_code (1 .. # ok
137  
138 There might be other dubious paragraph endings this policy could pick up,
139 but things like ";." or ":." can arise from code or smiley faces, so at the
140 moment only two dots are bad.
141  
142 =head2 Disabling
143  
144 If you don't care about this you can disable C<ProhibitParagraphTwoDots>
145 from your F<.perlcriticrc> in the usual way (see
146 L<Perl::Critic/CONFIGURATION>),
147  
148 [-Documentation::ProhibitParagraphTwoDots]
149  
150 A C<## no critic> directive works in new enough C<Perl::Critic>, but if you
151 have an C<__END__> token then any C<no critic> generally must be before
152 that.
153  
154 =head1 SEE ALSO
155  
156 L<Perl::Critic::Pulp>,
157 L<Perl::Critic>
158  
159 L<Perl::Critic::Policy::Documentation::ProhibitParagraphEndComma>
160  
161 =head1 HOME PAGE
162  
163 L<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
164  
165 =head1 COPYRIGHT
166  
167 Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
168  
169 Perl-Critic-Pulp is free software; you can redistribute it and/or modify it
170 under the terms of the GNU General Public License as published by the Free
171 Software Foundation; either version 3, or (at your option) any later
172 version.
173  
174 Perl-Critic-Pulp is distributed in the hope that it will be useful, but
175 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
176 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
177 more details.
178  
179 You should have received a copy of the GNU General Public License along with
180 Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
181  
182 =cut
« Policy/Modules/ProhibitModuleShebang.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitFiletest_f.pm »