« blib/lib/Perl/Critic/Document.pm
↑ Summary
blib/lib/Perl/Critic/Policy/Variables/ProhibitReusedNames.pm »
| 1 | package Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings; | ||||||||||||||||||||||||||||||||||||||||||
| 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 List::SomeUtils qw(all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Perl::Critic::Exception::Fatal::Internal qw{ throw_internal }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters :severities :data_conversion }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 40 | our $VERSION = '1.150'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | Readonly::Scalar my $DESC => q{Warnings disabled}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $EXPL => [ 431 ]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 92 | ▶ | name => 'allow', | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | description => 'Permitted warning categories.', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | default_string => $EMPTY, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | parser => \&_parse_allow, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | name => 'allow_with_category_restriction', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | description => | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 'Allow "no warnings" if it restricts the kinds of warnings that are turned off.', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | default_string => '0', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | behavior => 'boolean', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 75 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 92 | ▶ | sub default_themes { return qw( core bugs pbp certrec ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 33 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | sub _parse_allow { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 90 | ▶ | my ($self, $parameter, $config_string) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_allow: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 90 | $self->{_allow} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 90 | ▶ | if( defined $config_string ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $allowed = lc $config_string; #String of words | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my %allowed = hashify( $allowed =~ m/ (experimental::\w+|\w+) /gxms ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $self->{_allow} = \%allowed; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 90 | return; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | sub violates { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 61 | ▶ | my ( $self, $elem, undef ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=44.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 61 | ▶ | return if $elem->type() ne 'no'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return if $elem->pragma() ne 'warnings'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my @words = _extract_potential_categories( $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | @words >= 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@words >= 2 and "no" eq $words[0] and "warnings" eq $words[1]
@words >= 2 and "no" eq $words[0]
MC/DC0%0/3
@words >= 2 and "no" eq $words[0] and "warnings" eq $words[1]
@words >= 2
"no" eq $words[0]
"warnings" eq $words[1]
Truth table0%0/4
A and B and C
A= @words >= 2B= "no" eq $words[0]C= "warnings" eq $words[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | and 'no' eq $words[0] | ||||||||||||||||||||||||||||||||||||||||||
| 74 | and 'warnings' eq $words[1] | ||||||||||||||||||||||||||||||||||||||||||
| 75 | or throw_internal | ||||||||||||||||||||||||||||||||||||||||||
| 76 | q<'no warnings' word list did not begin with qw{ no warnings }>; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | splice @words, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return if $self->{_allow_with_category_restriction} and @words; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_allow_with_category_restriction"} and @words
MC/DC0%0/2
$self->{"_allow_with_category_restriction"} and @words
$self->{"_allow_with_category_restriction"}
@words
Truth table0%0/3
A and B
A= $self->{"_allow_with_category_restriction"}B= @words
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return if @words && all { exists $self->{_allow}->{$_} } @words; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
@words and &all(sub {
MC/DC0%0/2
@words and &all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
@words
&all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
Truth table0%0/3
A and B
A= @wordsB= &all(sub {
exists $self->{"_allow"}{$_};
}
, @words)
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | #If we get here, then it must be a violation | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Traverse the element, accumulating and ultimately returning things | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # that might be warnings categories. These are: | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # * Words (because of the 'foo' in 'no warnings foo => "bar"'); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # * Quotes (because of 'no warnings "foo"'); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # * qw{} strings (obviously); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # * Nodes (because of 'no warnings ( "foo", "bar" )'). | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # We don't lop off the 'no' and 'warnings' because we recurse. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # RT #74647. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Readonly::Array my @HANDLER => ( | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | [ 'PPI::Token::Word' => sub { return $_[0]->content() } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | [ 'PPI::Token::QuoteLike::Words' => | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub { return $_[0]->literal() }, ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | [ 'PPI::Token::Quote' => sub { return $_[0]->string() } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | [ 'PPI::Node' => sub { _extract_potential_categories( $_[0] ) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | sub _extract_potential_categories { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my ( $elem ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_potential_categories: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my @words; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | foreach my $child ( $elem->schildren() ) { | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $hdlr ( @HANDLER ) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $child->isa( $hdlr->[0] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | or next; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | push @words, $hdlr->[1]->( $child ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return @words; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =for stopwords perllexwarn | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings - Prohibit various flavors of C<no warnings>. | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =head1 AFFILIATION | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | This Policy is part of the core L<Perl::Critic|Perl::Critic> | ||||||||||||||||||||||||||||||||||||||||||
| 143 | distribution. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | There are good reasons for disabling certain kinds of warnings. But | ||||||||||||||||||||||||||||||||||||||||||
| 149 | if you were wise enough to C<use warnings> in the first place, then it | ||||||||||||||||||||||||||||||||||||||||||
| 150 | doesn't make sense to disable them completely. By default, any | ||||||||||||||||||||||||||||||||||||||||||
| 151 | C<no warnings> statement will violate this policy. However, you can | ||||||||||||||||||||||||||||||||||||||||||
| 152 | configure this Policy to allow certain types of warnings to be | ||||||||||||||||||||||||||||||||||||||||||
| 153 | disabled (See L<"CONFIGURATION">). A bare C<no warnings> | ||||||||||||||||||||||||||||||||||||||||||
| 154 | statement will always raise a violation. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | The permitted warning types can be configured via the C<allow> option. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | The value is a list of whitespace-delimited warning types that you | ||||||||||||||||||||||||||||||||||||||||||
| 161 | want to be able to disable. See L<perllexwarn|perllexwarn> for a list | ||||||||||||||||||||||||||||||||||||||||||
| 162 | of possible warning types. An example of this customization: | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | [TestingAndDebugging::ProhibitNoWarnings] | ||||||||||||||||||||||||||||||||||||||||||
| 165 | allow = uninitialized once | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | If a true value is specified for the | ||||||||||||||||||||||||||||||||||||||||||
| 168 | C<allow_with_category_restriction> option, then any C<no warnings> | ||||||||||||||||||||||||||||||||||||||||||
| 169 | that restricts the set of warnings that are turned off will pass. | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | [TestingAndDebugging::ProhibitNoWarnings] | ||||||||||||||||||||||||||||||||||||||||||
| 172 | allow_with_category_restriction = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | L<Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings|Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | Copyright (c) 2005-2021 Imaginative Software Systems. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 189 | the same terms as Perl itself. The full text of this license can be found in | ||||||||||||||||||||||||||||||||||||||||||
| 190 | the LICENSE file included with this module | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # Local Variables: | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # mode: cperl | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # cperl-indent-level: 4 | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # fill-column: 78 | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # c-indentation-style: bsd | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # End: | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||||||||||||||||||||||||||||||||