From 9f8fb732887024f4b725af7c6fa43d29ca004b97 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 30 Mar 2021 17:47:51 -0700 Subject: [PATCH] Avoid conflict of -bbp=2 and -xci --- lib/Perl/Tidy/Formatter.pm | 20 ++++++++++++++++++++ local-docs/BugLog.pod | 17 +++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index b089659f..e6b97ecf 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 ); diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 9fa3522b..bdfaab35 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,19 @@ =over 4 +=item B + +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 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 @@ -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 -- 2.39.5