]> git.donarmstrong.com Git - perltidy.git/commitdiff
Follow user requests better to break before operators
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 29 Mar 2021 02:16:51 +0000 (19:16 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 29 Mar 2021 02:16:51 +0000 (19:16 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index e7e3a1d33ffebc37e994c6f74cc43978f25e7eb5..2c2a8ba909e161e59b030afa6904d6f770383ed7 100644 (file)
@@ -200,6 +200,8 @@ my (
     %is_closing_sequence_token,
     %is_container_label_type,
 
+    @all_operators,
+
     # Initialized in check_options. These are constants and could
     # just as well be initialized in a BEGIN block.
     %is_do_follower,
@@ -546,6 +548,13 @@ BEGIN {
     @q = qw(&& || and or : ? . + - * /);
     @is_chain_operator{@q} = (1) x scalar(@q);
 
+    # Operators that the user can request break before or after.
+    # Note that some are keywords
+    @all_operators = qw(% + - * / x != == >= <= =~ !~ < > | &
+      = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
+      . : ? && || and or err xor
+    );
+
     # We can remove semicolons after blocks preceded by these keywords
     @q =
       qw(BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif else
@@ -1230,11 +1239,6 @@ EOM
     }
 
     # implement user break preferences
-    my @all_operators = qw(% + - * / x != == >= <= =~ !~ < > | &
-      = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
-      . : ? && || and or err xor
-    );
-
     my $break_after = sub {
         my @toks = @_;
         foreach my $tok (@toks) {
@@ -11162,7 +11166,12 @@ sub compare_indentation_levels {
     my %break_before_or_after_token;
 
     BEGIN {
-        my @q = qw( = . : ? and or xor && || );
+
+        # Updated to use all operators. This fixes case b1054
+        # Here is the previous simplified version:
+        ## my @q = qw( . : ? and or xor && || );
+        my @q = @all_operators;
+
         push @q, ',';
         @break_before_or_after_token{@q} = (1) x scalar(@q);
     }
@@ -11211,16 +11220,18 @@ sub compare_indentation_levels {
         return if ( $self->weld_len_right_to_go($i) );
 
         my $token = $tokens_to_go[$i];
+        my $type  = $types_to_go[$i];
 
         # For certain tokens, use user settings to decide if we break before or
         # after it
-        #    qw( = . : ? and or xor && || )
-        if ( $break_before_or_after_token{$token} ) {
+        if ( $break_before_or_after_token{$token}
+            && ( $type eq $token || $type eq 'k' ) )
+        {
             if ( $want_break_before{$token} && $i >= 0 ) { $i-- }
         }
 
         # breaks are forced before 'if' and 'unless'
-        elsif ( $is_if_unless{$token} ) { $i-- }
+        elsif ( $is_if_unless{$token} && $type eq 'k' ) { $i-- }
 
         if ( $i >= 0 && $i <= $max_index_to_go ) {
             my $i_nonblank = ( $types_to_go[$i] ne 'b' ) ? $i : $i - 1;
index 9ce8707121b1676e317791893ceb8e5c9ccedd81..6795b6be907b854dc66659d0af33ed00a300bfe7 100644 (file)
@@ -2,6 +2,27 @@
 
 =over 4
 
+=item B<Follow user requests better to break before operators>
+
+Random testing produced some cases in which user requests to break before selected
+operators were not being followed.  For example
+
+    # OLD: perltidy -wbb='.='
+    $value .=
+      ( grep /\s/, ( $value, $next ) )
+      ? " $next"
+      : $next;
+
+    # FIXED: perltidy -wbb='.='
+    $value
+      .= ( grep /\s/, ( $value, $next ) )
+      ? " $next"
+      : $next;
+
+This fixes case b1054.
+
+28 Mar 2021.
+
 =item B<Fix problems with combinations of -iob -lp>
 
 This is an correction to the update of 13 Mar 2021, 71adc77.  Random testing
@@ -13,7 +34,7 @@ This update fixes these old cases: b1021 b1023
 
 and these new cases: b1034 b1048 b1049 b1050 b1056 b1058
 
-27 Mar 2021
+27 Mar 2021, cc94623.
 
 =item B<Add flag -lpxl=s to provide control over -lp formatting>