From 48056d5ed4fd76f07775a1a4b1abe5cdc2754cd1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 4 Apr 2024 16:47:13 -0700 Subject: [PATCH] update docs, change name -wmacc to -wmauc --- bin/perltidy | 35 +++++++++++++++++++++++------------ lib/Perl/Tidy.pm | 10 +++++----- lib/Perl/Tidy/Formatter.pm | 12 ++++++------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index 32ff5987..b724ea33 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -6102,12 +6102,10 @@ B =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 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. @@ -6115,6 +6113,10 @@ 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 @@ -6128,27 +6130,36 @@ The default is not to do any of these checks, which can also be indicated with B To restrict the check to a specific warning type, set the string equal to the letter of that warning, either B or B. For example - perltidy -wmat='*' somefile.pl + perltidy -wmat='c' somefile.pl -will format F and report any call arg mismatches found. +will format F 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. This -number B 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 or less. Please note that this number B 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. 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 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 as usual and check for all mismatch types. But skip +checking for any sub named C, and only warn of undercounts for subs +expecting more than 2 args. + =back =head2 B diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index c104b796..31a1e1b4 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -3718,9 +3718,9 @@ sub generate_options { $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', '!' ); @@ -3871,7 +3871,7 @@ sub generate_options { 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 @@ -4030,7 +4030,7 @@ sub generate_options { '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 ], diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index f243ae65..49b4e27d 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -14106,13 +14106,13 @@ sub cross_check_call_args { # 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; } @@ -14354,7 +14354,7 @@ sub cross_check_call_args { # 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); @@ -14371,7 +14371,7 @@ sub cross_check_call_args { } 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, @@ -14545,7 +14545,7 @@ sub warn_mismatched_args { # 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}; -- 2.39.5