]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix problem with excess blank line generation with -blao
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 6 Apr 2021 21:38:58 +0000 (14:38 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 6 Apr 2021 21:38:58 +0000 (14:38 -0700)
bin/perltidy
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/rt113689.par
t/snippets7.t

index ffa7c52791353a9cbcdd3c39470b8be954a0c122..e5fe794fde7613334b5778924af582d5f3ea436a 100755 (executable)
@@ -3481,6 +3481,9 @@ with an opening block brace of a specified type.  By default, this only applies
 to the block of a named B<sub>, but this can be changed (see B<-blaol> below).
 The default is not to do this (B<i=0>).
 
+If the value of B<i> is greater than the limit specified with the parameter
+B<--maximum-consecutive-blank-lines=n>, it will be reduced to that value.
+
 Please see the note below on using the B<-blao> and B<-blbc> options.
 
 =item B<-blbc=i> or B<--blank-lines-before-closing-block=i>
@@ -3518,7 +3521,7 @@ this using
   perltidy -blao=2 -blbc=2 -blaol='*' -blbcl='*' filename
 
 Now suppose the script continues to be developed, but at some later date we
-decide we don't want these spaces after all. we might expect that running with
+decide we don't want these spaces after all. We might expect that running with
 the flags B<-blao=0> and B<-blbc=0> will undo them.  However, by default
 perltidy retains single blank lines, so the blank lines remain.  
 
index 1147c8b33bbecb3a095e1264c5199ca475aba065..b0a66da489bdc95534d1303ab937ac731e951e72 100644 (file)
@@ -7205,9 +7205,13 @@ EOM
                 $ris_essential_old_breakpoint->{$Kprev} = 1;
 
                 # Back up and count length from a token like '=' or '=>' if -lp
-                # is used; this fixes b520
-                if ($rOpts_line_up_parentheses) {
-                    if ( substr( $rLL->[$Kprev]->[_TYPE_], 0, 1 ) eq '=' ) {
+                # is used (this fixes b520)
+                # ...or if a break is wanted before there (this fixes b1041).
+                my $type_prev = $rLL->[$Kprev]->[_TYPE_];
+                if (   $rOpts_line_up_parentheses
+                    || $want_break_before{$type_prev} )
+                {
+                    if ( substr( $type_prev, 0, 1 ) eq '=' ) {
                         $Kref = $Kprev;
                     }
                 }
@@ -11499,9 +11503,10 @@ sub compare_indentation_levels {
     sub grind_batch_of_CODE {
 
         my ($self) = @_;
-        my $file_writer_object = $self->[_file_writer_object_];
 
-        my $this_batch = $self->[_this_batch_];
+        my $file_writer_object = $self->[_file_writer_object_];
+        my $rlines             = $self->[_rlines_];
+        my $this_batch         = $self->[_this_batch_];
         $batch_count++;
 
         my $starting_in_quote        = $this_batch->[_starting_in_quote_];
@@ -11952,14 +11957,35 @@ EOM
 
             # write requested number of blank lines after an opening block brace
             if ( $iterm >= $imin && $types_to_go[$iterm] eq '{' ) {
-                if (   $rOpts->{'blank-lines-after-opening-block'}
+                my $nblanks = $rOpts->{'blank-lines-after-opening-block'};
+                if (   $nblanks
                     && $block_type_to_go[$iterm]
                     && $block_type_to_go[$iterm] =~
                     /$blank_lines_after_opening_block_pattern/ )
                 {
-                    my $nblanks = $rOpts->{'blank-lines-after-opening-block'};
-                    $self->flush_vertical_aligner();
-                    $file_writer_object->require_blank_code_lines($nblanks);
+
+                    if ( $nblanks > $rOpts_maximum_consecutive_blank_lines ) {
+                        $nblanks = $rOpts_maximum_consecutive_blank_lines;
+                    }
+
+                    # Reduce by the existing blank count .. fixes case b1073
+                    my $Kterm = $K_to_go[$iterm];
+                    my $iline = $rLL->[$Kterm]->[_LINE_INDEX_] + 1;
+                    while ( $nblanks > 0 ) {
+                        my $line_of_tokens = $rlines->[$iline];
+                        last unless defined($line_of_tokens);
+                        my $line_type = $line_of_tokens->{_line_type};
+                        last
+                          if ( $line_type ne 'CODE'
+                            || $line_of_tokens->{_code_type} ne 'BL' );
+                        $nblanks--;
+                        $iline++;
+                    }
+
+                    if ($nblanks) {
+                        $self->flush_vertical_aligner();
+                        $file_writer_object->require_blank_code_lines($nblanks);
+                    }
                 }
             }
         }
index 45960e1d7cf9512d4bc2cfce2ff2e000c344ac40..790d2800527d9b92df36b4a9e30e0144da3cb254 100644 (file)
@@ -3,6 +3,38 @@
 
 =over 4
 
+=item B<Fix problem with excess blank line generation with -blao>
+
+Random testing produced some cases where excess blank lines could be generated
+with the parameter -blank-lines-after-opening-block.  Case b1073 has the
+following script
+
+    sub stop {
+
+        1;
+    }
+
+and the following parameters
+
+    --blank-lines-after-opening-block=2
+    --maximum-consecutive-blank-lines=10
+    --maximum-line-length=15
+
+When run, blank lines keep getting generated until the maximum is reached.
+This has been fixed.
+
+6 Apr 2021.
+
+
+=item B<Fix edge case involving -wn and -lp or -bbao>
+
+A change was made to a welding rule involving the -lp option or -wbb='=', and
+very short maximum line lengths.  This correctly fixes case b1041. It replaces
+a fix for this case reported on 2 Apr 2021.
+
+5 Apr 2021.
+
+
 =item B<Modify a condition for applying -bbx=2>
 
 Random testing produced some edge cases in which formatting with the -bbx=2 flags,
@@ -14,14 +46,14 @@ changing much existing formatting.
 
 This update fixes cases b1068 b1069 b1070 b1072 b1073 b1076.
 
-5 Apr 2021.
+5 Apr 2021, 16c4591.
 
 =item B<Improve previous -wn update>
 
 The previous update produced some problems in testing which are corrected
 with this update.
 
-5 Apr 2021.
+5 Apr 2021, ffef089.
 
 =item B<Fix rare convergence problem with -wn>
 
@@ -31,7 +63,7 @@ adjusting a tolerance in the line length calculation.
 
 This fixes cases b1041 b1055.
 
-2 Apr 2021.
+2 Apr 2021, a8b6259.
 
 =item B<Avoid conflict of -bli and -xci>
 
@@ -40,7 +72,7 @@ converge. This was fixed by turning off -xci for braces under -bli control.
 
 This fixes case b1065.
 
-2 Apr 2021.
+2 Apr 2021, d20ea80.
 
 =back
 
index e1f0f8c6d93b4ccdad79240212eee444a4260049..80f49e25e17e8d2747e9df08f353327c0ebd9651 100644 (file)
@@ -2,3 +2,4 @@
 -blbc=1
 -blaol='*'
 -blbcl='*'
+-mbl=2
index e89b4995259bcdb55ed0f194b2373de379719a2f..aff36100c3a4fdf680785c7b8dd5a6539f117d70 100644 (file)
@@ -52,6 +52,7 @@ BEGIN {
 -blbc=1
 -blaol='*'
 -blbcl='*'
+-mbl=2
 ----------
         'rt119970' => "-wn",
     };