From 453ae9a73d1f0234b65dee0a2c60e62bb5e8ad20 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 23 Oct 2024 06:58:27 -0700 Subject: [PATCH] fix stability issue b1492 --- dev-bin/run_convergence_tests.pl.data | 49 +++++++++++++++++++++++++ dev-bin/run_convergence_tests.pl.expect | 27 ++++++++++++++ lib/Perl/Tidy/Formatter.pm | 28 +++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 2a6dc5af..f4f16829 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -12341,6 +12341,55 @@ $e_str->bind ( '' => sub {$e_hnr->tabfocus if $e_hnr->can ( 'tabfocus' ) --add-trailing-commas --want-trailing-commas=1 +==> b1492.in <== + $col->configure ( -command => + sub { $t->configure ( -background => $color ); } ); + + $col->configure( + -command => sub { $t->configure(-background => $color); }, + ); + +==> b1492.par <== +--maximum-line-length=58 +--variable-maximum-line-length +--space-function-paren +--paren-tightness=2 +--add-trailing-commas +--want-trailing-commas='h' +--delete-trailing-commas + +==> b1493.in <== + $w->bind('' => + sub { $t1->yview(scroll => 1, 'pages'); },); + + $w->bind( + '' => sub { $t1->yview(scroll => 1, 'pages'); } + ); + +==> b1493.par <== +--maximum-line-length=58 +--variable-maximum-line-length +--paren-tightness=2 +--add-trailing-commas +--want-trailing-commas='h' +--delete-trailing-commas + +==> b1494.in <== + $b4->bind('<1>' => + sub { cset('D', 'HilightColorFore', "\$color"); },); + + $b4->bind( + '<1>' => sub { cset('D', 'HilightColorFore', "\$color"); } + ); + +==> b1494.par <== +--maximum-line-length=58 +--variable-maximum-line-length +--paren-tightness=2 +--add-trailing-commas +--want-trailing-commas='h' +--delete-trailing-commas + ==> b156.in <== # State 1 { diff --git a/dev-bin/run_convergence_tests.pl.expect b/dev-bin/run_convergence_tests.pl.expect index f744fb05..359b58c7 100644 --- a/dev-bin/run_convergence_tests.pl.expect +++ b/dev-bin/run_convergence_tests.pl.expect @@ -8351,6 +8351,33 @@ $e_str->bind ( Stack ) ; # inherit from Stack +==> b1492 <== + $col->configure ( + -command => sub { $t->configure (-background => $color); } + ); + + $col->configure ( + -command => sub { $t->configure (-background => $color); } + ); + +==> b1493 <== + $w->bind( + '' => sub { $t1->yview(scroll => 1, 'pages'); } + ); + + $w->bind( + '' => sub { $t1->yview(scroll => 1, 'pages'); } + ); + +==> b1494 <== + $b4->bind( + '<1>' => sub { cset('D', 'HilightColorFore', "\$color"); } + ); + + $b4->bind( + '<1>' => sub { cset('D', 'HilightColorFore', "\$color"); } + ); + ==> b156 <== # State 1 { diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 29551f78..aa4e2c1a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -14689,6 +14689,8 @@ sub match_trailing_comma_rule { $fat_comma_count = $rtype_count->{'=>'}; } + my $follows_isolated_closing_token; + #---------------------------------------------------------------- # If no existing commas, see if we have an inner nested container #---------------------------------------------------------------- @@ -14719,6 +14721,16 @@ sub match_trailing_comma_rule { return; } + # Does this trailing comma follow an isolated closing token? + if ($is_nesting_right) { + my $ix_pp = $rLL_new->[$Kpp]->[_LINE_INDEX_]; + my $Kpp_m = $self->K_previous_nonblank( $Kpp, $rLL_new ); + if ($Kpp_m) { + my $ix_pp_m = $rLL_new->[$Kpp_m]->[_LINE_INDEX_]; + $follows_isolated_closing_token = $ix_pp > $ix_pp_m; + } + } + #-------------------------------- # If no comma and no fat comma... #-------------------------------- @@ -14809,8 +14821,20 @@ sub match_trailing_comma_rule { # or has a fat comma not in parens or in parens over several lines # (b1489, b1490) - || ( $fat_comma_count - && ( !$is_paren_list || $iline_c - $iline_o > 1 ) ) + || ( + $fat_comma_count + ## stability fix for b1492 b1493 b1494: a single fat comma in + ## parens must follow an isolated closing token + ##&& ( !$is_paren_list || $iline_c - $iline_o > 1 ) ) + && ( + !$is_paren_list + || ( + ( $iline_c - $iline_o > 1 ) + && ( $follows_isolated_closing_token + || $fat_comma_count > 1 ) + ) + ) + ) # or contains an inner multiline structure || $has_inner_multiline_structure -- 2.39.5