]> git.donarmstrong.com Git - perltidy.git/commitdiff
update docs, change name -wmacc to -wmauc
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 4 Apr 2024 23:47:13 +0000 (16:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 4 Apr 2024 23:47:13 +0000 (16:47 -0700)
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index 32ff59876a8263fde2e05bfb429432220421317d..b724ea3378480d4900da9b7c73bf41ddf2945037 100755 (executable)
@@ -6102,12 +6102,10 @@ B<Some Limitations:>
 =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.
@@ -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<Use --warn-mismatched-arg-types=s to produce a warning for function calls with args not matching sub declarations>
@@ -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<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>
index c104b79663c6d9828ef4e7cb89b9c872437b996e..31a1e1b4767b7e54bd1cb5930c8aa78ece4c94a2 100644 (file)
@@ -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 ],
index f243ae65d67edc823297126699ab167d5fd5586d..49b4e27dd588479feafdbdce1771d80103c32f30 100644 (file)
@@ -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};