From 344519e66aac2ac821b799d58c6586875f87348a Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 20 Apr 2021 17:30:44 -0700 Subject: [PATCH] Adjust line break rules for uncontained commas --- lib/Perl/Tidy/Formatter.pm | 34 +++++++++++++++++++++------------- local-docs/BugLog.pod | 10 +++++++++- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 3b4fc805..118031c9 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7440,7 +7440,8 @@ EOM my $level_diff = $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_]; - if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) { + if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) + { $is_one_line_weld = 1; } } @@ -15313,21 +15314,28 @@ sub set_continuation_breaks { # Changed rule from multiple old commas to just one here: if ( $ibreak >= 0 && $obp_count == 1 && $old_comma_break_count > 0 ) { - # Do not to break before an opening token because - # it can lead to "blinkers". my $ibreakm = $ibreak; $ibreakm-- if ( $types_to_go[$ibreakm] eq 'b' ); + if ( $ibreakm >= 0 ) { - # In order to avoid blinkers we have to be fairly restrictive. - # This has been updated to avoid breaking at any sequenced item, - # so now ternary operators are included. - # (see case b931, which is similar to the above print example) - ##This works too but is a little more restrictive: - ##if ( $ibreakm >= 0 && !$type_sequence_to_go[$ibreakm] ) { - if ( $ibreakm >= 0 - && $types_to_go[$ibreakm] !~ /^[\(\{\[L\?\:]$/ ) - { - $self->set_forced_breakpoint($ibreak); + # In order to avoid blinkers we have to be fairly + # restrictive: + + # Rule 1: Do not to break before an opening token + # Rule 2: avoid breaking at ternary operators + # (see b931, which is similar to the above print example) + # Rule 3: Do not break at chain operators to fix case b1119 + # - The previous test was '$typem !~ /^[\(\{\[L\?\:]$/' + + # These rules can be made even more restrictive in the + # future if necessary. + + my $typem = $types_to_go[$ibreakm]; + if ( !$is_chain_operator{$typem} + && !$is_opening_type{$typem} ) + { + $self->set_forced_breakpoint($ibreak); + } } } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index f631a036..73f69bbc 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,14 @@ =over 4 +=item B + +Random testing produced case c1119 which was unstable due to the formatting +rules for breaking lines at commas which occur outside of containers. The +rules were modified to fix the problem. + +20 Apr 2021. + =item B Random testing produced case c001 in which the following snipppet @@ -38,7 +46,7 @@ This is a situation where perltidy must ignore a user spacing and line break request. This should have been done but in this case a flag to prevent this was not being propagated to later stages of formatting. This has been fixed. -20 Apr 2021. +20 Apr 2021, 4fbc69a. =item B -- 2.39.5