]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix issue c081, -cscw flag was preventing some csc deletions
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 2 Oct 2021 14:07:02 +0000 (07:07 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 2 Oct 2021 14:07:02 +0000 (07:07 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 42d8a2efdb9811fd9d70d967554e5cc16cbcdb1e..20eab4d3d8e5db5be2d32f12ce32c165d41571d8 100644 (file)
@@ -19900,7 +19900,7 @@ sub send_lines_to_vertical_aligner {
     my ( $cscw_block_comment, $closing_side_comment );
     if ($rOpts_closing_side_comments) {
         ( $closing_side_comment, $cscw_block_comment ) =
-          $self->add_closing_side_comment();
+          $self->add_closing_side_comment( $ri_first, $ri_last );
     }
 
     # flush before a long if statement to avoid unwanted alignment
@@ -23791,8 +23791,8 @@ sub set_vertical_tightness_flags {
 
 sub add_closing_side_comment {
 
-    my $self = shift;
-    my $rLL  = $self->[_rLL_];
+    my ( $self, $ri_first, $ri_last ) = @_;
+    my $rLL = $self->[_rLL_];
 
     # add closing side comments after closing block braces if -csc used
     my ( $closing_side_comment, $cscw_block_comment );
@@ -23951,14 +23951,28 @@ sub add_closing_side_comment {
                     if ( $block_line_count <
                         $rOpts->{'closing-side-comment-interval'} )
                     {
+                        # Since the line breaks have already been set, we have
+                        # to remove the token from the _to_go array and also
+                        # from the line range (this fixes issue c081).
+                        # Note that we can only get here if -cscw has been set
+                        # because otherwise the old comment is already deleted.
                         $token = undef;
-## FIXME: issue c081. This has not been working for some time.  To make it work,
-## we also have to reduce the value if $iend in the last packed line range.
-## Otherwise, the old closing side comment will remain in the output stream.
-##                        $self->unstore_token_to_go()
-##                          if ( $types_to_go[$max_index_to_go] eq '#' );
-##                        $self->unstore_token_to_go()
-##                          if ( $types_to_go[$max_index_to_go] eq 'b' );
+                        my $ibeg = $ri_first->[-1];
+                        my $iend = $ri_last->[-1];
+                        if (   $iend > $ibeg
+                            && $iend == $max_index_to_go
+                            && $types_to_go[$max_index_to_go] eq '#' )
+                        {
+                            $iend--;
+                            $max_index_to_go--;
+                            if (   $iend > $ibeg
+                                && $types_to_go[$max_index_to_go] eq 'b' )
+                            {
+                                $iend--;
+                                $max_index_to_go--;
+                            }
+                            $ri_last->[-1] = $iend;
+                        }
                     }
                 }
             }
index 768c08e409213d55619a8d92b72368c3f77008bf..707df233e7c17cb2436f1652ee1d382edc00ce0b 100644 (file)
@@ -2,6 +2,47 @@
 
 =over 4
 
+=item B<Fix issue c082, -cscw preventing deletion of closing side comments>
+
+Random testing revealed a problem in which an old closing side comment was not
+being deleted when it fell below the interval specified on -csci=n
+and the -cscw flag was also set.
+
+For example, the following snippet has been formatted with -csc -csci=1. The
+interval -csci=1 insures that all blocks get side comments:
+
+    if ($x3) {
+        $zz;
+        if ($x2) {
+            if ($x1) {
+                ..;
+            } ## end if ($x1)
+            $a;
+            $b;
+            $c;
+        } ## end if ($x2)
+    } ## end if ($x3)
+
+If we then run with -csc -csci=6, the comment ## end if ($x1) will fall below
+the threshold and be removed (correctly):
+
+    if ($x3) {
+        $zz;
+        if ($x2) {
+            if ($x1) {
+                ..;
+            }
+            $a;
+            $b;
+            $c;
+        } ## end if ($x2)
+    } ## end if ($x3)
+
+But if we also add the -cscw flag (warnings) then it was not being removed.  This
+update fixes this problem (issue c081).
+
+2 Oct 2021
+
 =item B<Partial fix for issue git #74 on -lp at anonymous subs>
 
 In the following snippet, the final one-line anonymous sub is not followed by a
@@ -35,7 +76,7 @@ sub is broken into several lines due to its length or complexity, then
 these forced line breaks cause indentation to revert to the standard
 indentation scheme.
 
-22 Sep 2021.
+22 Sep 2021, 4fd58f7.
 
 
 =item B<Fix issues b1209 related to -vmll>
@@ -48,7 +89,7 @@ is set.  In some rare cases there is a difference.  The problem was fixed by
 passing the maximum line length to the vertical aligner so that the calculation
 is only done in the formatter.  This fixes b1209.
 
-20 Sep 2021.
+20 Sep 2021, acf1d2d.
 
 =item B<Fix issue b1208>