Subject: | Allow (via config) "no warnings" with at least one category |
Enumerating all the acceptable warning categories for "no warnings"
isn't useful for my project. I don't want to prohibit turning off
certain warning categories, I can't even think of what such a list might
be, project-wide. I just care that they don't turn them *all* off
indiscriminately.
This patch adds a "with_at_least_one" value to the "allow" options to
TestingAndDebugging::ProhibitNoWarnings. This allows any "no warnings"
that has any number of categories.
So with...
[TestingAndDebugging::ProhibitNoWarnings]
allow = with_at_least_one
The policy works like this...
no warnings; # bad
no warnings 'glob'; # good
no warnings 'glob', 'uninitialized'; # good
Patch attached.
Subject: | no_warnings.patch |
--- lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoWarnings.pm (revision 57939)
+++ lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoWarnings.pm (local)
@@ -51,6 +51,8 @@
if( defined $config_string ) {
my $allowed = lc $config_string; #String of words
my %allowed = hashify( $allowed =~ m/ (\w+) /gmx );
+
+ $self->{_allow_with_at_least_one} = delete $allowed{with_at_least_one} ? 1 : 0;
$self->{_allow} = \%allowed;
}
@@ -80,6 +82,8 @@
return if !$stmnt;
my @words = $stmnt =~ m/ ([[:lower:]]+) /gmx;
@words = grep { $_ ne 'qw' && $_ ne 'no' && $_ ne 'warnings' } @words;
+
+ return if $self->{_allow_with_at_least_one} and @words;
return if all { exists $self->{_allow}->{$_} } @words;
#If we get here, then it must be a violation
@@ -128,6 +132,11 @@
[TestingAndDebugging::ProhibitNoWarnings]
allow = uninitialized once
+A special case is the "with_at_least_one" value which indicates that
+C<no warnings> must be qualified by at least one category.
+
+ [TestingAndDebugging::ProhibitNoWarnings]
+ allow = with_at_least_one
=head1 SEE ALSO
--- t/TestingAndDebugging/ProhibitNoWarnings.run (revision 57939)
+++ t/TestingAndDebugging/ProhibitNoWarnings.run (local)
@@ -67,3 +67,35 @@
package foo;
no warnings qw(numeric pack portable);
+
+#-----------------------------------------------------------------------------
+
+## name with_at_least_one, no categories
+## failures 1
+## parms { allow => 'with_at_least_one' }
+## cut
+
+package foo;
+no warnings;
+
+#-----------------------------------------------------------------------------
+
+## name with_at_least_one, one category
+## failures 0
+## parms { allow => 'with_at_least_one' }
+## cut
+
+package foo;
+no warnings "uninitalized";
+
+#-----------------------------------------------------------------------------
+
+## name with_at_least_one, many categories
+## failures 0
+## parms { allow => 'with_at_least_one' }
+## cut
+
+package foo;
+no warnings "uninitialized", "glob";
+
+