From: Steve Hancock Date: Sat, 2 Oct 2021 14:07:02 +0000 (-0700) Subject: fix issue c081, -cscw flag was preventing some csc deletions X-Git-Tag: 20211029~44 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=25ef8e8a1fc61dba0cc9fdab15704803772d6f68;p=perltidy.git fix issue c081, -cscw flag was preventing some csc deletions --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 42d8a2ef..20eab4d3 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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; + } } } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 768c08e4..707df233 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,47 @@ =over 4 +=item B + +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 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 @@ -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