开发者

Lint-like program for Perl?

开发者 https://www.devze.com 2023-03-23 06:26 出处:网络
I\'m looking for a lint for Perl, something that would catch dead code a开发者_运维百科nd other potential problems.Any suggestions?

I'm looking for a lint for Perl, something that would catch dead code a开发者_运维百科nd other potential problems. Any suggestions?

I have

use strict;
use warnings;

already but I'd like to have more.


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


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号