]> git.donarmstrong.com Git - perltidy.git/commitdiff
Avoid conflict of -bbp=2 and -xci
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 31 Mar 2021 00:47:51 +0000 (17:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 31 Mar 2021 00:47:51 +0000 (17:47 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index b089659fd9d6db8e4d2de737231cb941210c36dc..e6b97ecfad55f39278efdcec65974e54df32af04 100644 (file)
@@ -366,6 +366,7 @@ BEGIN {
         _rhas_ternary_                     => $i++,
         _ris_excluded_lp_container_        => $i++,
         _rwant_reduced_ci_                 => $i++,
+        _rno_xci_by_seqno_                 => $i++,
         _ris_bli_container_                => $i++,
         _rparent_of_seqno_                 => $i++,
         _rchildren_of_seqno_               => $i++,
@@ -725,6 +726,7 @@ sub new {
     $self->[_rhas_ternary_]                     = {};
     $self->[_ris_excluded_lp_container_]        = {};
     $self->[_rwant_reduced_ci_]                 = {};
+    $self->[_rno_xci_by_seqno_]                 = {};
     $self->[_ris_bli_container_]                = {};
     $self->[_rparent_of_seqno_]                 = {};
     $self->[_rchildren_of_seqno_]               = {};
@@ -8172,6 +8174,7 @@ sub break_before_list_opening_containers {
     my $rlines                    = $self->[_rlines_];
     my $rtype_count_by_seqno      = $self->[_rtype_count_by_seqno_];
     my $rlec_count_by_seqno       = $self->[_rlec_count_by_seqno_];
+    my $rno_xci_by_seqno          = $self->[_rno_xci_by_seqno_];
 
     my $length_tol =
       max( 1, $rOpts_continuation_indentation, $rOpts_indent_columns );
@@ -8236,11 +8239,22 @@ sub break_before_list_opening_containers {
         #  - this list contains a broken list with line-ending comma, or
         #  - this list is contained in a broken list
         elsif ( $break_option == 2 ) {
+
             my $ok_to_break = $has_list_with_lec;
             if ( !$ok_to_break ) {
+
+                # Turn off -xci if -bbx=2 and this container has a sublist but
+                # not a broken sublist. This avoids creating blinkers.  The
+                # problem is that -xci can cause one-line lists to break open,
+                # and thereby creating formatting instability.
+                # This fixes cases b1033 b1036 b1037 b1038 b1042 b1043 b1044
+                # b1045 b1046 b1047 b1051 b1052 b1061.
+                if ($has_list) { $rno_xci_by_seqno->{$seqno} = 1 }
+
                 my $parent = $rparent_of_seqno->{$seqno};
                 $ok_to_break = $self->is_list_by_seqno($parent);
             }
+
             next unless ($ok_to_break);
         }
 
@@ -8427,6 +8441,7 @@ sub extended_ci {
     my $ris_seqno_controlling_ci = $self->[_ris_seqno_controlling_ci_];
     my $rseqno_controlling_my_ci = $self->[_rseqno_controlling_my_ci_];
     my $rlines                   = $self->[_rlines_];
+    my $rno_xci_by_seqno         = $self->[_rno_xci_by_seqno_];
 
     my %available_space;
 
@@ -8514,6 +8529,11 @@ sub extended_ci {
             next;
         }
 
+        # Skip if requested by -bbx to avoid blinkers
+        if ( $rno_xci_by_seqno->{$seqno} ) {
+            next;
+        }
+
         # We are looking for opening container tokens with ci
         next unless ( defined($K_opening) && $KK == $K_opening );
 
index 9fa3522b4861456da5d6032b0b79e5a813cf08f4..bdfaab35aa818daaf39231ab494e1f893aa0287c 100644 (file)
@@ -2,6 +2,19 @@
 
 =over 4
 
+=item B<Avoid conflict of -bbp=2 and -xci>
+
+Random testing produced a number of cases of unstable formatting when both -xci
+and -bbp=2 or similar flags were set.  The problem was that -xci can cause
+one-line blocks to break open, causing the -bbp=2 flag to continually switch
+formatting.  The problem is fixed by locally turning off -xci at containers
+which do not themselves contain broken containers.
+
+This fixes cases 
+b1033 b1036 b1037 b1038 b1042 b1043 b1044 b1045 b1046 b1047 b1051 b1052 b1061.
+
+30 Mar 2021.
+
 =item B<Fix rule for welding with barewords>
 
 Random testing produced a case which was not converging due to a rule
@@ -11,7 +24,7 @@ discovered and fixed.
 
 This fixes cases b1057 b1064.
 
-29 Mar 2021.
+29 Mar 2021, d677082.
 
 =item B<Fix conflict between -wba='||' and -opr>
 
@@ -34,7 +47,7 @@ Both the '||' and the '(' want to be at the end of a line according to the
 parameters.  The problem is resolved by giving priority to the '||'.  This
 fixes case b1060.
 
-29 Mar 2021
+29 Mar 2021, 6921a7d.
 
 =item B<Follow user requests better to break before operators>