From d679b4871aafa69eef8d120a99544e8c509ae1f1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 17 Apr 2021 20:45:30 -0700 Subject: [PATCH] Avoid welding at sort/map/grep paren calls --- lib/Perl/Tidy/Formatter.pm | 17 +++++++++++++++-- local-docs/BugLog.pod | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6ef9eeca..38aad918 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3841,7 +3841,7 @@ EOM # Sixth Approximation. Welds. #--------------------------------------------------------------- - # Do not allow a break within welds, + # Do not allow a break within welds if ( $seqno && $total_weld_count ) { if ( $self->weld_len_right( $seqno, $type ) ) { $strength = NO_BREAK; @@ -6940,6 +6940,7 @@ sub find_nested_pairs { # ^--K_o_o ^--K_i_o # @array) ) my $Kn_first = $K_outer_opening; + my $Kn_last_nonblank; for ( my $Kn = $K_outer_opening + 1 ; $Kn <= $K_inner_opening ; @@ -6949,6 +6950,7 @@ sub find_nested_pairs { next if ( $rLL->[$Kn]->[_TYPE_] eq 'b' ); if ( !$nonblank_count ) { $Kn_first = $Kn } if ( $Kn eq $K_inner_opening ) { $nonblank_count++; last; } + $Kn_last_nonblank = $Kn; # skip chain of identifier tokens my $last_type = $type; @@ -6961,6 +6963,18 @@ sub find_nested_pairs { last if ( $nonblank_count > 2 ); } + # Patch for b1104: do not weld to a paren preceded by sort/map/grep + # because the special line break rules may cause a blinking state + if ( defined($Kn_last_nonblank) + && $rLL->[$K_inner_opening]->[_TOKEN_] eq '(' + && $rLL->[$Kn_last_nonblank]->[_TYPE_] eq 'k' ) + { + my $token = $rLL->[$Kn_last_nonblank]->[_TOKEN_]; + + # Turn off welding at sort/map/grep ( + if ( $is_sort_map_grep{$token} ) { $nonblank_count = 10 } + } + if ( # adjacent opening containers, like: do {{ @@ -22116,4 +22130,3 @@ sub wrapup { } ## end package Perl::Tidy::Formatter 1; - diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index e69cf02c..e0dc76b2 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,17 @@ =over 4 +=item B + +Random testing produced several cases of unstable welds in which the inner +container something like 'sort ('. The problem was that there are special +rules which prevent a break following such a paren. The problem was fixed by +preventing welds at these locations. + +This update fixes cases b1077 b1092 b1093 b1094 b1104 b1105 b1108. + +17 Apr 2021. + =item B This fixes issue git #62. A similar issue for the % operator was fixed. -- 2.39.5