Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New configuration parameter exempt_pod #10

Open
wants to merge 5 commits into from

2 participants

Jonas B. Nielsen Andy Lester
Jonas B. Nielsen

Hello,

I have implemented a configurable parameter exempt_pod for allowing the user of the policy to specify that POD should not be evaluated. This is a first shot, I would love to be able to do this on two levels so I could differentiate keywords matching actual part of POD and casual comments in POD, but this would require a POD parser. This first implementation can be regarded as a starting point for further exploration of the problem area.

Looking forward to hearing from you,

jonasbn

jonasbn added some commits
Jonas B. Nielsen jonasbn First shot at implementation of pod exemption.
Pondering whether we need different configuration options for keywords
in and part of pod. The ability to distinguish might prove useful later

Tests fail now so I am one happy camper
5461d65
Jonas B. Nielsen jonasbn Now with a working policy and all tests pass. It would however be
nice with a test, testing the actual exemption, since all we can
observe now is that previous behaviour (default?) is working
2759a31
Jonas B. Nielsen jonasbn Added test of actual exemption 7ae879c
Jonas B. Nielsen jonasbn Added POD on the configurable parameter f304510
Andy Lester
Owner

I'm not understanding the use case here. Is your goal to be able to say "XXX" and "README" are OK in POD but in inline comments?

Jonas B. Nielsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 14, 2014
  1. Jonas B. Nielsen

    First shot at implementation of pod exemption.

    jonasbn authored
    Pondering whether we need different configuration options for keywords
    in and part of pod. The ability to distinguish might prove useful later
    
    Tests fail now so I am one happy camper
  2. Jonas B. Nielsen

    Now with a working policy and all tests pass. It would however be

    jonasbn authored
    nice with a test, testing the actual exemption, since all we can
    observe now is that previous behaviour (default?) is working
  3. Jonas B. Nielsen

    Added test of actual exemption

    jonasbn authored
  4. Jonas B. Nielsen
Commits on Jan 31, 2014
  1. Jonas B. Nielsen
This page is out of date. Refresh to see the latest.
20 lib/Perl/Critic/Policy/Bangs/ProhibitFlagComments.pm
View
@@ -17,6 +17,12 @@ sub supported_parameters {
behavior => 'string list',
default_string => 'XXX FIXME TODO',
},
+ {
+ name => 'exempt_pod',
+ description => 'Flag to enable exemption of policy evaluation in POD context.',
+ default_string => '0',
+ behavior => 'boolean',
+ },
);
}
@@ -24,12 +30,16 @@ sub default_severity { return $SEVERITY_LOW }
sub default_themes { return qw( bangs maintenance ) }
sub applies_to { return qw( PPI::Token::Comment PPI::Token::Pod ) }
-
#---------------------------------------------------------------------------
sub violates {
my ( $self, $elem, $doc ) = @_;
+ #We are in POD context, so we consider the exempt POD parameter
+ if (ref $elem eq 'PPI::Token::Pod' and $self->{_exempt_pod}) {
+ return;
+ }
+
foreach my $keyword ( keys %{ $self->{'_keywords'} } ) {
if ( index( $elem->content(), $keyword ) != -1 ) { ## no critic (ProhibitMagicNumbers)
my $desc = qq(Flag comment '$keyword' found);
@@ -68,6 +78,14 @@ in your F<.perlcriticrc> file like this:
[Bangs::ProhibitFlagComments]
keywords = XXX TODO FIXME BUG REVIEW
+In addition you can enable exemption of examination of POD sections
+using the exempt_pod flag.
+
+ [Bangs::ProhibitFlagComments]
+ exempt_pod = 1
+
+POD is not exempted by default
+
=head1 AUTHOR
Andrew Moore <amoore@mooresystems.com>
2  t/14_policy_parameters.t
View
@@ -11,7 +11,7 @@ use Perl::Critic::PolicyParameter qw{ $NO_DESCRIPTION_AVAILABLE };
use Perl::Critic::Utils qw( policy_short_name );
use Perl::Critic::TestUtils qw(bundled_policy_names);
-use Test::More tests => 14;
+use Test::More tests => 16;
Perl::Critic::TestUtils::block_perlcriticrc();
16 t/Bangs/ProhibitFlagComments.run
View
@@ -22,10 +22,10 @@ my $XXX = 'foo';
=head1 SYNOPSIS
-FIXME: needs a description
-
=over 4
+FIXME: needs a description
+
=item one
TODO
@@ -35,4 +35,16 @@ TODO
=cut
#-----------------------------------------------------------------------------
+
+## name Flags as POD
+## failures 0
+## parms { exempt_pod => 1 };
+## cut
+
+=head1 TODO
+
+=cut
+
+#-----------------------------------------------------------------------------
+
# ex: set ft=perl:
Something went wrong with that request. Please try again.