From: Steve Hancock Date: Sat, 27 Apr 2024 00:31:31 +0000 (-0700) Subject: add --warn-mismatched-arg-overcount-cutoff=n X-Git-Tag: 20240511~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f2e7f36819f906b40e132902f90e8012e5b93199;p=perltidy.git add --warn-mismatched-arg-overcount-cutoff=n --- diff --git a/bin/perltidy b/bin/perltidy index fd6f0d18..ab34e367 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -6127,10 +6127,6 @@ B =over 4 -=item * -When prototypes or signatures are given, they are used to determine the -expected number of sub arguments. Otherwise, the sub text is scanned. - =item * This option works best for subs which unpack call args in an orderly manner near the beginning of the sub from C<@_> and/or with C @@ -6147,6 +6143,10 @@ Anonymous subs and lexical subs (introduced with C) are not checked. Only calls which appear to be to subs defined within the file being processed are checked. But note that a file may contain multiple packages. +=item * +When prototypes or signatures are given, they are used to determine the +expected number of sub arguments. Otherwise, the sub text is scanned. + =back =item B, or B<-wmauc=n>, can be used to -avoid undercount warnings when the number of args expected is B or less. +avoid B warnings when the expected number of args is less than B. 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 +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 needed to avoid triggering an error for a program can be determined by running with B<-wma -wmauc=0>. If there are undercount errors, a note at the bottom of the error output indicates the value of B required to avoid reporting them. +=item * +B<--warn-mismatched-arg-overcount-cutoff=n>, or B<-wmaoc=n>, can be used to +avoid B warnings when the expected number of args is less than B. +The default value is B. This avoids warning messages for subroutines +which are dummy placeholders for future development. + =back To illustrate these controls, diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 8854f397..3350864f 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -3721,6 +3721,7 @@ sub generate_options { $add_option->( 'warn-mismatched-args', 'wma', '!' ); $add_option->( 'warn-mismatched-arg-types', 'wmat', '=s' ); $add_option->( 'warn-mismatched-arg-undercount-cutoff', 'wmauc', '=i' ); + $add_option->( 'warn-mismatched-arg-overcount-cutoff', 'wmaoc', '=i' ); $add_option->( 'warn-mismatched-arg-exclusion-list', 'wmaxl', '=s' ); $add_option->( 'add-interbracket-arrows', 'aia', '!' ); @@ -3872,7 +3873,8 @@ sub generate_options { maximum-unexpected-errors=0 memoize minimum-space-to-comment=4 - warn-mismatched-arg-undercount-cutoff=3 + warn-mismatched-arg-undercount-cutoff=4 + warn-mismatched-arg-overcount-cutoff=1 nobrace-left-and-indent nocuddled-else nodelete-old-whitespace @@ -4032,6 +4034,7 @@ sub generate_options { 'maximum-unexpected-errors' => [ 0, undef ], 'minimum-space-to-comment' => [ 0, undef ], 'warn-mismatched-arg-undercount-cutoff' => [ 0, undef ], + 'warn-mismatched-arg-overcount-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 2c79c59e..2108405f 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -14378,12 +14378,15 @@ sub cross_check_call_args { # initialize for dump mode my $ris_mismatched_call_type = { 'a' => 1, 'o' => 1, 'u' => 1, 'i' => 1 }; my $mismatched_arg_undercount_cutoff = 0; + my $mismatched_arg_overcount_cutoff = 0; my $ris_mismatched_call_excluded_name = {}; if ($warn_mode) { $ris_mismatched_call_type = \%warn_mismatched_arg_types; $mismatched_arg_undercount_cutoff = $rOpts->{'warn-mismatched-arg-undercount-cutoff'}; + $mismatched_arg_overcount_cutoff = + $rOpts->{'warn-mismatched-arg-overcount-cutoff'}; $ris_mismatched_call_excluded_name = \%is_warn_mismatched_arg_excluded_name; } @@ -14733,7 +14736,9 @@ sub cross_check_call_args { # issue 'o': overcount if ($num_over_count) { - if ( $ris_mismatched_call_type->{'o'} ) { + if ( $ris_mismatched_call_type->{'o'} + && $shift_count_max >= $mismatched_arg_overcount_cutoff ) + { my $lines_over_count = stringify_line_range($rover_count); my $total = $num_direct + $num_self; @@ -14765,7 +14770,7 @@ sub cross_check_call_args { # Skip the warning for small lists with undercount if ( $ris_mismatched_call_type->{'u'} - && $shift_count_min > $mismatched_arg_undercount_cutoff ) + && $shift_count_min >= $mismatched_arg_undercount_cutoff ) { my $lines_under_count = stringify_line_range($runder_count); my $total = $num_direct + $num_self; @@ -14800,8 +14805,9 @@ sub cross_check_call_args { my $hint = EMPTY_STRING; if ($number_of_undercount_warnings) { + my $wmauc_min = $max_shift_count_with_undercount + 1; $hint = < 20240202.04) --warn-mismatched-args ---warn-mismatched-arg-undercount-cutoff=4 +--warn-mismatched-arg-undercount-cutoff=5 # user-defined subs must have args in parens --want-call-parens='&'