]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1436, b1439
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 30 Nov 2022 21:44:59 +0000 (13:44 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 30 Nov 2022 21:44:59 +0000 (13:44 -0800)
.perlcriticrc
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index e294d6a73a31c6fccad491c6d9c953f484ddcd70..68a7829dbb7b19229283591879259fea6e73103f 100644 (file)
@@ -77,10 +77,10 @@ short_subroutine_statements = 2
 # This policy is very useful in locating complex code which might benefit from
 # simplification.  The max value has to be set rather high here because there
 # are some routines in Formatter.pm with high mccabe values. In particular,
-# sub "check_options" has a value of 126 but is a very straightforward sub.
+# sub "check_options" has a value of 133 but is a very straightforward sub.
 # Nothing would be gained by modifying it.
 [Subroutines::ProhibitExcessComplexity]
-max_mccabe=130
+max_mccabe=140
 
 # This policy can be very helpful for locating complex code, but sometimes
 # deep nests are the best option, especially in error handling and debug
index b062e2ab937df8cb11d6945b42aadddea605036f..662496d7da1f1cc407ab8b1e86d49e7fea8b295f 100644 (file)
@@ -11135,6 +11135,70 @@ $last = after (
 --keep-old-breakpoints-after=':'
 --maximum-line-length=34
 
+==> b1436.in <==
+    if (
+           $included{'gold'}
+        && $yes_andor =~ /any/
+        && $not_andor !~ /all/
+        && (
+            grep ( { $included{$_} } @COLORS ) +
+            grep ( { $excluded{$_} } @COLORS ) ) == 5
+            )
+    {
+    }
+
+    if (
+           $included{'gold'}
+        && $yes_andor =~ /any/
+        && $not_andor !~ /all/
+        && (  grep ( { $included{$_} } @COLORS )
+            + grep ( { $excluded{$_} } @COLORS ) ) == 5
+            )
+    {
+    }
+
+==> b1436.par <==
+--continuation-indentation=8
+--extended-continuation-indentation
+--keep-old-breakpoints-after='+'
+--variable-maximum-line-length
+--want-break-before='+'
+
+==> b1439.in <==
+                $pt +=
+                  ( 0.1734 - 0.000393 * $t ) * dsin($m) +
+                  0.0021 * dsin( 2 * $m )
+                  - 0.4068 * dsin($mprime) +
+                  0.0161 * dsin( 2 * $mprime )
+                  - 0.0004 * dsin( 3 * $mprime ) +
+                  0.0104 * dsin( 2 * $f )
+                  - 0.0051 * dsin( $m + $mprime )
+                  - 0.0074 * dsin( $m - $mprime ) +
+                  0.0004 * dsin( 2 * $f + $m )
+                  - 0.0004 * dsin( 2 * $f - $m )
+                  - 0.0006 * dsin( 2 * $f + $mprime ) +
+                  0.0010 * dsin( 2 * $f - $mprime ) +
+                  0.0005 * dsin( $m + 2 * $mprime );
+
+                $pt +=
+                  ( 0.1734 - 0.000393 * $t ) * dsin($m) +
+                  0.0021 * dsin( 2 * $m ) -
+                  0.4068 * dsin($mprime) +
+                  0.0161 * dsin( 2 * $mprime ) -
+                  0.0004 * dsin( 3 * $mprime ) +
+                  0.0104 * dsin( 2 * $f ) -
+                  0.0051 * dsin( $m + $mprime )
+                  - 0.0074 * dsin( $m - $mprime ) +
+                  0.0004 * dsin( 2 * $f + $m ) -
+                  0.0004 * dsin( 2 * $f - $m )
+                  - 0.0006 * dsin( 2 * $f + $mprime ) +
+                  0.0010 * dsin( 2 * $f - $mprime ) +
+                  0.0005 * dsin( $m + 2 * $mprime );
+
+==> b1439.par <==
+--keep-old-breakpoints-after='-'
+--want-break-before='-'
+
 ==> b146.in <==
 # State 1
 
index 4696e7c6b510da8f722010796196f945443acf6b..5ec3cc8dbdd94137f7b7daf6e65c8472379028a6 100644 (file)
@@ -261,6 +261,7 @@ my (
     %is_container_label_type,
     %is_die_confess_croak_warn,
     %is_my_our_local,
+    %is_soft_keep_break_type,
 
     @all_operators,
 
@@ -745,6 +746,13 @@ BEGIN {
     push @q, ',';
     @is_counted_type{@q} = (1) x scalar(@q);
 
+    # Tokens where --keep-old-break-xxx flags make soft breaks instead
+    # of hard breaks.  See b1433 and b1436.
+    # NOTE: $type is used as the hash key for now; if other container tokens
+    # are added it might be necessary to use a token/type mixture.
+    @q = qw# -> ? : && || + - / * #;
+    @is_soft_keep_break_type{@q} = (1) x scalar(@q);
+
 }
 
 {    ## begin closure to count instances
@@ -1799,6 +1807,31 @@ EOM
     initialize_keep_old_breakpoints( $rOpts->{'keep-old-breakpoints-after'},
         'kba', \%keep_break_after_type );
 
+    # Modify %keep_break_before and %keep_break_after to avoid conflicts
+    # with %want_break_before; fixes b1436.
+    # This became necessary after breaks for some tokens were converted
+    # from hard to soft (see b1433).
+    # We could do this for all tokens, but to minimize changes to existing
+    # code we currently only do this for the soft break tokens.
+    foreach my $key ( keys %keep_break_before_type ) {
+        if (   defined( $want_break_before{$key} )
+            && !$want_break_before{$key}
+            && $is_soft_keep_break_type{$key} )
+        {
+            $keep_break_after_type{$key} = $keep_break_before_type{$key};
+            delete $keep_break_before_type{$key};
+        }
+    }
+    foreach my $key ( keys %keep_break_after_type ) {
+        if (   defined( $want_break_before{$key} )
+            && $want_break_before{$key}
+            && $is_soft_keep_break_type{$key} )
+        {
+            $keep_break_before_type{$key} = $keep_break_after_type{$key};
+            delete $keep_break_after_type{$key};
+        }
+    }
+
     $controlled_comma_style ||= $keep_break_before_type{','};
     $controlled_comma_style ||= $keep_break_after_type{','};
 
@@ -8861,19 +8894,6 @@ EOM
     return ( $severe_error, $rqw_lines );
 } ## end sub resync_lines_and_tokens
 
-my %is_soft_break_type;
-
-BEGIN {
-
-    # Soft breaks are needed to avoid conflicts for token types which might be
-    # treated with special logic for chains.  Fixes b1433, 1434, 1435.
-    # NOTE: $type is used as the hash key for now; if other container tokens
-    # are added it might be necessary to use a token/type mixture.
-    my @q = qw# -> ? : && || + - / * #;
-    @is_soft_break_type{@q} = (1) x scalar(@q);
-
-}
-
 sub keep_old_line_breaks {
 
     # Called once per file to find and mark any old line breaks which
@@ -8949,7 +8969,7 @@ sub keep_old_line_breaks {
         if ( !$seqno ) {
             my $type = $rLL->[$KK]->[_TYPE_];
             if ( $rkeep_break_hash->{$type} ) {
-                $rbreak_hash->{$KK} = $is_soft_break_type{$type} ? 2 : 1;
+                $rbreak_hash->{$KK} = $is_soft_keep_break_type{$type} ? 2 : 1;
             }
         }
 
@@ -8983,7 +9003,8 @@ sub keep_old_line_breaks {
                 }
                 if ($match) {
                     my $type = $rLL->[$KK]->[_TYPE_];
-                    $rbreak_hash->{$KK} = $is_soft_break_type{$type} ? 2 : 1;
+                    $rbreak_hash->{$KK} =
+                      $is_soft_keep_break_type{$type} ? 2 : 1;
                 }
             }
         }