| 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 ProhibitDuplicateSeeAlso ProhibitDuplicateSeeAlso.pm | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | package Perl::Critic::Policy::Documentation::ProhibitDuplicateSeeAlso; | ||||||||||||||||||||||||||||
| 23 | 40 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 40 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 40 | ▶ | use Perl::Critic::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 30 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 40 | our $VERSION = 100; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 40 | ▶ | use constant supported_parameters => (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 40 | ▶ | use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 40 | ▶ | use constant default_themes => qw(pulp cosmetic); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 40 | ▶ | use constant applies_to => 'PPI::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 8 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 8 | my ($self, $elem, $document) = @_; | |||||||||||||||||||||||||||
| 41 | # ### ProhibitDuplicateSeeAlso on: $elem->content | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 8 | my $parser = Perl::Critic::Pulp::PodParser::ProhibitDuplicateSeeAlso->new | |||||||||||||||||||||||||||
| 44 | (policy => $self); | ||||||||||||||||||||||||||||
| 45 | 8 | $parser->parse_from_elem ($elem); | |||||||||||||||||||||||||||
| 46 | 8 | return $parser->violations; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | package Perl::Critic::Pulp::PodParser::ProhibitDuplicateSeeAlso; | ||||||||||||||||||||||||||||
| 50 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 40 | ▶ | use Pod::ParseLink; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 40 | ▶ | use base 'Perl::Critic::Pulp::PodParser'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | ▶ | sub command { | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 56 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 11 | my ($command, $text, $linenum, $paraobj) = @_; | |||||||||||||||||||||||||||
| 58 | 11 | $self->SUPER::command(@_); # maintain 'in_begin' | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 11 | ▶ | if ($command eq 'head1') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 9 | $self->{'in_see_also'} = ($text =~ /^\s*SEE\s+ALSO\b/); | |||||||||||||||||||||||||||
| 62 | ### in_see_also: $self->{'in_see_also'} | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 11 | return $self->command_as_textblock(@_); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 20 | ▶ | sub textblock { | ||||||||||||||||||||||||||
|
Subroutine
textblock: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 68 | 20 | my ($self, $text, $linenum, $pod_obj) = @_; | |||||||||||||||||||||||||||
| 69 | ### textblock(): "linenum=$linenum" | ||||||||||||||||||||||||||||
| 70 | ### $text | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Ignore all =begin blocks for now. | ||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||
| 74 | # Distinct "=begin :foo" and "=begin :bar" blocks would be mutually | ||||||||||||||||||||||||||||
| 75 | # exclusive and duplicates between don't matter. | ||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||
| 77 | # Multiple blocks "=begin :foo" or of an =begin and non-begin should not | ||||||||||||||||||||||||||||
| 78 | # duplicate, but expect such things to be rare. | ||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||
| 80 | 20 | ▶ | unless ($self->{'in_begin'} eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | return ''; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 19 | $self->interpolate($text, $linenum); | |||||||||||||||||||||||||||
| 85 | 19 | return ''; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 16 | ▶ | sub interior_sequence { | ||||||||||||||||||||||||||
|
Subroutine
interior_sequence: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 89 | 16 | my ($self, $cmd, $text, $pod_obj) = @_; | |||||||||||||||||||||||||||
| 90 | ### interior_sequence() ... | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 16 | ▶ | if ($self->{'in_see_also'} && $cmd eq 'L') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"in_see_also"} and $cmd eq "L"
MC/DC100%2/2
$self->{"in_see_also"} and $cmd eq "L"
$self->{"in_see_also"}
$cmd eq "L"
Truth table100%3/3
A and B
A= $self->{"in_see_also"}B= $cmd eq "L"
| |||||||||||||||||||||||||||||
| 93 | 14 | my ($display, $inferred, $name, $section, $type) | |||||||||||||||||||||||||||
| 94 | = Pod::ParseLink::parselink ($text); | ||||||||||||||||||||||||||||
| 95 | ### $name | ||||||||||||||||||||||||||||
| 96 | ### $section | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 14 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 14 | ▶ | if (! defined $section) { $section = ''; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 14 | (undef, my $linenum) = $pod_obj->file_line; | |||||||||||||||||||||||||||
| 102 | 14 | ▶ | if (defined (my $prev_linenum = $self->{'seen'}->{$name,$section})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | $self->violation_at_linenum_and_textpos | |||||||||||||||||||||||||||
| 105 | ("Duplicate SEE ALSO link L<$text> (already at line $prev_linenum)", | ||||||||||||||||||||||||||||
| 106 | $linenum, '', 0); | ||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||
| 108 | 12 | $self->{'seen'}->{$name,$section} = $linenum; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 16 | return ''; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 40 | 1; | |||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||