File Coverage

blib/lib/Perl/Critic/Policy/Documentation/ProhibitParagraphTwoDots.pm
Criterion Covered Total %
statement 60 60 100.0
branch 8 8 100.0
condition 2 3 66.6
subroutine 17 17 100.0
pod 1 1 100.0
total 88 89 98.8


line stmt bran cond sub pod time code
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     40   33582 use 5.006;
  40         166  
27 40     40   242 use strict;
  40         97  
  40         840  
28 40     40   210 use warnings;
  40         87  
  40         1085  
29 40     40   229 use base 'Perl::Critic::Policy';
  40         104  
  40         4743  
30 40     40   180952 use Perl::Critic::Utils;
  40         104  
  40         782  
31              
32             # uncomment this to run the ### lines
33             #use Smart::Comments;
34              
35             our $VERSION = 99;
36              
37 40     40   36662 use constant supported_parameters => ();
  40         106  
  40         2779  
38 40     40   273 use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOWEST;
  40         98  
  40         2456  
39 40     40   262 use constant default_themes => qw(pulp cosmetic);
  40         93  
  40         2357  
40 40     40   312 use constant applies_to => 'PPI::Document';
  40         114  
  40         5824  
41              
42             sub violates {
43 29     29 1 561198 my ($self, $elem, $document) = @_;
44             ### ProhibitParagraphTwoDots on: $elem->content
45              
46 29         425 my $parser = Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots->new
47             (policy => $self);
48 29         131 $parser->parse_from_elem ($elem);
49 29         129 return $parser->violations;
50             }
51              
52             package Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots;
53 40     40   410 use strict;
  40         118  
  40         1294  
54 40     40   279 use warnings;
  40         123  
  40         1356  
55 40     40   811 use Pod::ParseLink;
  40         962  
  40         2133  
56 40     40   293 use base 'Perl::Critic::Pulp::PodParser';
  40         116  
  40         18343  
57              
58             sub command {
59 31     31   2827 my $self = shift;
60 31         161 $self->SUPER::command(@_); # maintain 'in_begin'
61 31         139 return $self->command_as_textblock(@_);
62             }
63              
64             sub textblock {
65 51     51   1552 my ($self, $text, $linenum, $pod_para) = @_;
66             ### textblock: "linenum=$linenum"
67              
68             # "=begin :foo" is markup, check it. Other =begin is not markup.
69 51 100 66     191 unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) {
70 1         41 return '';
71             }
72              
73 50         2524 my $str = $self->interpolate($text, $linenum);
74             ### $text
75             ### $str
76              
77 50 100       296 if ($str =~ /(?<!\.)(\.\.\s*)$/sg) {
78 13         80 $text =~ /(\s*)$/;
79 13         43 my $pos = length($text) - length($1); # end of $text
80             ### $pos
81 13         70 $self->violation_at_linenum_and_textpos
82             ("Paragraph ends with two dots (stray extra?)", $linenum, $text, $pos);
83             }
84 50         584 return '';
85             }
86             sub interior_sequence {
87 7     7   31 my ($self, $cmd, $text, $pod_seq) = @_;
88 7 100       32 if ($cmd eq 'X') {
    100          
89             # index entry, no text output, but keep newlines for linenum
90 1         4 $text =~ tr/\n//cd;
91              
92             } elsif ($cmd eq 'L') {
93 3         17 my ($display, $inferred, $name, $section, $type)
94             = Pod::ParseLink::parselink ($text);
95             ### $display
96             ### $inferred
97             ### $name
98 3         230 return $inferred; # the display part, or the name part if no display
99             }
100 4         140 return $text;
101             }
102              
103             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