1B::Lint(3)            User Contributed Perl Documentation           B::Lint(3)
2
3
4

NAME

6       B::Lint - Perl lint
7

SYNOPSIS

9       perl -MO=Lint[,OPTIONS] foo.pl
10

DESCRIPTION

12       The B::Lint module is equivalent to an extended version of the -w
13       option of perl. It is named after the program lint which carries out a
14       similar process for C programs.
15

OPTIONS AND LINT CHECKS

17       Option words are separated by commas (not whitespace) and follow the
18       usual conventions of compiler backend options. Following any options
19       (indicated by a leading -) come lint check arguments. Each such
20       argument (apart from the special all and none options) is a word
21       representing one possible lint check (turning on that check) or is no-
22       foo (turning off that check). Before processing the check arguments, a
23       standard list of checks is turned on. Later options override earlier
24       ones. Available options are:
25
26       magic-diamond
27               Produces a warning whenever the magic "<>" readline is used.
28               Internally it uses perl's two-argument open which itself treats
29               filenames with special characters specially. This could allow
30               interestingly named files to have unexpected effects when
31               reading.
32
33                 % touch 'rm *|'
34                 % perl -pe 1
35
36               The above creates a file named "rm *|". When perl opens it with
37               "<>" it actually executes the shell program "rm *". This makes
38               "<>" dangerous to use carelessly.
39
40       context Produces a warning whenever an array is used in an implicit
41               scalar context. For example, both of the lines
42
43                   $foo = length(@bar);
44                   $foo = @bar;
45
46               will elicit a warning. Using an explicit scalar() silences the
47               warning. For example,
48
49                   $foo = scalar(@bar);
50
51       implicit-read and implicit-write
52               These options produce a warning whenever an operation
53               implicitly reads or (respectively) writes to one of Perl's
54               special variables.  For example, implicit-read will warn about
55               these:
56
57                   /foo/;
58
59               and implicit-write will warn about these:
60
61                   s/foo/bar/;
62
63               Both implicit-read and implicit-write warn about this:
64
65                   for (@a) { ... }
66
67       bare-subs
68               This option warns whenever a bareword is implicitly quoted, but
69               is also the name of a subroutine in the current package.
70               Typical mistakes that it will trap are:
71
72                   use constant foo => 'bar';
73                   @a = ( foo => 1 );
74                   $b{foo} = 2;
75
76               Neither of these will do what a naive user would expect.
77
78               Notice: Perl 5.22.0 does not report "foo" in $b{foo} as BARE
79               token anymore. Therefore B::Lint test is not reliable here. See
80               CPAN RT#101115
81               <https://rt.cpan.org/Public/Bug/Display.html?id=101115>.
82
83       dollar-underscore
84               This option warns whenever $_ is used either explicitly
85               anywhere or as the implicit argument of a print statement.
86
87       private-names
88               This option warns on each use of any variable, subroutine or
89               method name that lives in a non-current package but begins with
90               an underscore ("_"). Warnings aren't issued for the special
91               case of the single character name "_" by itself (e.g. $_ and
92               @_).
93
94       undefined-subs
95               This option warns whenever an undefined subroutine is invoked.
96               This option will only catch explicitly invoked subroutines such
97               as "foo()" and not indirect invocations such as "&$subref()" or
98               "$obj->meth()". Note that some programs or modules delay
99               definition of subs until runtime by means of the AUTOLOAD
100               mechanism.
101
102       regexp-variables
103               This option warns whenever one of the regexp variables "$`", $&
104               or "$'" is used. Any occurrence of any of these variables in
105               your program can slow your whole program down. See perlre for
106               details.
107
108       all     Turn all warnings on.
109
110       none    Turn all warnings off.
111

NON LINT-CHECK OPTIONS

113       -u Package
114               Normally, Lint only checks the main code of the program
115               together with all subs defined in package main. The -u option
116               lets you include other package names whose subs are then
117               checked by Lint.
118

EXTENDING LINT

120       Lint can be extended by with plugins. Lint uses Module::Pluggable to
121       find available plugins. Plugins are expected but not required to inform
122       Lint of which checks they are adding.
123
124       The "B::Lint->register_plugin( MyPlugin => \@new_checks )" method adds
125       the list of @new_checks to the list of valid checks. If your module
126       wasn't loaded by Module::Pluggable then your class name is added to the
127       list of plugins.
128
129       You must create a "match( \%checks )" method in your plugin class or
130       one of its parents. It will be called on every op as a regular method
131       call with a hash ref of checks as its parameter.
132
133       The class methods "B::Lint->file" and "B::Lint->line" contain the
134       current filename and line number.
135
136         package Sample;
137         use B::Lint;
138         B::Lint->register_plugin( Sample => [ 'good_taste' ] );
139
140         sub match {
141             my ( $op, $checks_href ) = shift @_;
142             if ( $checks_href->{good_taste} ) {
143                 ...
144             }
145         }
146

TODO

148       while(<FH>) stomps $_
149       strict oo
150       unchecked system calls
151       more tests, validate against older perls
152

BUGS

154       This is only a very preliminary version.
155

AUTHOR

157       Malcolm Beattie, mbeattie@sable.ox.ac.uk.
158

ACKNOWLEDGEMENTS

160       Sebastien Aperghis-Tramoni - bug fixes
161
162
163
164perl v5.30.1                      2020-01-29                        B::Lint(3)
Impressum