]> git.donarmstrong.com Git - perltidy.git/commitdiff
add --warn-mismatched-arg-overcount-cutoff=n
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 27 Apr 2024 00:31:31 +0000 (17:31 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 27 Apr 2024 00:31:31 +0000 (17:31 -0700)
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
perltidyrc

index fd6f0d18c403e616e9035fb7df9809085dd3b4fd..ab34e36723d6bddbc97d0fa773ba430d3dcd2edc 100755 (executable)
@@ -6127,10 +6127,6 @@ B<Notes and Limitations:>
 
 =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<shift>
@@ -6147,6 +6143,10 @@ Anonymous subs and lexical subs (introduced with C<my>) 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<Use --warn-mismatched-args to produce a warning for function calls with
@@ -6180,18 +6180,24 @@ skipped, regardless of package.
 
 =item *
 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.
+avoid B<undercount> warnings when the expected number of args is less than B<n>.
 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=3>. This has been found to allow most programs to
+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> 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<n> required to avoid reporting them.
 
+=item *
+B<--warn-mismatched-arg-overcount-cutoff=n>, or B<-wmaoc=n>, can be used to
+avoid B<overcount> warnings when the expected number of args is less than B<n>.
+The default value is B<n=1>. This avoids warning messages for subroutines
+which are dummy placeholders for future development.
+
 =back
 
 To illustrate these controls,
index 8854f3971c318bc7358c17191b3e96fcc739d3ac..3350864f340e3b16e592613d4c63750be4e8d4d2 100644 (file)
@@ -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 ],
index 2c79c59e73a302b63cefba95abe0b0e2acb7c785..2108405f98853b420ef0b276ade70db0f416cbc4 100644 (file)
@@ -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 = <<EOM;
-Note: use -wmauc=$max_shift_count_with_undercount or greater to prevent undercount warnings in this file
+Note: use -wmauc=$wmauc_min or greater to prevent undercount warnings in this file
 EOM
     }
     return ( \@warnings, $hint );
index 2ae4e2f3ec19b93971085bc7c6b7c6c59e5f435c..b3bb38d0cb6a1fe71f5848af7b5b193c53ac96ab 100644 (file)
@@ -18,7 +18,7 @@
 # warn if call arg counts differ from sub definitions
 # (requires version > 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='&'