]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1458
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 12 Jul 2023 03:17:41 +0000 (20:17 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 12 Jul 2023 03:17:41 +0000 (20:17 -0700)
dev-bin/run_convergence_tests.pl.data
dev-bin/run_convergence_tests.pl.expect
lib/Perl/Tidy/Formatter.pm

index 2cbc58112c3ba90941ecb3ed6695aedc4f7cde61..0b804bb5f083540f3885b497d0f41df8eb9cdd53 100644 (file)
@@ -11666,6 +11666,25 @@ BEGIN {
 --extended-continuation-indentation
 --extended-line-up-parentheses
 
+==> b1458.in <==
+     join( '',
+          grep { defined }
+           @{ $me->{'mail_hdr_list'} }
+     );
+
+     join( '',
+          grep { defined }
+           @{ $me->{'mail_hdr_list'}
+           }, );
+
+==> b1458.par <==
+--maximum-line-length=38
+--indent-columns=5
+--continuation-indentation=1
+--add-trailing-commas
+--want-trailing-commas='b'
+--delete-trailing-commas
+
 ==> b146.in <==
 # State 1
 
index f19eb8192ad7509e317bd8be664b723976bddfe9..1a47deee45f599dade7865ff169a6c4f71ced8c3 100644 (file)
@@ -7901,6 +7901,17 @@ BEGIN {
 }
 
 
+==> b1458 <==
+     join( '',
+          grep { defined }
+           @{ $me->{'mail_hdr_list'}
+           }, );
+
+     join( '',
+          grep { defined }
+           @{ $me->{'mail_hdr_list'}
+           }, );
+
 ==> b146 <==
 # State 1
 
index 223462eb5045efd45feb23266dfb2857809bdccd..0591ce6695af1a50078e237ecb6c434abda39caf 100644 (file)
@@ -9566,6 +9566,22 @@ sub add_trailing_comma {
       $self->match_trailing_comma_rule( $KK, $Kfirst, $Kp,
         $trailing_comma_rule, 1 );
 
+    # b1458 fix method 1: do not add if this would excess line length.
+    # This is more general than fix method 2, below, but the logic is not
+    # as clean. So this fix is currently deactivated.
+    if ( 0 && $match && $rOpts_delete_trailing_commas && $KK > 0 ) {
+        my $line_index     = $rLL->[ $KK - 1 ]->[_LINE_INDEX_];
+        my $rlines         = $self->[_rlines_];
+        my $line_of_tokens = $rlines->[$line_index];
+        my $input_line     = $line_of_tokens->{_line_text};
+        my $len            = $self->[_length_function_]->($input_line) - 1;
+        my $level          = $rLL->[$Kfirst]->[_LEVEL_];
+        my $max_len        = $maximum_line_length_at_level[$level];
+        if ( $len >= $max_len ) {
+            $match = 0;
+        }
+    }
+
     # if so, add a comma
     if ($match) {
         my $Knew = $self->store_new_token( ',', ',', $Kp );
@@ -9627,6 +9643,31 @@ sub delete_trailing_comma {
         }
     }
 
+    # b1458 fix method 2: do not remove a comma after a leading brace type 'R'
+    # since it is under stress and could become unstable. This is a more
+    # specific fix but the logic is cleaner than method 1.
+    if (  !$match
+        && $rOpts_add_trailing_commas
+        && $rLL->[$Kfirst]->[_TYPE_] eq 'R' )
+    {
+
+        # previous old token should be the comma..
+        my $Kp_old = $self->K_previous_nonblank( $KK, $rLL );
+        if (   defined($Kp_old)
+            && $Kp_old > $Kfirst
+            && $rLL->[$Kp_old]->[_TYPE_] eq ',' )
+        {
+
+            # if the comma follows the first token of the line ..
+            my $Kpp_old = $self->K_previous_nonblank( $Kp_old, $rLL );
+            if ( defined($Kpp_old) && $Kpp_old eq $Kfirst ) {
+
+                # do not delete it
+                $match = 1;
+            }
+        }
+    }
+
     # If no match, delete it
     if ( !$match ) {