fix some edge cases involving the -wn parameter
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 29 Jan 2021 15:58:30 +0000 (07:58 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 29 Jan 2021 15:58:30 +0000 (07:58 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 80b48cdaae92c47eb84838de8ce815e71f646a3d..ca5ff27e61d993b88627b3a8b231c7672d0b7b29 100644 (file)
@@ -6713,6 +6713,14 @@ sub weld_nested_containers {
             next unless ( defined($Kp) && $rLL->[$Kp]->[_TOKEN_] eq '@' );
         }
 
+        # RULE: do not weld to a square bracket without commas
+        if ( $inner_opening->[_TYPE_] eq '[' ) {
+            my $rtype_count = $self->[_rtype_count_by_seqno_]->{$inner_seqno};
+            next unless ($rtype_count);
+            my $comma_count = $rtype_count->{','};
+            next unless ($comma_count);
+        }
+
         # Set flag saying if this pair starts a new weld
         my $starting_new_weld = !( @welds && $outer_seqno == $welds[-1]->[0] );
 
@@ -6753,15 +6761,10 @@ sub weld_nested_containers {
             # An existing one-line weld is a line in which
             # (1) the containers are all on one line, and
             # (2) the line does not exceed the allowable length, and
-            # (3) there are no good line breaks (comma or semicolon).
             # This flag is used to avoid creating blinkers.
             if ( $iline_oo == $iline_oc && $excess_length_to_K->($Klast) <= 0 )
             {
-                my $rtype_count =
-                  $self->[_rtype_count_by_seqno_]->{$inner_seqno};
-                $is_one_line_weld = 1
-                  unless ( $rtype_count
-                    && ( $rtype_count->{','} || $rtype_count->{';'} ) );
+                $is_one_line_weld = 1;
             }
 
             # DO-NOT-WELD RULE 1:
@@ -6842,7 +6845,7 @@ sub weld_nested_containers {
 
         # DO-NOT-WELD RULE 3:
         # Do not weld if this makes our line too long
-        $do_not_weld ||= $excess_length_to_K->($Kinner_opening) > 0;
+        $do_not_weld ||= $excess_length_to_K->($Kinner_opening) >= 0;
 
         # DO-NOT-WELD RULE 4; implemented for git#10:
         # Do not weld an opening -ce brace if the next container is on a single
index 319d51095e4d33116696f999e07299892a95671a..74721122a6aade29457352988188c0f1e608c50d 100644 (file)
@@ -2,6 +2,49 @@
 
 =over 4
 
+=item B<fix additional edge blinker cases involving -wn>
+
+Some blinking cases produced in random testing were traced to welding in
+very short lines (length = 20 for example) in which a weld was made to
+a square bracket containing just a single parameter, so that it had no
+good internal breaking points. A rule was added to avoid welding to a
+square bracket not containing any commas. The following cases were fixed
+with the update: 
+
+b002 b003 b005 b006 b007 b009 b010 b014 b015 b017 b020 b111 b112 b113 b124 b126
+b128 b151 b153 b439 b606
+
+29 Jan 2021.
+
+=item B<fix additional edge blinker cases involving -wn>
+
+Random testing produced some blinking states which were traced to the
+precision of a line length test. In sub weld_nested_containers, the
+test
+
+    $do_not_weld ||= $excess_length_to_K->($Kinner_opening) > 0;
+
+was changed to allow a 1 character margin of error:
+
+    $do_not_weld ||= $excess_length_to_K->($Kinner_opening) >= 0;
+
+The following cases were fixed with this update:
+
+b025 b075 b091 b109 b110 b152 b154 b155 b162 b168 b176 b422 b423 b424 b425 b426
+b565
+
+29 Jan 2021.
+
+=item B<fix some edge blinker cases involving -wn>
+
+Random testing produced some blinking states which were eliminated by a
+simplification of the definition of a one_line_weld in sub
+weld_nested_containers.  The following cases were fixed with this update:
+
+b131 b134 b136 b205 b233 b238 b284 b350 b352 b358 b385 b487 b604 b605
+
+29 Jan 2021.
+
 =item B<fix some edge blinker cases involving -bbxi=n esp. with -boc>
 
 The following cases were fixed with this update: