Perl的Lint式程序?

Cha*_*les 21 perl lint static-code-analysis

我正在为Perl寻找一个lint,它可以捕获死代码和其他潜在的问题.有什么建议?

我有

use strict;
use warnings;
Run Code Online (Sandbox Code Playgroud)

已经但我想要更多.

Stu*_*att 20

Perl ::评论家是你的朋友.我使用Test :: Perl :: Critic并将其构建到我的代码的作者测试中

  • 您还可以使用`Devel :: Cover`或其他代码分析器来查找无法访问(在Devel :: Cover的情况下未经测试)代码. (9认同)
  • @Charles是的,有一个`ControlStructures :: ProhibitUnreachableCode`政策,但并不是所有人都知道.例如,我不相信它会分析所有常量表达式,但它在我的一些工作中已经找到了大部分死代码. (3认同)

Mic*_*man 11

Perl没有直接相当于lint.其中很大一部分原因是Perl没有提供像C一样多的方法来挂起自己.Perl的"lint"的基本版本是这样的:

perl -Mstrict [-Mdiagnostics] -cw <file>
Run Code Online (Sandbox Code Playgroud)

这会导致perl在打开限制和警告的情况下编译(但不运行)指定的文件.如果您想要更详细的消息,可以使用诊断程序,或者如果简洁的消息足够您可以将其保留.

如果你想要更多的东西尝试使用Perl :: Critic,但要注意这不是真正的lint.lint主要关注错误(例如,会阻止编译,触发运行时错误,不可移植,依赖于未定义的行为等).Perl :: Critic更专注于编码标准的实施.虽然有一些重叠,但它们是完全不同的东西.

  • @Volomike:不要在命令行中包含方括号。它们用来表明其中的内容是可选的。 (2认同)

Alo*_*dal 5

使用B::Lint.您可以通过O使用Lint作为参数调用模块在命令行上使用它,例如:

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
Run Code Online (Sandbox Code Playgroud)