From 33f1f2bb441ee7dfa7c5c7fa709c553c9eace387 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 29 Jan 2021 07:58:30 -0800 Subject: [PATCH] fix some edge cases involving the -wn parameter --- lib/Perl/Tidy/Formatter.pm | 17 ++++++++------- local-docs/BugLog.pod | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 80b48cda..ca5ff27e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 319d5109..74721122 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,49 @@ =over 4 +=item B + +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 + +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 + +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 The following cases were fixed with this update: -- 2.39.5