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;
already but I'd like to have more.
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;
already but I'd like to have more.
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.
perl -Mstrict -cw myscript.pl
and it syntax checked just fine. –
Paralyze -c
can still execute your program and break you in hard way: perldoc.perl.org/… –
Kumar Perl::Critic is your friend. I use Test::Perl::Critic and build it into my code's author tests
ControlStructures::ProhibitUnreachableCode
policy for that, but it isn't all knowing. I don't believe it analyzes all constant expressions, for example, but it has picked up most blocks of dead code in some of my work. –
Ketose Devel::Cover
or other code profilers to find unreachable (untested in the case of Devel::Cover) code. –
Departmentalize 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.
perl -Mstrict -cw myscript.pl
and it syntax checked just fine. –
Paralyze -c
can still execute your program and break you in hard way: perldoc.perl.org/… –
Kumar 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.
© 2022 - 2024 — McMap. All rights reserved.