]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix inconsistency involving counting commas
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 16 May 2021 14:13:59 +0000 (07:13 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 16 May 2021 14:13:59 +0000 (07:13 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 3f27fb653216800de75cbf544e5c24c7c17be6c7..cabd19d09b3fd3d045b5c0711ffd4cef1d66751b 100644 (file)
@@ -4,6 +4,11 @@
 
     - Added a new option for closing paren placement, -vtc=3, requested in rt #136417.
 
+    - Some nested structures formatted with the -lp indentation option may have
+      some changes in indentation.  This is due to some updates which were made to
+      prevent formatting instability when line lengths are limited by the maximum line
+      length. Most scripts will not be affected.
+
     - A more complete list of updates is at
 
            https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod
index 06f95b6d3698683bd2811a411d952d5e061cac8e..55e2e511bb6792fbc33954c87989c306f7c2903a 100644 (file)
@@ -5110,8 +5110,9 @@ sub respace_tokens {
                 # Fix for case b1100: Count a line ending in ', [' as having
                 # a line-ending comma.  Otherwise, these commas can be hidden
                 # with something like --opening-square-bracket-right
-                if (   $Ktoken_vars == $Klast_old_code
-                    && $last_nonblank_type eq ',' )
+                if (   $last_nonblank_type eq ','
+                    && $Ktoken_vars == $Klast_old_code
+                    && $Ktoken_vars > $Kfirst_old )
                 {
                     $rlec_count_by_seqno->{$type_sequence}++;
                 }
@@ -5750,7 +5751,9 @@ sub respace_tokens {
                         if ($seqno) {
                             $rtype_count_by_seqno->{$seqno}
                               ->{$last_nonblank_type}--;
-                            if (   $last_nonblank_type eq ','
+
+                            if (   $KK == $Kfirst
+                                && $last_nonblank_type eq ','
                                 && $rlec_count_by_seqno->{$seqno} )
                             {
                                 $rlec_count_by_seqno->{$seqno}--;
@@ -8729,7 +8732,12 @@ sub break_before_list_opening_containers {
         elsif ( $break_option == 2 ) {
 
             #  break if this list contains a broken list with line-ending comma
-            my $ok_to_break = $has_list_with_lec;
+            my $ok_to_break;
+            my $Msg = "";
+            if ($has_list_with_lec) {
+                $ok_to_break = 1;
+                $Msg         = "has list with lec;";
+            }
 
             if ( !$ok_to_break ) {
 
@@ -8742,21 +8750,33 @@ sub break_before_list_opening_containers {
                 if ($has_list) { $rno_xci_by_seqno->{$seqno} = 1 }
 
                 my $parent = $rparent_of_seqno->{$seqno};
-                $ok_to_break ||= $self->is_list_by_seqno($parent);
+                if ( $self->is_list_by_seqno($parent) ) {
+                    $Msg         = "parent is list";
+                    $ok_to_break = 1;
+                }
             }
 
             # Patch to fix b1099 for -lp
             #  ok in -lp mode if this is a list which contains a list
             if ( !$ok_to_break && $rOpts_line_up_parentheses ) {
-                $ok_to_break ||= $is_list && $has_list;
+                if ( $is_list && $has_list ) {
+                    $ok_to_break = 1;
+                    $Msg         = "is list or has list";
+                }
             }
 
-            next unless ($ok_to_break);
+            if ( !$ok_to_break ) {
+                DEBUG_BBX
+                  && print STDOUT "Not breaking at seqno=$seqno: $Msg\n";
+                next;
+            }
+
+            DEBUG_BBX
+              && print STDOUT "OK to break at seqno=$seqno: $Msg\n";
 
             # Patch: turn off -xci if -bbx=2 and -lp
             # This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122
             $rno_xci_by_seqno->{$seqno} = 1 if ($rOpts_line_up_parentheses);
-
         }
 
         # -bbx=3 = always break
index cc2bbe13aa5a1e18afa6498c583ddee705bfdcfc..840a674348548ba68a01d1459f36daec1ff5390d 100644 (file)
@@ -2,16 +2,26 @@
 
 =over 4
 
+=item B<Fix inconsistency involving counting commas>
+
+Random testing produced a formatting instability involving the combination of
+flags -bbp=2 -xci -vt=2 -bvtc=2.  The problem was traced to an error in
+counting the number of line ending commas in lists.
+
+This fixes case b1130.
+
+15 May 2021.
+
 =item B<Slightly modify line breaks for -lp indentation>
 
-Random testing produced a edge case of formatting instability for -lp indentation
+Random testing produced an edge case of formatting instability for -lp indentation
 which was traced to checking for an old line break at a '=>'.  This has been fixed.
 Some existing formatting with deeply nested structures may be slightly changed due
 to the fix, but most existing formatting will be unchanged.
 
 This fixes b1035.
 
-15 May 2021.
+15 May 2021, dd42648.
 
 
 =item B<Rewrite coding for -bom flag>