]> git.donarmstrong.com Git - perltidy.git/commitdiff
Adjust line break rules for uncontained commas
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 21 Apr 2021 00:30:44 +0000 (17:30 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 21 Apr 2021 00:30:44 +0000 (17:30 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 3b4fc80574428190b5e6fdfcef5bed0470847659..118031c9d5ccf244d1076dd9e28de17cfe475ffa 100644 (file)
@@ -7440,7 +7440,8 @@ EOM
                     my $level_diff =
                       $outer_opening->[_LEVEL_] - $rLL->[$Kfirst]->[_LEVEL_];
 
-                    if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 ) {
+                    if ( !$level_diff || $excess + $rOpts_indent_columns <= 0 )
+                    {
                         $is_one_line_weld = 1;
                     }
                 }
@@ -15313,21 +15314,28 @@ sub set_continuation_breaks {
             # Changed rule from multiple old commas to just one here:
             if ( $ibreak >= 0 && $obp_count == 1 && $old_comma_break_count > 0 )
             {
-                # Do not to break before an opening token because
-                # it can lead to "blinkers".
                 my $ibreakm = $ibreak;
                 $ibreakm-- if ( $types_to_go[$ibreakm] eq 'b' );
+                if ( $ibreakm >= 0 ) {
 
-                # In order to avoid blinkers we have to be fairly restrictive.
-                # This has been updated to avoid breaking at any sequenced item,
-                # so now ternary operators are included.
-                # (see case b931, which is similar to the above print example)
-                ##This works too but is a little more restrictive:
-                ##if ( $ibreakm >= 0 && !$type_sequence_to_go[$ibreakm] ) {
-                if (   $ibreakm >= 0
-                    && $types_to_go[$ibreakm] !~ /^[\(\{\[L\?\:]$/ )
-                {
-                    $self->set_forced_breakpoint($ibreak);
+                    # In order to avoid blinkers we have to be fairly
+                    # restrictive:
+
+                    # Rule 1: Do not to break before an opening token
+                    # Rule 2: avoid breaking at ternary operators
+                    # (see b931, which is similar to the above print example)
+                    # Rule 3: Do not break at chain operators to fix case b1119
+                    #  - The previous test was '$typem !~ /^[\(\{\[L\?\:]$/'
+
+                    # These rules can be made even more restrictive in the
+                    # future if necessary.
+
+                    my $typem = $types_to_go[$ibreakm];
+                    if (   !$is_chain_operator{$typem}
+                        && !$is_opening_type{$typem} )
+                    {
+                        $self->set_forced_breakpoint($ibreak);
+                    }
                 }
             }
         }
index f631a03637a175c172719c8f0a06a671b2b29905..73f69bbcb37526a0db5880554af8b0e2416ec116 100644 (file)
@@ -2,6 +2,14 @@
 
 =over 4
 
+=item B<Adjust line break rules for uncontained commas>
+
+Random testing produced case c1119 which was unstable due to the formatting
+rules for breaking lines at commas which occur outside of containers. The
+rules were modified to fix the problem.
+
+20 Apr 2021.
+
 =item B<Fix a bad line break choice at a slash>
 
 Random testing produced case c001 in which the following snipppet
@@ -38,7 +46,7 @@ This is a situation where perltidy must ignore a user spacing and line break
 request.  This should have been done but in this case a flag to prevent this
 was not being propagated to later stages of formatting.  This has been fixed.
 
-20 Apr 2021.
+20 Apr 2021, 4fbc69a.
 
 =item B<Fix rare problem with -lp -wn>