From 9ba001c8b75810864322e3aaf8b8175b270e6e03 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 11 Oct 2022 06:52:17 -0700 Subject: [PATCH] fix issue b1379 --- dev-bin/run_convergence_tests.pl.data | 31 ++++++++++++++++++++++++++- lib/Perl/Tidy/Formatter.pm | 25 ++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 70dd2b34..fb62b4fb 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -10190,7 +10190,36 @@ $font_size } ==> b1378.par <== --extrude -vtc=2 -dtc=1 +-extrude -vtc=2 -dtc -tcs=0 + +==> b1379.in <== +# S1 +print star ( + 'Sol', + planet ( + 'Earth', moon ('Lunar') + ), ); + +# S2 +print star ( + 'Sol', + planet ( + 'Earth', moon ('Lunar'), ) +); + + +==> b1379.par <== +--add-trailing-commas +--delete-trailing-commas +--extended-line-up-parentheses +--ignore-old-breakpoints +--indent-columns=3 +--maximum-fields-per-table=27 +--maximum-line-length=40 +--space-function-paren +--trailing-comma-style='b' +--variable-maximum-line-length +--vertical-tightness-closing=2 ==> b140.in <== $cmd[ $i ]=[ diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index c572e027..6ccd0e1a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -529,6 +529,7 @@ BEGIN { _roverride_cab3_ => $i++, _ris_assigned_structure_ => $i++, _ris_short_broken_eval_block_ => $i++, + _ris_bare_trailing_comma_by_seqno_ => $i++, _rseqno_non_indenting_brace_by_ix_ => $i++, _rreduce_vertical_tightness_by_seqno_ => $i++, @@ -952,6 +953,7 @@ sub new { $self->[_roverride_cab3_] = {}; $self->[_ris_assigned_structure_] = {}; $self->[_ris_short_broken_eval_block_] = {}; + $self->[_ris_bare_trailing_comma_by_seqno_] = {}; $self->[_rseqno_non_indenting_brace_by_ix_] = {}; $self->[_rreduce_vertical_tightness_by_seqno_] = {}; @@ -2463,7 +2465,7 @@ sub initialize_trailing_comma_rules { # if -dtc set => will delete non-bare trailing commas # =h or 'hash': single column stable bare lists require trailing comma # if -atc set will add these - # TODO: currently only works with -atc + # if -dtc set will delete other trailing commas my $rvalid_flags = [qw(0 1 * m b h)]; @@ -8099,6 +8101,18 @@ sub match_trailing_comma_rule { $rLL_new ); } + # Fix for b1379, b1380, part 1. Mark bare trailing commas for use by -vtc + # logic to avoid instability when -dtc and -atc are both active. + if ( $match + && ( $trailing_comma_style eq 'b' || $trailing_comma_style eq 'h' ) ) + { + if ( $if_add && $rOpts_delete_trailing_commas + || !$if_add && $rOpts_add_trailing_commas ) + { + $self->[_ris_bare_trailing_comma_by_seqno_]->{$type_sequence} = 1; + } + } + return $match; } @@ -27486,6 +27500,15 @@ sub set_vertical_tightness_flags { $cvt = 1; } + # Fix for b1379, b1380, part 2. In some rare cases, -cvt=2 can be + # unstable with adding and deleting trailing bare commas. + # Reducing to -cvt=1 seems to restore stability. + if ( $cvt == 2 + && $self->[_ris_bare_trailing_comma_by_seqno_]->{$seqno} ) + { + $cvt = 1; + } + if ( # Never append a trailing line like ')->pack(' because it -- 2.39.5