]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix issue b1379
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Oct 2022 13:52:17 +0000 (06:52 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Oct 2022 13:52:17 +0000 (06:52 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 70dd2b3452fd2b592998f2c69c482ef4eab3c2a9..fb62b4fbf978a7c56b6fb0b6290385d28797df0d 100644 (file)
@@ -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 ]=[
index c572e027a6d1396ee756c019816e285ede10d0d4..6ccd0e1a6900d0204f81786236a6874af77e1082 100644 (file)
@@ -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