From 3da7e419bd07a98fc2c7c69c3f512c8678b99ba6 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 7 Mar 2021 07:46:51 -0800 Subject: [PATCH] Fix problem with -vtc=n and outdented long lines --- CHANGES.md | 37 +++++++++++++++++++++++++++++--- lib/Perl/Tidy/VerticalAligner.pm | 8 +++++-- local-docs/BugLog.pod | 26 +++++++++++++++++++++- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8e7669f7..b9b32959 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,12 +2,43 @@ ## 2021 01 xx + - Fixed issue git #55 regarding lack of coordination of the --break-before-xxx + flags and the --line-up-parens flag. + + - Fixed issue git #54 regarding irregular application of the --break-before-paren + and similar --break-before-xxx flags, in which lists without commas were not + being formatted according to these flags. + + - Fixed issue git #53. A flag was added to turn off alignment of spaced function + parens. If the --space-function-paren, -sfp flag is set, a side-effect is that the + spaced function parens may get vertically aligned. This can be undesirable, + so a new parameter '--function-paren-vertical-alignment', or '-fpva', has been + added to turn this vertical alignment off. The default is '-fpva', so that + existing formatting is not changed. Use '-nfpva' to turn off unwanted + vertical alignment. To illustrate the possibilities: + + # perltidy [default] + myfun( $aaa, $b, $cc ); + mylongfun( $a, $b, $c ); + + # perltidy -sfp + myfun ( $aaa, $b, $cc ); + mylongfun ( $a, $b, $c ); + + # perltidy -sfp -nfpva + myfun ( $aaa, $b, $cc ); + mylongfun ( $a, $b, $c ); + - Fixed issue git #51, a closing qw bare paren was not being outdented when the -nodelete-old-newlines flag was set. - - Fixed a rare problem with -lp formatting which could cause alternating - output states. Except for some very deeply nested data structures, - most scripts formatted with this option will not be changed. + - Fixed numerous edge cases involving unusual parameter combinations which + could cause alternating output states. Most scripts will not be + changed by these fixes. + + - A more complete list of updates is at + + https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod ## 2021 01 11 diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 3100eda0..9bcf2318 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -4787,6 +4787,7 @@ sub get_output_line_number { # perl527/(method.t.2, reg_mesg.t, mime-header.t) # handle outdenting of long lines: + my $is_outdented_line; if ($outdent_long_lines) { my $excess = $str_length - @@ -4807,6 +4808,7 @@ sub get_output_line_number { } $outdented_line_count++; $self->[_outdented_line_count_] = $outdented_line_count; + $is_outdented_line = 1; } } @@ -5075,8 +5077,10 @@ sub get_output_line_number { } } - # write or cache this line - if ( !$open_or_close || $side_comment_length > 0 ) { + # write or cache this line ... + # fix for case b999: do not cache an outdented line + if ( !$open_or_close || $side_comment_length > 0 || $is_outdented_line ) + { $self->valign_output_step_C( $line, $leading_space_count, $level, $Kend ); } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 348eaaac..972949f0 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,30 @@ =over 4 +=item B + +Random testing produced an issue with -vtc=1 and an outdented long +line. The parameters for b999 are + + --maximum-line-length=75 + --paren-vertical-tightness-closing=1 + +File 'b999.in' state 1 is + + while ( $line =~ + s/^([^\t]*)(\t+)/$1.(" " x ((length($2)<<3)-(length($1)&7)))/e + ) + +and state 2 is + + while ( $line =~ + s/^([^\t]*)(\t+)/$1.(" " x ((length($2)<<3)-(length($1)&7)))/e) + +The problem was fixed by turning off caching for outdented long lines. +This fixes case b999. + +7 Mar 2021. + =item B Random testing produced case b932 in which the combination -lp and -wbb='=' @@ -29,7 +53,7 @@ check the -wba flag setting. This update fixes case b932. -7 Mar 2021. +7 Mar 2021, 63129c3. =item B -- 2.39.5