]> git.donarmstrong.com Git - perltidy.git/commitdiff
Restrict references to old line breaks
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 8 Feb 2021 18:07:49 +0000 (10:07 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 8 Feb 2021 18:07:49 +0000 (10:07 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/andor6.def
t/snippets/expect/multiple_equals.def
t/snippets1.t
t/snippets12.t
t/snippets16.t

index 95d112827688779e0295ec9869e9916f32fb3f70..eb0eb50a55ee183d4b2c795778ca13b7060cbca4 100644 (file)
@@ -3210,8 +3210,8 @@ EOM
         my $list_str            = $left_bond_strength{'?'};
 
         my ( $block_type, $i_next, $i_next_nonblank, $next_nonblank_token,
-            $next_nonblank_type, $next_token, $next_type, $total_nesting_depth,
-        );
+            $next_nonblank_type, $next_token, $next_type,
+            $total_nesting_depth, );
 
         # main loop to compute bond strengths between each pair of tokens
         foreach my $i ( 0 .. $max_index_to_go ) {
@@ -3574,8 +3574,14 @@ EOM
                   : $next_nonblank_token
               : $next_nonblank_type;
 
-            # add any bias set by sub scan_list at old comma break points.
-            if ( $type eq ',' ) { $bond_str += $bond_strength_to_go[$i] }
+            if ( $type eq ',' ) {
+
+                # add any bias set by sub scan_list at old comma break points
+                $bond_str += $bond_strength_to_go[$i];
+
+                # Avoid breaking at a useless terminal comma
+                $bond_str += 0.001 if ( $next_nonblank_type eq '}' );
+            }
 
             # bias left token
             elsif ( defined( $bias{$left_key} ) ) {
@@ -13609,25 +13615,14 @@ sub set_continuation_breaks {
             $strength = $bond_strength_to_go[$i_test];
             if ( $type eq 'b' ) { $strength = $last_strength }
 
-            # use old breaks as a tie-breaker.  For example to
-            # prevent blinkers with -pbp in this code:
-
-##@keywords{
-##    qw/ARG OUTPUT PROTO CONSTRUCTOR RETURNS DESC PARAMS SEEALSO EXAMPLE/}
-##    = ();
-
-            # At the same time try to prevent a leading * in this code
-            # with the default formatting:
-            #
-##                return
-##                    factorial( $a + $b - 1 ) / factorial( $a - 1 ) / factorial( $b - 1 )
-##                  * ( $x**( $a - 1 ) )
-##                  * ( ( 1 - $x )**( $b - 1 ) );
-
-            # reduce strength a bit to break ties at an old breakpoint ...
+            # reduce strength a bit to break ties at an old comma breakpoint ...
             if (
+
                 $old_breakpoint_to_go[$i_test]
 
+                # Patch: limited to just commas to avoid blinking states
+                && $type eq ','
+
                 # which is a 'good' breakpoint, meaning ...
                 # we don't want to break before it
                 && !$want_break_before{$type}
@@ -20232,8 +20227,8 @@ sub set_vertical_tightness_flags {
                 my $valid_flag = 1;
                 my $spaces = ( $types_to_go[ $ibeg_next - 1 ] eq 'b' ) ? 1 : 0;
                 @{$rvertical_tightness_flags} =
-                  ( 2, $spaces, $type_sequence_to_go[$ibeg_next], $valid_flag,
-                  );
+                  ( 2, $spaces, $type_sequence_to_go[$ibeg_next],
+                    $valid_flag, );
             }
         }
     }
index 23153c523cccbe7d651acfe83da5febf2800ca9e..fe6c36205f1f9254a0f0a5ea01f8bef47dc3f0d8 100644 (file)
@@ -2,6 +2,53 @@
 
 =over 4
 
+=item B<Restrict references to old line breaks>
+
+A number of cases of blinking states were traced to code which biased
+the breaking of long lines to existing breaks.  This was fixed by restricting
+this coding to just use old comma line break points.
+
+The following cases were fixed with this update:
+
+b193 b194 b195 b197 b198 b199 b216 b217 b218 b219 b220 b221 b244 b245 b246 b247
+b249 b251 b252 b253 b254 b256 b257 b258 b259 b260 b261 b262 b263 b264 b265 b266
+b268 b269 b270 b271 b272 b274 b275 b278 b280 b281 b283 b285 b288 b291 b295 b296
+b297 b299 b302 b304 b305 b307 b310 b311 b312 b313 b314 b315 b316 b317 b318 b319
+b320 b321 b322 b323 b324 b325 b326 b327 b329 b330 b331 b332 b333 b334 b335 b336
+b337 b338 b339 b340 b341 b342 b343 b344 b345 b346 b347 b348 b349
+
+8 Feb 2021.
+
+=item B<Avoid breaking a line after an optional ending comma>
+
+Given the following input line with a length of 81, the default formatting
+will break at the last comma:
+
+    emit_subroutine_test( $test_file, $name, $capitalization_scheme, $failures );
+
+    # perltidy -sil=1 -iob
+    emit_subroutine_test( $test_file, $name, $capitalization_scheme,
+        $failures );
+
+But if the input line has a comma at the end of the list
+
+    emit_subroutine_test( $test_file, $name, $capitalization_scheme, $failures, );
+
+# Then the break is at the last comma
+    
+    # OLD: perltidy -sil=1 -iob
+    emit_subroutine_test( $test_file, $name, $capitalization_scheme, $failures,
+    );
+
+This update causes the break to be at the previous comma, so that the output
+is similar to the output without the needless ending comma:
+
+    # NEW: perltidy -sil=1 -iob
+    emit_subroutine_test( $test_file, $name, $capitalization_scheme,
+        $failures, );
+
+8 Feb 2021.
+
 =item B<Fix rare problem involving interaction of -olbn=n and -wn flags>
 
 Random testing revealed a rare alternating state which could occur when both
@@ -12,7 +59,7 @@ realistic parameter values.
 
 The following case was fixed with this update: b690.
 
-6 Feb 2021.
+6 Feb 2021, 3e96930.
 
 =item B<add rule to avoid welding at some barewords>
 
@@ -22,7 +69,7 @@ unknown, a weld will be avoided.
 
 The following cases were fixed with this update: b611 b626.
 
-6 Feb 2021, 5083ab9.
+6 Feb 2021, 6b1f44a
 
 =item B<further simplify -bbxi=n implementation>
 
index f5513afa8e831acac9a5a05e5ad37991aab2c37f..7f41552d3654b1bb70b1c7d4ee0f7a197dcd157e 100644 (file)
@@ -2,7 +2,8 @@
 sub is_miniwhile {    # check for one-line loop (`foo() while $y--')
     my $op = shift;
     return (
-              !null($op) and null( $op->sibling )
+             !null($op)
+          and null( $op->sibling )
           and $op->ppaddr eq "pp_null"
           and class($op) eq "UNOP"
           and (
index f10eefe3ba7977cf9f6aa1097b5d43fa1f4d1e3e..6e65950a1bf24555b3e8ee5825e977275f06852a 100644 (file)
@@ -4,5 +4,5 @@ $full_index = 1          if $opt_i;
 $query_all  = $opt_A     if $opt_A;
 
 # not aligning multiple '='s here
-$start = $end = $len = $ismut = $number = $allele_ori = $allele_mut =
-  $proof = $xxxxreg = $reg = $dist = '';
+$start = $end = $len = $ismut = $number = $allele_ori = $allele_mut = $proof =
+  $xxxxreg = $reg = $dist = '';
index 210e5ca0d7edb61de2d32e38d84d52576dfafcc6..546cee5384c1f10e4959aa07141741015b9f32e4 100644 (file)
@@ -450,7 +450,8 @@ ok(       ( $obj->name() eq $obj2->name() )
 sub is_miniwhile {    # check for one-line loop (`foo() while $y--')
     my $op = shift;
     return (
-              !null($op) and null( $op->sibling )
+             !null($op)
+          and null( $op->sibling )
           and $op->ppaddr eq "pp_null"
           and class($op) eq "UNOP"
           and (
index 89172f42c71c42799dcdc1ed0994be6e0266d2ae..d2b7edee4504b2c12e0fc60e86032ca85b27707b 100644 (file)
@@ -167,7 +167,7 @@ use_all_ok(
                 @{ $coords[0] }, @{ $coords[1] } ) ) );
         
             # OLD: do not weld to a one-line block because the function could
-           # get separated from its opening paren.
+            # get separated from its opening paren.
             # NEW: (30-jan-2021): keep one-line block together for stability
             $_[0]->code_handler
                  ( sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
index 5951bf608d8b67a369bcf5dd45cabddc0781ac66..7322a8b5cbb886c6efca7b7ca4662b208205eda9 100644 (file)
@@ -254,8 +254,8 @@ $full_index = 1          if $opt_i;
 $query_all  = $opt_A     if $opt_A;
 
 # not aligning multiple '='s here
-$start = $end = $len = $ismut = $number = $allele_ori = $allele_mut =
-  $proof = $xxxxreg = $reg = $dist = '';
+$start = $end = $len = $ismut = $number = $allele_ori = $allele_mut = $proof =
+  $xxxxreg = $reg = $dist = '';
 #6...........
         },