]> git.donarmstrong.com Git - perltidy.git/commitdiff
Moved logic of previous update to the FileWriter module
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 7 Apr 2021 01:28:30 +0000 (18:28 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 7 Apr 2021 01:28:30 +0000 (18:28 -0700)
bin/perltidy
lib/Perl/Tidy/FileWriter.pm
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index e5fe794fde7613334b5778924af582d5f3ea436a..142c09608f0402e7b204b2e16be90cd7b71b5d34 100755 (executable)
@@ -3481,9 +3481,6 @@ 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>
index fb5af8e15534664ad19032543e438d0aca9a0a87..10e72ac3ba3f760aa45e78124723317aa78ef3a4 100644 (file)
@@ -47,25 +47,26 @@ BEGIN {
     # Array index names for variables
     my $i = 0;
     use constant {
-        _line_sink_object_           => $i++,
-        _logger_object_              => $i++,
-        _rOpts_                      => $i++,
-        _output_line_number_         => $i++,
-        _consecutive_blank_lines_    => $i++,
-        _consecutive_nonblank_lines_ => $i++,
-        _first_line_length_error_    => $i++,
-        _max_line_length_error_      => $i++,
-        _last_line_length_error_     => $i++,
-        _first_line_length_error_at_ => $i++,
-        _max_line_length_error_at_   => $i++,
-        _last_line_length_error_at_  => $i++,
-        _line_length_error_count_    => $i++,
-        _max_output_line_length_     => $i++,
-        _max_output_line_length_at_  => $i++,
-        _rK_checklist_               => $i++,
-        _K_arrival_order_matches_    => $i++,
-        _K_sequence_error_msg_       => $i++,
-        _K_last_arrival_             => $i++,
+        _line_sink_object_            => $i++,
+        _logger_object_               => $i++,
+        _rOpts_                       => $i++,
+        _output_line_number_          => $i++,
+        _consecutive_blank_lines_     => $i++,
+        _consecutive_nonblank_lines_  => $i++,
+        _consecutive_new_blank_lines_ => $i++,
+        _first_line_length_error_     => $i++,
+        _max_line_length_error_       => $i++,
+        _last_line_length_error_      => $i++,
+        _first_line_length_error_at_  => $i++,
+        _max_line_length_error_at_    => $i++,
+        _last_line_length_error_at_   => $i++,
+        _line_length_error_count_     => $i++,
+        _max_output_line_length_      => $i++,
+        _max_output_line_length_at_   => $i++,
+        _rK_checklist_                => $i++,
+        _K_arrival_order_matches_     => $i++,
+        _K_sequence_error_msg_        => $i++,
+        _K_last_arrival_              => $i++,
     };
 }
 
@@ -89,25 +90,26 @@ sub new {
     my ( $class, $line_sink_object, $rOpts, $logger_object ) = @_;
 
     my $self = [];
-    $self->[_line_sink_object_]           = $line_sink_object;
-    $self->[_logger_object_]              = $logger_object;
-    $self->[_rOpts_]                      = $rOpts;
-    $self->[_output_line_number_]         = 1;
-    $self->[_consecutive_blank_lines_]    = 0;
-    $self->[_consecutive_nonblank_lines_] = 0;
-    $self->[_first_line_length_error_]    = 0;
-    $self->[_max_line_length_error_]      = 0;
-    $self->[_last_line_length_error_]     = 0;
-    $self->[_first_line_length_error_at_] = 0;
-    $self->[_max_line_length_error_at_]   = 0;
-    $self->[_last_line_length_error_at_]  = 0;
-    $self->[_line_length_error_count_]    = 0;
-    $self->[_max_output_line_length_]     = 0;
-    $self->[_max_output_line_length_at_]  = 0;
-    $self->[_rK_checklist_]               = [];
-    $self->[_K_arrival_order_matches_]    = 0;
-    $self->[_K_sequence_error_msg_]       = "";
-    $self->[_K_last_arrival_]             = -1;
+    $self->[_line_sink_object_]            = $line_sink_object;
+    $self->[_logger_object_]               = $logger_object;
+    $self->[_rOpts_]                       = $rOpts;
+    $self->[_output_line_number_]          = 1;
+    $self->[_consecutive_blank_lines_]     = 0;
+    $self->[_consecutive_nonblank_lines_]  = 0;
+    $self->[_consecutive_new_blank_lines_] = 0;
+    $self->[_first_line_length_error_]     = 0;
+    $self->[_max_line_length_error_]       = 0;
+    $self->[_last_line_length_error_]      = 0;
+    $self->[_first_line_length_error_at_]  = 0;
+    $self->[_max_line_length_error_at_]    = 0;
+    $self->[_last_line_length_error_at_]   = 0;
+    $self->[_line_length_error_count_]     = 0;
+    $self->[_max_output_line_length_]      = 0;
+    $self->[_max_output_line_length_at_]   = 0;
+    $self->[_rK_checklist_]                = [];
+    $self->[_K_arrival_order_matches_]     = 0;
+    $self->[_K_sequence_error_msg_]        = "";
+    $self->[_K_last_arrival_]              = -1;
 
     # save input stream name for local error messages
     $input_stream_name = "";
@@ -163,6 +165,10 @@ sub get_consecutive_nonblank_lines {
     return $_[0]->[_consecutive_nonblank_lines_];
 }
 
+sub get_consecutive_blank_lines {
+    return $_[0]->[_consecutive_blank_lines_];
+}
+
 sub reset_consecutive_blank_lines {
     $_[0]->[_consecutive_blank_lines_] = 0;
     return;
@@ -199,16 +205,26 @@ sub write_blank_code_line {
       if (!$forced
         && $self->[_consecutive_blank_lines_] >=
         $rOpts->{'maximum-consecutive-blank-lines'} );
-    $self->[_consecutive_blank_lines_]++;
+
     $self->[_consecutive_nonblank_lines_] = 0;
+
+    if ( !$forced && $self->[_consecutive_new_blank_lines_] > 0 ) {
+        $self->[_consecutive_new_blank_lines_]--;
+        return;
+    }
+
     $self->write_line("\n");
+    $self->[_consecutive_blank_lines_]++;
+    $self->[_consecutive_new_blank_lines_]++ if ($forced);
+
     return;
 }
 
 sub write_code_line {
     my ( $self, $str, $K ) = @_;
 
-    $self->[_consecutive_blank_lines_] = 0;
+    $self->[_consecutive_blank_lines_]     = 0;
+    $self->[_consecutive_new_blank_lines_] = 0;
     $self->[_consecutive_nonblank_lines_]++;
     $self->write_line($str);
 
index b0a66da489bdc95534d1303ab937ac731e951e72..9a87efe77c2adb78e3ccdab926859f014aee6b9d 100644 (file)
@@ -8962,7 +8962,7 @@ sub process_all_lines {
     my $rwant_blank_line_after = $self->keyword_group_scan();
 
     my $line_type      = "";
-    my $i_last_POD_END = -1;
+    my $i_last_POD_END = -10;
     my $i              = -1;
     foreach my $line_of_tokens ( @{$rlines} ) {
         $i++;
@@ -11503,10 +11503,9 @@ sub compare_indentation_levels {
     sub grind_batch_of_CODE {
 
         my ($self) = @_;
-
         my $file_writer_object = $self->[_file_writer_object_];
-        my $rlines             = $self->[_rlines_];
-        my $this_batch         = $self->[_this_batch_];
+
+        my $this_batch = $self->[_this_batch_];
         $batch_count++;
 
         my $starting_in_quote        = $this_batch->[_starting_in_quote_];
@@ -11957,35 +11956,14 @@ EOM
 
             # write requested number of blank lines after an opening block brace
             if ( $iterm >= $imin && $types_to_go[$iterm] eq '{' ) {
-                my $nblanks = $rOpts->{'blank-lines-after-opening-block'};
-                if (   $nblanks
+                if (   $rOpts->{'blank-lines-after-opening-block'}
                     && $block_type_to_go[$iterm]
                     && $block_type_to_go[$iterm] =~
                     /$blank_lines_after_opening_block_pattern/ )
                 {
-
-                    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);
-                    }
+                    my $nblanks = $rOpts->{'blank-lines-after-opening-block'};
+                    $self->flush_vertical_aligner();
+                    $file_writer_object->require_blank_code_lines($nblanks);
                 }
             }
         }
index 790d2800527d9b92df36b4a9e30e0144da3cb254..dc79b19fb4c9ec2168e61e134a3f04c91986b432 100644 (file)
@@ -3,6 +3,14 @@
 
 =over 4
 
+=item B<Moved logic of previous update to the FileWriter module>
+
+The previous update regarding blank line generation was not sufficiently
+general to handle all possible parameter combinations. The problem was solved
+and simplified by moving the logic to a lower level, in the FileWriter module.
+
+6 Apr 2021.
+
 =item B<Fix problem with excess blank line generation with -blao>
 
 Random testing produced some cases where excess blank lines could be generated