Lint-like program for Perl?

前端 未结 4 1678
天命终不由人
天命终不由人 2021-02-07 01:38

I\'m looking for a lint for Perl, something that would catch dead code and other potential problems. Any suggestions?

I have

use strict;
use warnings;
<         


        
相关标签:
4条回答
  • 2021-02-07 02:18

    Perl doesn't have a direct equivalent to lint. A large part of the reason for that is that Perl doesn't provide quite as many ways to hang yourself as C does. The basic version of "lint" for Perl is this:

    perl -Mstrict [-Mdiagnostics] -cw <file>
    

    This causes perl to compile (but not run) the specified file with strictures and warnings turned on. You can use diagnostics if you want more verbose messages or leave it out if the terse ones are enough for you.

    If you want something more try using Perl::Critic, but be aware that this isn't really lint, either. lint primarily concerns itself with errors (e.g. things that would prevent compilation, trigger runtime errors, be non-portable, rely on undefined behavior, etc.). Perl::Critic is more focused on enforcement of coding standards. While there is some overlap they're very different things.

    0 讨论(0)
  • 2021-02-07 02:18

    In addition to Perl::Critic you might want to look at the newer Perl::Lint.

    0 讨论(0)
  • 2021-02-07 02:20

    Use B::Lint. You can use it on command line by calling O module with Lint as argument, e.g.:

    you@there:~/sandbox$ perl -MO=Lint Some.pm 
    Implicit scalar context for array in logical and (&&) at Some.pm line 121
    Implicit scalar context for array in conditional expression at Some.pm line 49
    Implicit scalar context for array in logical and (&&) at Some.pm line 132
    Some.pm syntax OK
    
    0 讨论(0)
  • 2021-02-07 02:22

    Perl::Critic is your friend. I use Test::Perl::Critic and build it into my code's author tests

    0 讨论(0)
提交回复
热议问题