]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix issues b1390, b1392
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 16 Oct 2022 01:20:23 +0000 (18:20 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 16 Oct 2022 01:20:23 +0000 (18:20 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 17a8504b30939be9826e371164af92abb45e0f0e..d438d243081a7740033a03de42310f8c66e3fe86 100644 (file)
@@ -10349,6 +10349,57 @@ unlink(
 --variable-maximum-line-length
 --want-trailing-commas='b'
 
+==> b1390.in <==
+    seek
+      (
+        FH,
+        $end,
+        0
+        ,
+
+      )
+      ;
+
+    seek
+      (
+        FH,
+        $end,
+        0
+
+      )
+      ;
+
+==> b1390.par <==
+--add-trailing-commas
+--delete-trailing-commas
+--maximum-line-length=1
+--want-trailing-commas='h'
+
+==> b1392.in <==
+if (  ioctl (  STDERR, $TIOCGWINSZ,
+               $winsize, )
+  ) {
+          ...;
+}
+
+if (  ioctl (  STDERR, $TIOCGWINSZ, $winsize
+      )
+  )
+{
+          ...;
+}
+
+==> b1392.par <==
+--add-trailing-commas
+--delete-trailing-commas
+--extended-line-up-parentheses
+--ignore-old-breakpoints
+--indent-columns=10
+--maximum-line-length=45
+--paren-vertical-tightness=2
+--space-keyword-paren
+--want-trailing-commas='b'
+
 ==> b140.in <==
 $cmd[ $i ]=[
         $s, $e, $cmd, \@hunk, $i ] ;
index 4cb161cdc09a4a91c147123f992a625094b0da37..f076004037fb087333a45909fe6c8cdd983dbf8f 100644 (file)
@@ -327,6 +327,7 @@ my (
     $line_up_parentheses_control_is_lxpl,
 
     %trailing_comma_rules,
+    $wtc_cutoff_level,
 
     # regex patterns for text identification.
     # Most are initialized in a sub make_**_pattern during configuration.
@@ -1795,9 +1796,6 @@ EOM
     initialize_keep_old_breakpoints( $rOpts->{'keep-old-breakpoints-after'},
         'kba', \%keep_break_after_type );
 
-    %trailing_comma_rules = ();
-    initialize_trailing_comma_rules();
-
     #------------------------------------------------------------
     # Make global vars for frequently used options for efficiency
     #------------------------------------------------------------
@@ -2030,6 +2028,9 @@ EOM
         $stress_level_beta = $level;
     }
 
+    %trailing_comma_rules = ();
+    initialize_trailing_comma_rules();
+
     initialize_weld_nested_exclusion_rules();
     initialize_weld_fat_comma_rules();
 
@@ -2486,6 +2487,9 @@ sub initialize_trailing_comma_rules {
     #        if -atc set will add these
     #        if -dtc set will delete other trailing commas
 
+    # This routine must be called after the alpha and beta stress levels
+    # have been defined.
+
     my $rvalid_flags = [qw(0 1 * m b h)];
 
     my $option = $rOpts->{'want-trailing-commas'};
@@ -2571,6 +2575,24 @@ EOM
             %trailing_comma_rules = %rule_hash;
         }
     }
+
+    # Adding and deleting under stress can lead to instability.
+    # So we define an indentation level above which we shut things down
+    # if both adding and deleting trailing commas are requested.
+    # This fixes b1389, b1390, b1391, b1392.
+    if ( $rOpts_add_trailing_commas && $rOpts_delete_trailing_commas ) {
+
+        # This is the same as the $lp_cutoff_level used to shut down -lp:
+        $wtc_cutoff_level = min( $stress_level_alpha, $stress_level_beta + 2 );
+
+        # If the level is zero, then we can turn off everything right now.
+        if ( $wtc_cutoff_level < 1 ) {
+            %trailing_comma_rules         = ();
+            $rOpts_add_trailing_commas    = 0;
+            $rOpts_delete_trailing_commas = 0;
+        }
+    }
+
     return;
 }
 
@@ -7747,6 +7769,10 @@ sub add_trailing_comma {
     my $type_p = $rLL_new->[$Kp]->[_TYPE_];
     return if ( $type_p eq '#' );
 
+    return
+      if ( defined($wtc_cutoff_level)
+        && $rLL_new->[$Kp]->[_LEVEL_] >= $wtc_cutoff_level );
+
     # see if the user wants a trailing comma here
     my $match =
       $self->match_trailing_comma_rule( $KK, $Kfirst, $trailing_comma_rule, 1 );
@@ -7790,6 +7816,10 @@ sub delete_trailing_comma {
         return;
     }
 
+    return
+      if ( defined($wtc_cutoff_level)
+        && $rLL_new->[$Kp]->[_LEVEL_] >= $wtc_cutoff_level );
+
     # See if the user wants this trailing comma
     my $match =
       $self->match_trailing_comma_rule( $KK, $Kfirst, $trailing_comma_rule, 0 );