]> git.donarmstrong.com Git - perltidy.git/commitdiff
switch control -wmat=s to -wma for simplicity
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 9 Apr 2024 01:16:44 +0000 (18:16 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 9 Apr 2024 01:16:44 +0000 (18:16 -0700)
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index 8abcdea91391ae0cfd4036cb19d8db72b778a132..f990a656a1c2138a8249ac35e1b0040f2b317797 100644 (file)
@@ -3,7 +3,7 @@
 ## 2024 02 02.04
 
     - Add options --dump-mismatched-args (or -dma) and
-      --warn-mismatched-arg-types=s (or -wmat=s).  These options look
+      --warn-mismatched-arg (or -wma).  These options look
       for and report instances where the number of args expected by a
       sub appear to differ from the number passed to the sub.  The -dump
       version writes the results for a single file to standard output
       The -warn version formats as normal but reports any issues as warnings in
       the error file:
 
-         perltidy -wmat=1 somefile.pl
+         perltidy -wma somefile.pl
 
-      It takes a string parameter which is 1 or '*' to activate all checks.
-      It may be customized with two additional parameters if necessary to
-      avoid needless warnings, --warn-mismatched-arg-exclusion-list=s and
-      --warn-mismatched-arg-undercount-cutoff=n. These are explained in the manual.
+      It may be customized with three additional parameters if necessary to
+      avoid needless warnings, --warn-mismatched-arg-types=s,
+      --warn-mismatched-arg-exclusion-list=s and
+      --warn-mismatched-arg-undercount-cutoff=n.
+      These are explained in the manual.
 
     - Add option --valign-wide-equals, or -vwe, for issue git #135.
       Setting this parameter causes the following assignment operators
index a08c51ff2c93ec0b5a8cb1fc4548a290910065a9..b486b7e5bebd1d3153e1c2b3fce4eadf7d93e873 100755 (executable)
@@ -6097,7 +6097,7 @@ so it is worth checking.
 
 =back
 
-B<Some Limitations:>
+B<Some Current Limitations:>
 
 =over 4
 
@@ -6105,28 +6105,42 @@ B<Some Limitations:>
 The only subs which these checks are made are those 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.
 
 =item *
-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.
+Subs which appear to have no args are not checked. This restriction is
+currently 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.
+Only calls which appear to be to subs defined within the file being
+processed are checked. The file may contain any number of packages.
 
 =item *
 Sub calls made without parentheses around the args are not checked.
 
 =item *
-Anonymous subs and lexical subs (introduced with 'my') are not currently
+Anonymous subs and lexical subs (introduced with C<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>
+Some of these restrictions may be removed in the future.
 
-The parameter B<--warn-mismatched-arg-types=s>, or B<-wmat=s>, can be used to
-produce a warning message when perltidy formats a file and certain of the above
-mismatchs is detected during formatting.  Both checks may be requested with
-B<-wmat='*'> or B<-wmat=1>.
+=item B<Use --warn-mismatched-args to produce a warning for function calls with
+args not matching sub declarations>.
 
-The default is not to do any of these checks, which can also be indicated with B<-wmat=0>.
+This is similar to the B<-dump> parameter described above
+except that any mismatches are reported in the error file and
+otherwise formatting continues normally.  Thus
+
+    perltidy -wma somefile.pl
+
+means format F<somefile.pl> and report any mismatched arg errors found.
+Several companion controls are available to avoid unwanted error messages:
+
+=over 4
+
+=item *
+B<--warn-mismatched-arg-types=s>, or B<-wmat=s>, can be used to
+select specific tests, either type B<a> (arrow test) or B<c> (mismatched counts). Both checks may be requested with B<-wmat='*'> or B<-wmat=1>. This is the default.
 
 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
 
@@ -6135,11 +6149,14 @@ To restrict the check to a specific warning type, set the string equal to the le
 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.
+=item *
+B<--warn-mismatched-arg-exclusion-list>, or B<-wmaxl=string>, can be given to
+skip the warning checks for a list of subroutine names, entered as a quoted
+string of space- or comma-separated names. All subs with those names will be
+skipped, regardless of package.
 
-Another control parameter B<--warn-mismatched-arg-undercount-cutoff=n>, or
+=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.  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
@@ -6147,18 +6164,21 @@ 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 -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.
+checking.  The minimum possible value of B<n> needed to avoid triggering an
+error for a program can be determined by running with B<-wmauc=0>, or by
+running with B<--dump-mismatched-args>. 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
+To illustrate these controls,
 
-   perltidy -wmat='*' -wmaxl='new' -wmauc=2 somefile.pl
+   perltidy -wma -wmat='c' -wmaxl='new old' -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.
+means format F<somefile.pl> as usual and check for mismatched counts but not
+arrows. Skip checking for any sub named C<new> or C<old>, and only warn of
+undercounts for subs expecting more than 2 args.
+
+=back
 
 =back
 
@@ -6471,21 +6491,21 @@ The following list shows all short parameter names which allow a prefix
  aws    b      baa    baao   bar    bbao   bbb    bbc    bbs    bl
  bli    boa    boc    bok    bol    bom    bos    bot    cblx   ce
  conv   cpb    cs     csc    cscb   cscw   dac    dbc    dbs    dcbl
- dcsc   ddf    dia    dior   dln    dmcp   dnl    dop    dp     dpro
- drc    dsc    dsm    dsn    dtc    dtt    duv    dwic   dwls   dwrs
- dws    eos    f      fpva   frm    fs     fso    gcs    hbc    hbcm
- hbco   hbh    hbhh   hbi    hbj    hbk    hbm    hbn    hbp    hbpd
- hbpu   hbq    hbs    hbsc   hbv    hbw    hent   hic    hicm   hico
- hih    hihh   hii    hij    hik    him    hin    hip    hipd   hipu
- hiq    his    hisc   hiv    hiw    hsc    html   ibc    icb    icp
- iob    ipc    isbc   iscl   kgb    kgbd   kgbi   kis    lal    log
- lop    lp     lsl    mem    nib    ohbr   okw    ola    olc    oll
- olq    opr    opt    osbc   osbr   otr    ple    pod    pvl    q
- sac    sbc    sbl    scbb   schb   scp    scsb   sct    se     sfp
- sfs    skp    sob    sobb   sohb   sop    sosb   sot    ssc    st
- sts    t      tac    tbc    toc    tp     tqw    trp    ts     tsc
- tso    vbc    vc     viu    vmll   vsc    vsn    w      wfc    wia
- wme    wn     x      xbt    xci    xlp    xs
+ dcsc   ddf    dia    dior   dln    dma    dmcp   dnl    dop    dp
+ dpro   drc    dsc    dsm    dsn    dtc    dtt    duv    dwic   dwls
+ dwrs   dws    eos    f      fpva   frm    fs     fso    gcs    hbc
+ hbcm   hbco   hbh    hbhh   hbi    hbj    hbk    hbm    hbn    hbp
+ hbpd   hbpu   hbq    hbs    hbsc   hbv    hbw    hent   hic    hicm
+ hico   hih    hihh   hii    hij    hik    him    hin    hip    hipd
+ hipu   hiq    his    hisc   hiv    hiw    hsc    html   ibc    icb
+ icp    iob    ipc    isbc   iscl   kgb    kgbd   kgbi   kis    lal
+ log    lop    lp     lsl    mem    nib    ohbr   okw    ola    olc
+ oll    olq    opr    opt    osbc   osbr   otr    ple    pod    pvl
+ q      sac    sbc    sbl    scbb   schb   scp    scsb   sct    se
+ sfp    sfs    skp    sob    sobb   sohb   sop    sosb   sot    ssc
+ st     sts    t      tac    tbc    toc    tp     tqw    trp    ts
+ tsc    tso    vbc    vc     viu    vmll   vsc    vsn    vwe    w
+ wfc    wia    wma    wme    wn     x      xbt    xci    xlp    xs
 
 Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be
 used.
index 1227bf9209124e9f44009ac94141d0685ef32872..45c036d821af1a3d15c465ff676bb61431280cb0 100644 (file)
@@ -3717,6 +3717,7 @@ sub generate_options {
     $add_option->( 'want-call-parens',             'wcp',  '=s' );
     $add_option->( 'nowant-call-parens',           'nwcp', '=s' );
 
+    $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-exclusion-list',    'wmaxl', '=s' );
index 1159e2a6491cc61adc1e37ebef2f1d9bc3177887..7be5f95f51be750cf1f8ebb7870100a905045d58 100644 (file)
@@ -389,7 +389,7 @@ my (
     %warn_variable_types,
     %is_warn_variable_excluded_name,
 
-    # INITIALIZER: sub initialize_warn_mismatched_arg_types
+    # INITIALIZER: sub initialize_warn_mismatched_args
     %warn_mismatched_arg_types,
     %is_warn_mismatched_arg_excluded_name,
 
@@ -1014,7 +1014,7 @@ sub new {
     $self->[_ris_asub_block_]          = {};
     $self->[_ris_sub_block_]           = {};
 
-    # Variables for --warn-mismatched-arg-types and
+    # Variables for --warn-mismatched-args and
     #               --dump-mismatched-args
     $self->[_rK_package_list_]               = [];
     $self->[_rsub_call_paren_info_by_seqno_] = {};
@@ -1472,7 +1472,7 @@ sub check_options {
 
     initialize_warn_variable_types();
 
-    initialize_warn_mismatched_arg_types();
+    initialize_warn_mismatched_args();
 
     make_bli_pattern();
 
@@ -1491,6 +1491,21 @@ sub check_options {
         Exit(0);
     }
 
+    # --indent-only skips the call to sub respace_tokens, which defines
+    # some essential data structures needed by some dump routines,
+    # or might be in the future. Since there is an immediate exit after a
+    # dump, we can turn off indent-only to get these structures for a -dump.
+    if ( $rOpts->{'indent-only'} ) {
+
+        if ( $rOpts->{'dump-mismatched-args'} ) {
+            $rOpts->{'indent-only'} = 0;
+        }
+
+        if ( $rOpts->{'dump-block-summary'} ) {
+            $rOpts->{'indent-only'} = 0;
+        }
+    }
+
     initialize_line_up_parentheses();
 
     check_tabs();
@@ -6609,7 +6624,7 @@ EOM
         && $self->[_logger_object_] );
 
     $self->warn_mismatched_args()
-      if ( $rOpts->{'warn-mismatched-arg-types'}
+      if ( $rOpts->{'warn-mismatched-args'}
         && $self->[_logger_object_] );
 
     if ( $rOpts->{'dump-mismatched-args'} ) {
@@ -14086,7 +14101,7 @@ sub cross_check_call_args {
     my ( $self, $warn_mode ) = @_;
 
     # Input parameter:
-    #  $warn_mode = true  for --warn-mismatched-arg-types
+    #  $warn_mode = true  for --warn-mismatched-args
     #  $warn_mode = false for --dump-mismatched-args
 
     # The current possible checks are indicated by these letters:
@@ -14412,23 +14427,15 @@ sub stringify_line_range {
     return $string;
 } ## end sub stringify_line_range
 
-sub initialize_warn_mismatched_arg_types {
+sub initialize_warn_mismatched_args {
 
     # Initialization for:
-    #    --dump-mismatched-args
-    #    --warn-mismatched-arg-types=s and
+    #    --warn-mismatched-args
+    #    --warn-mismatched-arg-types=s
     #    --warn-mismatched-arg-exclusion-list=s
     %warn_mismatched_arg_types            = ();
     %is_warn_mismatched_arg_excluded_name = ();
-
-    # The --dump-mismatched-args needs data structures which are not
-    # available with -io. Since it causes immediate exit without formatting,
-    # we can turn off --indent-only to allow it to work.
-    if ( $rOpts->{'dump-mismatched-args'} ) {
-        if ( $rOpts->{'indent-only'} ) {
-            $rOpts->{'indent-only'} = 0;
-        }
-    }
+    return unless $rOpts->{'warn-mismatched-args'};
 
     # Note: coding here is similar to sub initialize_warn_variable_types
 
@@ -14437,12 +14444,13 @@ sub initialize_warn_mismatched_arg_types {
     #-----------------------------------
     my $wmat_key    = 'warn-mismatched-arg-types';
     my $wmat_option = $rOpts->{$wmat_key};
-    return unless ($wmat_option);
+    $wmat_option = '1' unless defined($wmat_option);
 
     # The -indent-only option skips production of data structures needed by
     # the --warn-mismatched-args
     if ( $rOpts->{'indent-only'} ) {
-        Warn("Note: '--$wmat_key' is ignored if '--indent-only' is set\n");
+        my $wma_key = 'warn-mismatched-args';
+        Warn("Note: '--$wma_key' is ignored if '--indent-only' is set\n");
         return;
     }
 
@@ -14525,24 +14533,23 @@ sub initialize_warn_mismatched_arg_types {
         @is_warn_mismatched_arg_excluded_name{@xl} = (1) x scalar(@xl);
     }
     return;
-} ## end sub initialize_warn_mismatched_arg_types
+} ## end sub initialize_warn_mismatched_args
 
 sub warn_mismatched_args {
     my ($self) = @_;
 
-    # process a --warn-mismatched-arg-types command
+    # process a --warn-mismatched-args command
 
     # additional control parameters are:
-    # - mismatched-arg-exclusion-list
+    # - warn-mismatched-arg-types
+    # - warn-mismatched-arg-exclusion-list
     # - warn-mismatched-arg-undercount-cutoff
 
-    my $wma_key    = 'warn-mismatched-arg-types';
-    my $wma_option = $rOpts->{$wma_key};
-
     my $rwarnings = $self->cross_check_call_args(1);
     return unless ( $rwarnings && @{$rwarnings} );
 
-    my $output_string = "Begin scan for --$wma_key=$wma_option\n";
+    my $wma_key       = 'warn-mismatched-args';
+    my $output_string = "Begin scan for --$wma_key\n";
     $output_string .= <<EOM;
 Line:Mismatch:Name:#args:Min:Max: note
 EOM
@@ -14559,7 +14566,7 @@ EOM
         $output_string .=
 "$lno:$letter:$name:$shift_count:$min_arg_count:$max_arg_count: $note\n";
     }
-    $output_string .= "End scan for --$wma_key=$wma_option:\n";
+    $output_string .= "End scan for --$wma_key\n";
     warning($output_string);
 
     return;