Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
First off, great job on Perl::Critic. The first thing I thought after reading PBP is "Hey, I wonder if there's a tool that would check my code for this stuff". And, as usual, it was on CPAN.

Here are my thoughts on some possible additions and modifications that might be useful:

  • A HOWTO document on writing custom policies. This would make it much easier for people who don't yet grok PPI (like myself) to just dive in and write something, whether it's implementing the remaining things from PBP that can be submitted back to you, or a set of policy modules to match their own internal coding standards.
  • Package configuration files for better editor integration. Being able to just type:
    :compiler perlcritic :make
    within Vim is very nice, and is easier to configure than the :grep hack I suggested earlier. I think I've already sent you my perlcritic.vim with instructions on setting it up, but if you didn't get it, let me know.
  • An extension to the ## no critic syntax that would allow (or optionally require?) an explanation of the reason for overriding the Perl::Critic check in that case. Maybe something like:
    ## no critic: All the bad stuff below is necessary because [...]
    I could see this being possibly implemented as a Perl::Critic::Policy::Pragma::NoCriticRequiresComments, except that the 'no critic' blocks get stripped out before the policies are applied. Not sure if there's an easy way around that.
  • A way to allow sets of policies to reference a URL, or page numbers in a different book. This would give you a mechanism to refer to the Safari version of PBP, or for new policies, allow them to refer to completely different documents altogether (ie: internal coding standards on company website, other books like Code Complete or AntiPatterns, or even just a 2nd edition of PBP with different page numbers).

    You could do it with a Perl::Critic::Reference class that would provide a lookup table and remove page references entirely from the Policy modules. You could look up the appropriate reference with something like:

    use Perl::Critic::Reference; my $ref = Perl::Critic::Reference->new(); # Load reference data for policies from three different files $ref->load( qw( PBP FooCorpCodingStyle CodeComplete ) ); # and later... my $explanation = $ref->lookup($violation->policy());
    Data files containing the explanation reference could be subclasses of Perl::Critic::Reference (with the parent delegating the ->lookup() to each of the load()'ed subclasses in order until a hit is found), or they could just be YAML files merged into a single hash for lookup.

Hmm... that Reference idea sounds useful, and not too difficult. If you'd take the patch, I think I might try coding it up.

One last comment before I head off to sleep. I'm not sure I agree with the idea that Perl::Critic could or should be enhanced to correct the code. I use Perl::Critic to warn me when I'm doing something silly, so that I can fix it, and by fixing it, learn to not do it again. If it tried to correct those things for me, there's less of an opportunity to learn. Plus, some of the things detected by the policies would be downright nasty, if not impossible, to auto-correct without potentially breaking the code.

In reply to Re: Request for Comments on Perl::Critic by dave0
in thread Request for Comments on Perl::Critic by jthalhammer

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-05-13 03:10 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (134 votes). Check out past polls.