=over 4
=item *
-Only sub definitions within the file being processed are checked. Anonymous subs and lexical subs (introduced with 'my') are not currently checked.
+Only subs for which the call args are unpacked in an orderly manner at the beginning of the sub from C<@_>, directly and/or with C<shift> operations, are checked. Subs for which this does not appear to be the case are skipped.
=item *
-The number of arguments expected by a sub is determined by scanning the initial
-lines of the sub for extractions from C<@_>. If args are extracted or used in
-later code, then that sub will be skipped, or the analysis could be in error.
+Subs which appear to have no args are not checked. This is necessary to avoid false warnings when a sub actually uses args in a complex way.
=item *
Only calls which appear to be to subs defined within the file are checked.
=item *
Sub calls made without parentheses around the args are not checked.
+=item *
+Anonymous subs and lexical subs (introduced with 'my') are not currently
+checked.
+
=back
=item B<Use --warn-mismatched-arg-types=s to produce a warning for function calls with args not matching sub declarations>
To restrict the check to a specific warning type, set the string equal to the letter of that warning, either B<a> or B<c>. For example
- perltidy -wmat='*' somefile.pl
+ perltidy -wmat='c' somefile.pl
-will format F<somefile.pl> and report any call arg mismatches found.
+will format F<somefile.pl> and report any call arg count mismatches found but
+will skip checking for arrow-type mismatches.
A companion control parameter B<--warn-mismatched-arg-exclusion-list>, or
B<-wmaxl=string>, can be given to skip the warning checks for a list of
subroutine names.
-Another control parameter B<--warn-mismatched-arg-cutoff-count=n>, or
-B<-wmacc=n>, can be used to avoid warnings when a sub is called with fewer args
-than expected, and the number of args expected is not greater than B<n>. This
-number B<n> is the number of args from the point of view of the sub definition,
-so an object like C<$self> passed with an arrow operator counts as one arg.
+Another control parameter B<--warn-mismatched-arg-undercount-cutoff=n>, or
+B<-wmauc=n>, can be used to avoid undercount warnings when the number of
+args expected is B<n> or less. Please note that this number B<n> is the number
+of args from the point of view of the sub definition, so an object like
+C<$self> passed with an arrow operator counts as one arg.
The default value is B<n=4>. This has been found to allow most programs to pass
without warnings, but it should be reduced if possible for better error
checking. The minimum possible value of B<n> for a program can be determined
-by running with -wmacc=0, or by running the -dump version. The output shows,
+by running with -wmauc=0, or by running the -dump version. The output shows,
for each mismatch, the number of args expected by a sub plus the range of the
number of args actually passed to it.
+For example
+
+ perltidy -wmat='*' -wmaxl='new' -wmauc=2 somefile.pl
+
+means format F<somefile.pl> as usual and check for all mismatch types. But skip
+checking for any sub named C<new>, and only warn of undercounts for subs
+expecting more than 2 args.
+
=back
=head2 B<Working with MakeMaker, AutoLoader and SelfLoader>
$add_option->( 'want-call-parens', 'wcp', '=s' );
$add_option->( 'nowant-call-parens', 'nwcp', '=s' );
- $add_option->( 'warn-mismatched-arg-types', 'wmat', '=s' );
- $add_option->( 'warn-mismatched-arg-count-cutoff', 'wmacc', '=i' );
- $add_option->( 'warn-mismatched-arg-exclusion-list', 'wmaxl', '=s' );
+ $add_option->( 'warn-mismatched-arg-types', 'wmat', '=s' );
+ $add_option->( 'warn-mismatched-arg-undercount-cutoff', 'wmauc', '=i' );
+ $add_option->( 'warn-mismatched-arg-exclusion-list', 'wmaxl', '=s' );
$add_option->( 'add-interbracket-arrows', 'aia', '!' );
$add_option->( 'delete-interbracket-arrows', 'dia', '!' );
maximum-unexpected-errors=0
memoize
minimum-space-to-comment=4
- warn-mismatched-arg-count-cutoff=4
+ warn-mismatched-arg-undercount-cutoff=4
nobrace-left-and-indent
nocuddled-else
nodelete-old-whitespace
'maximum-line-length' => [ 0, undef ],
'maximum-unexpected-errors' => [ 0, undef ],
'minimum-space-to-comment' => [ 0, undef ],
- 'warn-mismatched-arg-count-cutoff' => [ 0, undef ],
+ 'warn-mismatched-arg-undercount-cutoff' => [ 0, undef ],
'one-line-block-nesting' => [ 0, 1 ],
'one-line-block-semicolons' => [ 0, 2 ],
'paren-tightness' => [ 0, 2 ],
# initialize for dump mode
my $ris_mismatched_call_type = { 'a' => 1, 'c' => 1 };
- my $mismatched_arg_count_cutoff = 0;
+ my $mismatched_arg_undercount_cutoff = 0;
my $ris_mismatched_call_excluded_name = {};
if ($warn_mode) {
$ris_mismatched_call_type = \%warn_mismatched_arg_types;
- $mismatched_arg_count_cutoff =
- $rOpts->{'warn-mismatched-arg-count-cutoff'};
+ $mismatched_arg_undercount_cutoff =
+ $rOpts->{'warn-mismatched-arg-undercount-cutoff'};
$ris_mismatched_call_excluded_name =
\%is_warn_mismatched_arg_excluded_name;
}
# Skip the warning for small lists with undercount
my $expect = $num_self ? $shift_count : $shift_count + 1;
if ( $num_over_count
- || $expect > $mismatched_arg_count_cutoff )
+ || $expect > $mismatched_arg_undercount_cutoff )
{
my $lines_over_count = stringify_line_range($rover_count);
my $lines_under_count = stringify_line_range($runder_count);
}
else {
$note =
-"undefined args at $num_under_count of $total calls($lines_under_count)";
+"missing args at $num_under_count of $total calls($lines_under_count)";
}
push @warnings,
# additional control parameters are:
# - mismatched-arg-exclusion-list
- # - warn-mismatched-call-count-cutoff
+ # - warn-mismatched-arg-undercount-cutoff
my $wma_key = 'warn-mismatched-arg-types';
my $wma_option = $rOpts->{$wma_key};