]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix conflict of -kbl=0 and essential space after =cut
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 11 Feb 2021 23:42:20 +0000 (15:42 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 11 Feb 2021 23:42:20 +0000 (15:42 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 50ba34b237fcf5e0a0def42bf0f14006a99407db..55aff87789f1329cdff606e4b0b4b11b0b88bb49 100644 (file)
@@ -8347,21 +8347,29 @@ sub process_all_lines {
             # Handle blank lines
             if ( $CODE_type eq 'BL' ) {
 
-                # If keep-old-blank-lines is zero, we delete all
-                # old blank lines and let the blank line rules generate any
-                # needed blanks.
-
-                # and delete lines requested by the keyword-group logic
-                my $kgb_keep = !( defined( $rwant_blank_line_after->{$i} )
-                    && $rwant_blank_line_after->{$i} == 2 );
-
-                # But: the keep-old-blank-lines flag has priority over kgb flags
-                $kgb_keep = 1 if ( $rOpts_keep_old_blank_lines == 2 );
+                # Keep this blank? Start with the flag -kbl=n, where
+                #   n=0 ignore all old blank lines
+                #   n=1 stable: keep old blanks, but limited by -mbl=n
+                #   n=2 keep all old blank lines, regardless of -mbl=n
+                # If n=0 we delete all old blank lines and let blank line
+                # rules generate any needed blank lines.
+                my $kgb_keep = $rOpts_keep_old_blank_lines;
+
+               # Then delete lines requested by the keyword-group logic if
+               # allowed
+                if (   $kgb_keep == 1
+                    && defined( $rwant_blank_line_after->{$i} )
+                    && $rwant_blank_line_after->{$i} == 2 )
+                {
+                    $kgb_keep = 0;
+                }
 
-                # Do not delete a blank line following an =cut
-                $kgb_keep = 1 if ( $i - $i_last_POD_END < 3 );
+                # But always keep a blank line following an =cut
+                if ( $i - $i_last_POD_END < 3 && !$kgb_keep ) {
+                    $kgb_keep = 1;
+                }
 
-                if ( $rOpts_keep_old_blank_lines && $kgb_keep ) {
+                if ($kgb_keep) {
                     $self->flush($CODE_type);
                     $file_writer_object->write_blank_code_line(
                         $rOpts_keep_old_blank_lines == 2 );
index 619c049f83de40817fbdc8e68a78bef775d5a7d0..ac9e82133bf9060211f85116cd0747d28b98f49d 100644 (file)
@@ -2,6 +2,15 @@
 
 =over 4
 
+=item B<Fix conflict of -kbl=0 and essential space after =cut>
+
+Random testing produced a case where a blank line after an =cut
+was alternately being deleted and added due to a conflict with
+the flag setting -keep-old-blank-lines=0.  This was resolved by giving
+prioritiy to the essential blank line after the =cut line.
+
+This fixes case b860. 11 Feb 2021.
+
 =item B<Do not break one-line block at here target>
 
 A blinking state produced by random testing was traced to a line of coding
@@ -18,7 +27,7 @@ These will now be output with the blocks intact, like this
 
     unless ($INC{$file}) { die <<"END_DIE" }
 
-This fixes case b523. 11 Feb 2021.
+This fixes case b523. 11 Feb 2021, 6d5bb74.
 
 =item B<Skip processing -kgb* flags in lists or if -maximum-consecutive-blank-lines=0>