]> git.donarmstrong.com Git - perltidy.git/commitdiff
Revise coding for the --freeze-whitespace option
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 25 Jan 2021 01:53:52 +0000 (17:53 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 25 Jan 2021 01:53:52 +0000 (17:53 -0800)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 6c98498600f31219286d74e47474252cab7f9238..b4cbca6f659cfa2e7919dd986e5c2b37b6d105a1 100644 (file)
@@ -1486,9 +1486,12 @@ EOM
                         my $iterm = $iter - 1;
                         if ( $saw_md5{$digest} != $iterm ) {
 
-                            # Blinking (oscillating) between two stable
-                            # end states.  This has happened in the past
-                            # but at present there are no known instances.
+                            # Blinking (oscillating) between two or more stable
+                            # end states.  This is unlikely to occur with normal
+                            # parameters, but it can occur in stress testing 
+                            # with extreme parameter values, such as very short
+                            # maximum line lengths.  We want to catch and fix
+                            # them when they happen.
                             $convergence_log_message = <<EOM;
 BLINKER. Output for iteration $iter same as for $saw_md5{$digest}. 
 EOM
@@ -3322,7 +3325,6 @@ EOM
         $rOpts->{'opening-brace-on-new-line'} = 1;
     }
 
-
     # it simplifies things if -bl is 0 rather than undefined
     if ( !defined( $rOpts->{'opening-brace-on-new-line'} ) ) {
         $rOpts->{'opening-brace-on-new-line'} = 0;
@@ -3388,6 +3390,17 @@ EOM
         $rOpts->{'sub-alias-list'} = join ' ', @filtered_word_list;
     }
 
+    # The freeze-whitespace option is currently a derived option which has its
+    # own key
+    $rOpts->{'freeze-whitespace'} = !$rOpts->{'add-whitespace'}
+      && !$rOpts->{'delete-old-whitespace'};
+
+    # Turn off certain options if whitespace is frozen
+    # Note: vertical alignment will be automatically shut off
+    if ( $rOpts->{'freeze-whitespace'} ) {
+        $rOpts->{'logical-padding'} = 0;
+    }
+
     # Define $tabsize, the number of spaces per tab for use in
     # guessing the indentation of source lines with leading tabs.
     # Assume same as for this run if tabs are used , otherwise assume
index 5a51768b6134d982cb6ebce31acbbfa390896286..55071c0225bf33b1dd1b96680c176d2b2a501f80 100644 (file)
@@ -170,6 +170,10 @@ my (
     $rOpts_indent_only,
     $rOpts_static_block_comments,
 
+    $rOpts_add_whitespace,
+    $rOpts_delete_old_whitespace,
+    $rOpts_freeze_whitespace,
+
     # Static hashes initialized in a BEGIN block
     %is_assignment,
     %is_keyword_returning_list,
@@ -1414,8 +1418,8 @@ EOM
             $rOpts->{'keep-old-breakpoints-after'} = "";
         }
 
-       # Note: These additional parameters are made inactive by -iob.
-       # They are silently turned off here because they are on by default.
+        # Note: These additional parameters are made inactive by -iob.
+        # They are silently turned off here because they are on by default.
         # We would generate unexpected warnings if we issued a warning.
         $rOpts->{'break-at-old-keyword-breakpoints'}   = 0;
         $rOpts->{'break-at-old-logical-breakpoints'}   = 0;
@@ -1460,6 +1464,10 @@ EOM
     $rOpts_indent_only           = $rOpts->{'indent-only'};
     $rOpts_static_block_comments = $rOpts->{'static-block-comments'};
 
+    $rOpts_add_whitespace        = $rOpts->{'add-whitespace'};
+    $rOpts_delete_old_whitespace = $rOpts->{'delete-old-whitespace'};
+    $rOpts_freeze_whitespace     = $rOpts->{'freeze-whitespace'};
+
     # Note that both opening and closing tokens can access the opening
     # and closing flags of their container types.
     %opening_vertical_tightness = (
@@ -2555,7 +2563,7 @@ EOM
           # (testfiles prnterr1.t with --extrude and mangle.t with --mangle)
           || $typel eq 'Z'
 
-          # Added 'Y' here 16 Jan 2021 to prevent -mangle option from removing 
+          # Added 'Y' here 16 Jan 2021 to prevent -mangle option from removing
           # space after type Y. Otherwise, it will get parsed as type 'Z' later
           # and any space would have to be added back manually if desired.
           || $typel eq 'Y'
@@ -4713,8 +4721,6 @@ sub respace_tokens {
     my $CODE_type = "";
     my $line_type = "";
 
-    my $rOpts_add_whitespace        = $rOpts->{'add-whitespace'};
-    my $rOpts_delete_old_whitespace = $rOpts->{'delete-old-whitespace'};
     my $rOpts_ignore_side_comment_lengths =
       $rOpts->{'ignore-side-comment-lengths'};
 
@@ -5252,7 +5258,13 @@ sub respace_tokens {
                 # white space BEFORE the token is needed
                 next if ( $KK >= $Klast );    # skip terminal blank
                 my $Knext = $KK + 1;
-                my $ws    = $rwhitespace_flags->[$Knext];
+
+                if ($rOpts_freeze_whitespace) {
+                    $store_token->($rtoken_vars);
+                    next;
+                }
+
+                my $ws = $rwhitespace_flags->[$Knext];
                 if (   $ws == -1
                     || $rOpts_delete_old_whitespace )
                 {
@@ -5285,10 +5297,8 @@ sub respace_tokens {
                     next unless ($do_not_delete);
                 }
 
-                # make it just one character if allowed
-                if ($rOpts_add_whitespace) {
-                    $rtoken_vars->[_TOKEN_] = ' ';
-                }
+                # make it just one character
+                $rtoken_vars->[_TOKEN_] = ' ';
                 $store_token->($rtoken_vars);
                 next;
             }
@@ -6696,7 +6706,7 @@ sub weld_nested_containers {
 
         # RULE: do not weld to a hash brace unless it is preceded by @
         if ( $inner_opening->[_TYPE_] eq 'L' ) {
-            my $Kp  = $self->K_previous_nonblank($Kinner_opening);
+            my $Kp = $self->K_previous_nonblank($Kinner_opening);
             next unless ( defined($Kp) && $rLL->[$Kp]->[_TOKEN_] eq '@' );
         }
 
@@ -7585,7 +7595,7 @@ sub adjust_container_indentation {
         # This is only for list containers
         next unless $self->is_list_by_seqno($seqno);
 
-        # and only for broken lists. 
+        # and only for broken lists.
         # Require container to span 3 or more line to avoid blinkers,
         # so line difference must be 2 or more.
         next
@@ -17183,11 +17193,12 @@ sub send_lines_to_vertical_aligner {
         }
         else {
 
-            # Patch for git #51, a bare closing qw paren was not outdented 
+            # Patch for git #51, a bare closing qw paren was not outdented
             # if the flag '-nodelete-old-newlines is set
             my $Kbeg_next = $self->K_next_code($Kend);
             if ( defined($Kbeg_next) ) {
-                 $ljump = $rLL->[$Kbeg_next]->[_LEVEL_] - $rLL->[$Kend]->[_LEVEL_];
+                $ljump =
+                  $rLL->[$Kbeg_next]->[_LEVEL_] - $rLL->[$Kend]->[_LEVEL_];
             }
         }
 
@@ -17448,7 +17459,6 @@ sub send_lines_to_vertical_aligner {
         my ( $self, $ri_first, $ri_last ) = @_;
         my $rspecial_side_comment_type = $self->[_rspecial_side_comment_type_];
 
-        my $rOpts_add_whitespace = $rOpts->{'add-whitespace'};
         my $ralignment_type_to_go;
 
         # Initialize the alignment array. Note that closing side comments can
index 72a60a8f4a749ad516f33f48e62542a7b8501077..674a194a0c86d6659dc2dd87d6c6dcdfce47f24c 100644 (file)
@@ -2,6 +2,14 @@
 
 =over 4
 
+=item B<Revise coding for the --freeze-whitespace option>
+
+Random testing produced some blinking states which were traced to an incorrect
+implementation of the B<--freeze-whitespace> option (which is mainly useful
+in stress testing perltidy).  A related flag, --add-whitespace is involved.
+This update corrects these problems.  Test cases include b057, b183, b242.
+24 Jan 2021.
+
 =item B<Fix for issue git #51, closing qw paren not outdented when -ndnl is set>
 
 The problem is that a bare closing qw paren was not being outdented