]> git.donarmstrong.com Git - perltidy.git/commitdiff
minor code cleanups and update docs
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 2 May 2024 23:41:34 +0000 (16:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 2 May 2024 23:41:34 +0000 (16:41 -0700)
CHANGES.md
bin/perltidy
lib/Perl/Tidy/Formatter.pm

index ee947a9ae4a99f68b3dcb9dc80c9ab183a69adf0..ce6d0200c1ff6c6d1dd43ec8b6b0491cd99df6ad 100644 (file)
@@ -2,6 +2,56 @@
 
 ## 2024 02 02.07
 
+    - The option --valign-signed-numbers, or -vsn is now the default. It
+      was introduced in the previous release has been found to significantly
+      improve the overall appearance of columns of signed and unsigned
+      numbers.  It will change formatting slightly in scripts with columns
+      of vertically aligned numbers, and can be deactivated with -nvsn.
+
+    - Previously, a line break was made before a short concatenated terminal
+      quoted string, such as "\n", if the previous line had a greater
+      starting indentation. The break is now placed after the short quote.
+      This keeps code a little more compact. For example:
+
+    # old rule: break before "\n" here because '$name' has more indentation:
+    my $html = $this->SUPER::genObject( $query, $bindNode, $field . ":$var",
+        $name, "remove", "UNCHECKED" )
+      . "\n";
+
+    # new rule: break after a short terminal quote like "\n" for compactness;
+    my $html = $this->SUPER::genObject( $query, $bindNode, $field . ":$var",
+        $name, "remove", "UNCHECKED" ) . "\n";
+
+    - The option --delete-repeated-commas is now the default.
+
+      It makes the following checks and changes:
+      - Repeated commas like ',,' are removed with a warning
+      - Repeated fat commas like '=> =>' are removed with a warning
+      - The combination '=>,' produces a warning but is not changed
+      These warnings are only output if --warning-output, or -w, is set.
+
+      Use --nodelete-repeated-commas, or -ndrc, to retain repeated commas.
+
+    - The operator ``**=`` now has spaces on both sides by default. Previously,
+      there was no space on the left.  This change makes its spacing the same
+      as all other assignment operators. The previous behavior can be obtained
+      with the parameter setting -nwls='**='.
+
+    - The option --file-size-order, or -fso is now the default. When
+      perltidy is given a list of multiple filenames to process, they
+      are sorted by size and processed in order of increasing size.
+      This can significantly reduce memory usage by Perl.  This
+      option has always been used in testing, where typically several
+      jobs each operating on thousands of filenames are running at the
+      same time and competing for system resources.  If this option
+      is not wanted for some reason, it can be deactivated with -nfso.
+
+    - In the option --dump-block-summary, the number of sub arguments indicated
+      for each sub now includes any leading object variable passed with
+      an arrow-operator call.  Previously the count would have been decreased
+      by one in this case. This change is needed for compatibility with future
+      updates.
+
     - Fix issue git #138 involving -xlp (--extended-line-up-parentheses).
       When multiple-line quotes and regexes have long secondary lines, these
       line lengths could influencing some spacing and indentation, but they
 
          perltidy -wma somefile.pl
 
-      The -warn version may be customized with three additional parameters if
-      necessary to avoid needless warnings:
+      The -warn version may be customized with the following additional parameters
+      if necessary to avoid needless warnings:
 
       --warn-mismatched-arg-types=s (or -wmat=s),
       --warn-mismatched-arg-exclusion-list=s (or -wmaxl=s), and
       --warn-mismatched-arg-undercount-cutoff=n (or -wmauc=n).
+      --warn-mismatched-arg-overcount-cutoff=n (or -wmaoc=n).
 
       These are explained in the manual.
 
       This option currently is off by default to avoid changing existing
       formatting.
 
-    - Previously, a line break was made before a short concatenated terminal
-      quoted string, such as "\n", if the previous line had a greater
-      starting indentation. The break is now placed after the short quote.
-      This keeps code a little more compact. For example:
-
-    # old rule: break before "\n" here because '$name' has more indentation:
-    my $html = $this->SUPER::genObject( $query, $bindNode, $field . ":$var",
-        $name, "remove", "UNCHECKED" )
-      . "\n";
-
-    # new rule: break after a short terminal quote like "\n" for compactness;
-    my $html = $this->SUPER::genObject( $query, $bindNode, $field . ":$var",
-        $name, "remove", "UNCHECKED" ) . "\n";
-
-    - In the option --dump-block-summary, the number of sub arguments indicated
-      for each sub now includes any leading object variable passed with
-      an arrow-operator call.  Previously the count would have been decreased
-      by one in this case. This change is needed for compatibility with future
-      updates.
-
-    - The operator ``**=`` now has spaces on both sides by default. Previously,
-      there was no space on the left.  This change makes its spacing the same
-      as all other assignment operators. The previous behavior can be obtained
-      with the parameter setting -nwls='**='.
-
-    - The option --file-size-order, or -fso is now the default. When
-      perltidy is given a list of multiple filenames to process, they
-      are sorted by size and processed in order of increasing size.
-      This can significantly reduce memory usage by Perl.  This
-      option has always been used in testing, where typically several
-      jobs each operating on thousands of filenames are running at the
-      same time and competing for system resources.  If this option
-      is not wanted for some reason, it can be deactivated with -nfso.
-
-    - The option --valign-signed-numbers, or -vsn is now the default. It
-      was introduced in the previous release has been found to significantly
-      improve the overall appearance of columns of signed and unsigned
-      numbers.  It will change formatting slightly in scripts with columns
-      of vertically aligned numbers, and can be deactivated with -nvsn.
-
-    - The option --delete-repeated-commas is now the default.
-
-      It makes the following checks and changes:
-      - Repeated commas like ',,' are removed with a warning
-      - Repeated fat commas like '=> =>' are removed with a warning
-      - The combination '=>,' produces a warning but is not changed
-      These warnings are only output if --warning-output, or -w, is set.
-
-      Use --nodelete-repeated-commas, or -ndrc, to retain repeated commas.
-
     - Added control --delete-interbracket-arrows, or -dia, to delete optional
       hash ref and array ref arrows between brackets as in the following
       expression (see git #131)
index aa190991678ce278c8fb7b129921363d7cd44184..7615362ef250d423fe4daffa0e204ede028eb39f 100755 (executable)
@@ -5748,7 +5748,24 @@ perltidy development.
 
 Perltidy reports any obvious issues that are found during formatting, such as
 unbalanced braces. But several parameters are available for making certain
-additional checks for issues which might be of interest to a programmer.
+additional checks for issues which might be of interest to a programmer.  These
+parameters fall into two categories as indicated by their prefix, B<--dump-> or
+B<--warn->:
+
+=over 4
+
+=item *
+The B<--dump-> parameters read a file, write information to the standard output,
+and then exit without doing any formatting.
+
+=item *
+The B<--warn-> parameters, on the other hand, cause perltidy to function
+normally but issue warnings to the error output when certain conditions are
+encountered.
+
+=back
+
+Some of these have associated control parameters.
 
 =over 4
 
@@ -6078,7 +6095,7 @@ C<open>.
 
 The parameter B<--dump-mismatched-args>, or B<-dma>, causes perltidy to
 examine the definitions of subroutines in a file, and calls to those subs,
-and report any apparent differences.  Like all B<--dump> commands, it
+and report certain differences.  Like all B<--dump> commands, it
 writes its report to standard output and exits immediately.  For example
 
     perltidy -dma somefile.pl >results.txt
@@ -6143,10 +6160,6 @@ 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
@@ -6196,7 +6209,7 @@ indicates the value of B<n> required to avoid reporting them.
 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.
+which are dummy placeholders for possible expansion.
 
 =back
 
index f36779f67debd68f4c32f11a31dbf56e1e4d483a..841c2a0c4bd14f8c1201d34d51939598aca93762 100644 (file)
@@ -1144,7 +1144,7 @@ sub new {
     if (DEVEL_MODE) {
         my @non_existant;
         foreach ( 0 .. _LAST_SELF_INDEX_ ) {
-            if ( !exists( $self->[$_] ) ) {
+            if ( !exists $self->[$_] ) {
                 push @non_existant, $_;
             }
         }
@@ -1443,7 +1443,7 @@ sub split_words {
     return unless $str;
     $str =~ s/\s+$//;
     $str =~ s/^\s+//;
-    return split( /\s+/, $str );
+    return split /\s+/, $str;
 } ## end sub split_words
 
 ###########################################
@@ -1986,7 +1986,7 @@ sub initialize_space_after_keyword {
     if ( my @q = split_words( $rOpts->{'nospace-after-keyword'} ) ) {
 
         # -nsak='*' selects all the above keywords
-        if ( @q == 1 && $q[0] eq '*' ) { @q = keys(%space_after_keyword) }
+        if ( @q == 1 && $q[0] eq '*' ) { @q = keys %space_after_keyword }
         @space_after_keyword{@q} = (0) x scalar(@q);
     }
 
@@ -9741,6 +9741,7 @@ sub dump_mixed_call_parens {
 
     my $output_string = <<EOM;
 counts with and without call parens made by --dump-mixed-call-parens
+use -wcp=s and/or nwcp=s to find line numbers, where s is a string of words
 types are 'k'=builtin keyword 'U'=user sub  'w'=other word
 type:word:+count:-count
 EOM
@@ -10916,10 +10917,8 @@ sub respace_tokens_inner_loop {
                       )
                     {
                         $rsub_call_paren_info_by_seqno->{$type_sequence} = {
-                            token_mm => $last_last_nonblank_code_token,
-                            type_mm  => $last_last_nonblank_code_type,
-                            token_m  => $last_nonblank_code_token,
-                            type_m   => $last_nonblank_code_type,
+                            type_mm => $last_last_nonblank_code_type,
+                            token_m => $last_nonblank_code_token,
                         };
                     }
                 }
@@ -13657,7 +13656,7 @@ sub count_prototype_args {
         $count_min = undef if ( !$saw_semicolon );
         return;
     };
-    while ( my $ch = shift(@chars) ) {
+    while ( my $ch = shift @chars ) {
         if    ( !defined($ch) )                 { $saw_array->(); last }
         elsif ( $ch eq '(' )                    { last if ($count_min) }
         elsif ( $ch eq ')' )                    { last }
@@ -13889,7 +13888,6 @@ EOM
             elsif ( $token eq '$_' ) {
 
                 # Found $_: currently the search ends at '$_['
-                # TODO: eventually this can be handled
                 my $Kn = $self->K_next_code($KK);
                 if ( $Kn && $rLL->[$Kn]->[_TOKEN_] eq '[' ) {
                     return;
@@ -14296,9 +14294,6 @@ sub update_sub_call_paren_info {
         my $item    = $rsub_call_paren_info_by_seqno->{$seqno};
         my $name    = $item->{token_m};
         my $type_mm = $item->{type_mm};
-        ## These values are available but currently unused: [TODO: maybe remove]
-        ## my $type_m   = $item->{type_m};
-        ## my $token_mm = $item->{token_mm};
 
         # find function and package
         my $is_ampersand_call;
@@ -14309,6 +14304,18 @@ sub update_sub_call_paren_info {
             $name              = substr( $name, 1 );
         }
 
+        my $call_type   = $is_ampersand_call ? '&' : EMPTY_STRING;
+        my $caller_name = EMPTY_STRING;
+        if ( $type_mm eq '->' ) {
+            $call_type = '->';
+            my $K_m   = $self->K_previous_code($Ko);
+            my $K_mm  = $self->K_previous_code($K_m);
+            my $K_mmm = $self->K_previous_code($K_mm);
+            if ( defined($K_mmm) && $rLL->[$K_mmm]->[_TYPE_] eq 'i' ) {
+                $caller_name = $rLL->[$K_mmm]->[_TOKEN_];
+            }
+        }
+
         # look for explicit package on name
         my $package = $current_package;
         if ( ( index( $name, ':' ) >= 0 || index( $name, "'" ) >= 0 )
@@ -14363,18 +14370,6 @@ sub update_sub_call_paren_info {
             $arg_count = $item->{shift_count_min};
         }
 
-        my $call_type   = $is_ampersand_call ? '&' : EMPTY_STRING;
-        my $caller_name = EMPTY_STRING;
-        if ( $type_mm eq '->' ) {
-            $call_type = '->';
-            my $K_m   = $self->K_previous_code($Ko);
-            my $K_mm  = $self->K_previous_code($K_m);
-            my $K_mmm = $self->K_previous_code($K_mm);
-            if ( defined($K_mmm) && $rLL->[$K_mmm]->[_TYPE_] eq 'i' ) {
-                $caller_name = $rLL->[$K_mmm]->[_TOKEN_];
-            }
-        }
-
         # update the hash of info for this item
         my $line_number = $rLL->[$Ko]->[_LINE_INDEX_] + 1;
         $item->{arg_count}   = $arg_count;
@@ -26024,7 +26019,7 @@ sub correct_lp_indentation_pass_1 {
     return unless (@ilist);
 
     my $max_line = @{$ri_first} - 1;
-    my $inext    = shift(@ilist);
+    my $inext    = shift @ilist;
 
     # loop over lines, checking length of each with a one-line block
     my ( $ibeg, $iend );