From: Steve Hancock Date: Mon, 19 Jul 2021 00:00:21 +0000 (-0700) Subject: Fix to keep from losing blank lines after a code-skipping section X-Git-Tag: 20210717.01~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9648e169fbb76659a7f42d6959494bdc95754228;p=perltidy.git Fix to keep from losing blank lines after a code-skipping section --- diff --git a/CHANGES.md b/CHANGES.md index 8c36f599..5f6f0af6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,15 @@ # Perltidy Change Log +## 2021 07 17.01 + + - Fixed problem where a blank line following a closing code-skipping + comment, '#>>V', can be lost. A workaround for the previous version + is to include the parameter '-mbl=2'. + + - Numerous minor fixes have been made. A complete list is at: + + https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod + ## 2021 07 17 - This release is being made mainly because of the next item, in which an diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index cdca0f1a..f70ea794 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -9654,6 +9654,14 @@ sub process_all_lines { $self->[_saw_END_or_DATA_] = 1; } + # Patch to avoid losing blank lines after a code-skipping block; + # fixes case c047. Note that the code for code-skipping is + # currently 'FORMAT'. If it changes, the next line would need to + # be changed. + elsif ( $line_type eq 'FORMAT' ) { + $file_writer_object->reset_consecutive_blank_lines(); + } + # write unindented non-code line if ( !$skip_line ) { $self->write_unindented_line($input_line); diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 1ca07254..b37001c8 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,49 @@ =over 4 +=item B + +A problem in the current version of perltidy is that a blank line +after the closing code-skipping comment can be lost if there was a blank +line before the start of the code skipping section. For example, given +the following code: + + $x = 1; + + #< 'bar', baz => 'buz' ); + print keys(%#), "\n"; + #>>V + + @# = ( foo, 'bar', baz, 'buz' ); + print @#, "\n"; + +running perltidy gives: + + $x = 1; + + #< 'bar', baz => 'buz' ); + print keys(%#), "\n"; + #>>V + @# = ( foo, 'bar', baz, 'buz' ); + print @#, "\n"; + +Notice that the blank line after the closing comment #>>V is missing. What +happened is that the formatter is counting blank lines and did not 'see' the +code skipping section. So the blank after the closing comment looked like the +second blank in a row, so it got removed since the default is +--maximum-consecutive-blank-lines=1. + +This update fixes this by resetting the counter. This fixes case c047. +A simple workaround until the next release is to include the parameter + +--maximum-consecutive-blank-lines=2, or -mbl=2. + +It can be removed after the next release. + +18 Jul 2021. + =item B Random testing produced a case of formatting instability involving welding