From: Steve Hancock Date: Sun, 2 May 2021 03:13:38 +0000 (-0700) Subject: Avoid instability of combination -bbx=2 -lp and -xci X-Git-Tag: 20210402.01~59 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4cb81ba35a4a135c3de233f19763cf042be54c5c;p=perltidy.git Avoid instability of combination -bbx=2 -lp and -xci --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 02947bf0..3410b651 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -8476,19 +8476,19 @@ sub break_before_list_opening_containers { ################################################################# my $KK = $K_opening_container->{$seqno}; + next if ( $rLL->[$KK]->[_BLOCK_TYPE_] ); - my $is_list = $self->is_list_by_seqno($seqno); - my $has_list = $rhas_list->{$seqno}; - my $has_broken_list = $rhas_broken_list->{$seqno}; - my $has_list_with_lec = $rhas_broken_list_with_lec->{$seqno}; - - # This must be a list (this will exclude all code blocks) - # or contain a list. + # This must be a list or contain a list. # Note1: switched from 'has_broken_list' to 'has_list' to fix b1024. # Note2: 'has_list' holds the depth to the sub-list. We will require # a depth of just 1 + my $is_list = $self->is_list_by_seqno($seqno); + my $has_list = $rhas_list->{$seqno}; next unless ( $is_list || $has_list && $has_list == 1 ); + my $has_broken_list = $rhas_broken_list->{$seqno}; + my $has_list_with_lec = $rhas_broken_list_with_lec->{$seqno}; + # Only for types of container tokens with a non-default break option my $token = $rLL->[$KK]->[_TOKEN_]; my $break_option = $break_before_container_types{$token}; @@ -8520,12 +8520,12 @@ sub break_before_list_opening_containers { next unless ( $KK == $Kfirst ); } - # -bbx=2 = only if complex list, meaning: - # - this list contains a broken list with line-ending comma, or - # - this list is contained in a broken list + # -bbx=2 => apply this style only for a 'complex' list elsif ( $break_option == 2 ) { + # break if this list contains a broken list with line-ending comma 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 @@ -8537,10 +8537,21 @@ sub break_before_list_opening_containers { if ($has_list) { $rno_xci_by_seqno->{$seqno} = 1 } my $parent = $rparent_of_seqno->{$seqno}; - $ok_to_break = $self->is_list_by_seqno($parent); + $ok_to_break ||= $self->is_list_by_seqno($parent); + } + + # Patch to fix b1099 for -lp + # ok in -lp mode if this is a list which contains a list + if ( !$ok_to_break && $rOpts_line_up_parentheses ) { + $ok_to_break ||= $is_list && $has_list; } next unless ($ok_to_break); + + # Patch: turn off -xci if -bbx=2 and -lp + # This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122 + $rno_xci_by_seqno->{$seqno} = 1 if ($rOpts_line_up_parentheses); + } # -bbx=3 = always break @@ -15490,6 +15501,8 @@ sub set_continuation_breaks { my $rOpts_break_at_old_ternary_breakpoints = $rOpts->{'break-at-old-ternary-breakpoints'}; + my $rLL = $self->[_rLL_]; + my $ris_list_by_seqno = $self->[_ris_list_by_seqno_]; my $ris_broken_container = $self->[_ris_broken_container_]; $starting_depth = $nesting_depth_to_go[0]; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 26bc83ca..377f1ba7 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,16 @@ =over 4 +=item B + +Random testing produced several cases in which the flags -bbx=2 -lp and -xci +were causing formatting instability. The fix is to locally turn off -xci when +-lp and -bbx=2 are in effect. This is an extension of commit 2b05051. + +This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122 b1099 + +1 May 2021. + =item B Logic was added to turn off -cab=3 in complex structures. Otherwise, @@ -32,7 +42,7 @@ formatting of the following snippet was unstable: This update fixes cases b1096 b1113. -29 Apr 2021. +29 Apr 2021, 32a1830. =item B @@ -58,7 +68,7 @@ long). For example this is ok But if a list is more than one level deep then the default indentation is used. -28 Apr 2021. +28 Apr 2021, 49977b8. =item B @@ -72,7 +82,7 @@ Other updates are: Remove unused indentation table. Correct maximum_line_length table for -vmll when -wc is also set. Also fix whitespace rule for '$ =' within a signature to fix case b1123. -26 Apr 2021. +26 Apr 2021, d014c2a. =item B