]> git.donarmstrong.com Git - perltidy.git/commitdiff
Minor adjustments to improve formatting stability
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 29 Jun 2021 13:58:57 +0000 (06:58 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 29 Jun 2021 13:58:57 +0000 (06:58 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index f3c38e83a9b2d4c848f80c7602caf8dc499aa420..3dbc3e2d7433a15acb1eaf08d0cc61d4ab14490f 100644 (file)
@@ -15515,7 +15515,11 @@ sub set_continuation_breaks {
         @has_broken_sublist = ();
         @want_comma_break   = ();
 
-        # Define a tolerance to use a tolerance when checking if closed
+        ####################################################
+        # Set tolerances to prevent formatting instabilities
+        ####################################################
+
+        # Define tolerances to use when checking if closed
         # containers will fit on one line.  This is necessary to avoid
         # formatting instability. The basic tolerance is based on the
         # following:
@@ -15528,33 +15532,42 @@ sub set_continuation_breaks {
         $length_tol =
           1 + max( 0, $rOpts_continuation_indentation - $rOpts_indent_columns );
 
-        # In addition, use a few characters of extra tolerance for broken lines
-        # when -lp is used to help prevent instability. This is currently only
-        # necessary for -lp which has a more variable indentation.  At least 3
-        # characters have been found to be required.
-        # Fixes cases b1059 b1063 b1117.
+        # In addition, it may be necessary to use a few extra tolerance spaces
+        # when -lp is used and/or when -xci is used.  The history of this
+        # so far is as follows:
+
+        # FIX1: At least 3 characters were been found to be required for -lp
+        # to fixes cases b1059 b1063 b1117.
 
-        # Testing shows that we need a total of 3 extra spaces when -lp is set
-        # for non-lists, and at least 2 spaces when -lp and -xci are set.
-        # The following formulation is a minimal set of values which works.
+        # FIX2: Further testing showed that we need a total of 3 extra spaces
+        # when -lp is set for non-lists, and at least 2 spaces when -lp and
+        # -xci are set.
         # Fixes cases b1063 b1103 b1134 b1135 b1136 b1138 b1140 b1143 b1144
         # b1145 b1146 b1147 b1148 b1151 b1152 b1153 b1154 b1156 b1157 b1164
         # b1165
+
+        # FIX3: To fix cases b1169 b1170 b1171, an update was made in sub
+        # 'find_token_starting_list' to go back before an initial blank space.
+        # This fixed these three cases, and allowed the tolerances to be
+        # reduced to continue to fix all other known cases of instability.
+        # This gives the current tolerance formulation (note that
+        # variable $length_tol_boost is always 0 now):
+
         $length_tol_boost = 0;
         if ($rOpts_line_up_parentheses) {
 
             if ( $rOpts->{'extended-continuation-indentation'} ) {
                 $length_tol += 2;
-                $length_tol_boost = 1;
+                $length_tol_boost = 0;    # was 1 for FIX2, 0 for FIX3
             }
             else {
-                $length_tol_boost = 3;
+                $length_tol_boost = 0;    # was 3 for FIX2, 0 for FIX3
             }
         }
 
         # The -xci option alone also needs a slightly larger tol for non-lists
         elsif ( $rOpts->{'extended-continuation-indentation'} ) {
-            $length_tol_boost = 1;
+            $length_tol_boost = 0;        # was 1 for FIX2, 0 for FIX3
         }
         return;
     }
@@ -16865,8 +16878,12 @@ sub find_token_starting_list {
     elsif ( $tokens_to_go[$i_opening_paren] eq '(' ) {
         $i_opening_minus = $im1;
 
-        # walk back to improve length estimate
-        for ( my $j = $im1 ; $j >= 0 ; $j-- ) {
+        # Walk back to improve length estimate...
+        # FIX for cases b1169 b1170 b1171: start walking back
+        # at the previous nonblank. This makes the result insensitive
+        # to the flag --space-function-paren, and similar.
+        # previous loop: for ( my $j = $im1 ; $j >= 0 ; $j-- ) {
+        for ( my $j = $iprev_nb ; $j >= 0 ; $j-- ) {
             last if ( $types_to_go[$j] =~ /^[\(\[\{L\}\]\)Rb,]$/ );
             $i_opening_minus = $j;
         }
@@ -19006,7 +19023,8 @@ sub send_lines_to_vertical_aligner {
             my $nt  = @{$rtokens};
             my $nf  = @{$rfields};
             my $msg = <<EOM;
-"Program bug in Perl::Tidy::Formatter - number of tokens = $nt should be one less than number of fields: $nf)\n"
+Program bug in Perl::Tidy::Formatter, probably in sub 'make_alignment_patterns':
+The number of tokens = $nt should be one less than number of fields: $nf
 EOM
             Fault($msg);
         }
index 803f1354b6125a798dcc47290b9d16287ef226c5..8f1fc67b23f69fa758377d530d187c689447e0a6 100644 (file)
@@ -2,6 +2,15 @@
 
 =over 4
 
+=item B<Minor adjustments to improve formatting stability>
+
+Testing with random input parameters produced several new cases of formatting
+instability involving unusual parameter combinations.  This update fixes these
+cases, b1169 b1170 b1171, and all previously discovered cases remain
+stable with the update.
+
+28 Jun 2021.
+
 =item B<Remove limit on the value of -ci=n when -xci is set>
 
 This update undoes the update c16c5ee of 20 Feb 2021, in which the value