From: Steve Hancock Date: Wed, 23 Nov 2022 16:37:40 +0000 (-0800) Subject: fix b1428 X-Git-Tag: 20221112.01~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=afeb3139fed6a3d6a309eb24a071ea388ce7a916;p=perltidy.git fix b1428 --- diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index c5b5a171..1ec73c9b 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -10988,6 +10988,26 @@ my$sem=sub --variable-maximum-line-length --want-trailing-commas='m' +==> b1428.in <== + is( + grep ( { $_->{branchcode} eq 'MYLIBRARY' and $_->{selected} == 1 } + @$libraries ), + 1, + 'Without selected parameter, my library should be preselected', + ); + + is( + grep ( + { $_->{branchcode} eq 'MYLIBRARY' + and $_->{selected} == 1 } @$libraries ), + 1, +'Without selected parameter, my library should be preselected', + ); + +==> b1428.par <== +--extended-line-up-parentheses +--indent-columns=9 + ==> b1430.in <== $t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index ad935251..55e4a9a7 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -11925,6 +11925,35 @@ BEGIN { }; } +sub is_fragile_block_type { + my ( $self, $block_type, $seqno ) = @_; + + # Given: + # $block_type = the block type of a token, and + # $seqno = its sequence number + + # Return: + # true if this block type stays broken after being broken, + # false otherwise + + # This sub has been added to isolate a tricky decision needed + # to fix issue b1428. + + # The coding here needs to agree with: + # - sub process_line where variable '$rbrace_follower' is set + # - sub process_line_inner_loop where variable '$is_opening_BLOCK' is set, + + if ( $is_sort_map_grep_eval{$block_type} + || $block_type eq 't' + || $self->[_rshort_nested_]->{$seqno} ) + { + return 0; + } + + return 1; + +} ## end sub is_fragile_block_type + sub xlp_collapsed_lengths { my $self = shift; @@ -12385,9 +12414,11 @@ EOM && $block_length < $maximum_line_length_at_level[$level] - # But skip this for sort/map/grep/eval blocks - # because they can reform (b1345) - && !$is_sort_map_grep_eval{$block_type} + # But skip this for blocks types which can reform, + # like sort/map/grep/eval blocks, to avoid + # instability (b1345, b1428) + && $self->is_fragile_block_type( $block_type, + $seqno ) ) { $collapsed_len = $block_length;