]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed rare problem with when -lp parameter is set
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Jan 2021 01:01:05 +0000 (17:01 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Jan 2021 01:01:05 +0000 (17:01 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 138cef9a60bf7e5ced5c1138fd74ea9922526934..6ef5b969bff6bc4a13a2d9d78000d3c9fc682214 100644 (file)
@@ -4879,6 +4879,17 @@ sub respace_tokens {
             my $rcopy = copy_token_as_type( $item, 'b', ' ' );
             $rcopy->[_LINE_INDEX_] =
               $rLL_new->[-1]->[_LINE_INDEX_];
+
+            # Patch 23-Jan-2021 to fix -lp blinkers:
+            # The level and ci_level of newly created spaces should be the same
+            # as the previous token.  Otherwise the coding for the -lp option,
+            # in sub set_leading_whitespace, can create a blinking state in
+            # some rare cases.
+            $rcopy->[_LEVEL_] =
+              $rLL_new->[-1]->[_LEVEL_];
+            $rcopy->[_CI_LEVEL_] =
+              $rLL_new->[-1]->[_CI_LEVEL_];
+
             $store_token->($rcopy);
         }
 
@@ -16397,8 +16408,6 @@ sub get_available_spaces_to_go {
         return $item;
     }
 
-    use constant TEST_LP_FIX => 0;
-
     sub set_leading_whitespace {
 
         # This routine defines leading whitespace for the case of -lp formatting
@@ -16413,17 +16422,6 @@ sub get_available_spaces_to_go {
         return unless ($rOpts_line_up_parentheses);
         return unless ( defined($max_index_to_go) && $max_index_to_go >= 0 );
 
-        # Patch created 19-Jan-2021 to fix blinkers. But causes a few differences with
-        # old formatting which need to be checked more.
-        if ( TEST_LP_FIX && $max_index_to_go > 0 && $types_to_go[$max_index_to_go] eq 'b' ) {
-
-            $leading_spaces_to_go[$max_index_to_go] =
-              $leading_spaces_to_go[ $max_index_to_go - 1 ];
-            $reduced_spaces_to_go[$max_index_to_go] =
-              $reduced_spaces_to_go[ $max_index_to_go - 1 ];
-            return;
-        }
-
         my $rbreak_container = $self->[_rbreak_container_];
         my $rshort_nested    = $self->[_rshort_nested_];
         my $rLL              = $self->[_rLL_];
index 41396c1235e1f3d5d1cc58b9ec1cb8915de90689..055c539d37a90ffb9f61d2185114f05573acfe82 100644 (file)
@@ -2,6 +2,37 @@
 
 =over 4
 
+=item B<Some issues with the -lp option>
+
+Random testing revealed some problems involving the B<-lp> option which are
+fixed with this update.
+
+The problem is illustrated with the following snippet
+
+    # perltidy -lp
+    Alien::FillOutTemplate(
+                "$main::libdir/to-$main::desttype/$main::filetype/spec",
+                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
+                %fields
+    );
+
+which alternately formats to this form
+
+    # perltidy -lp
+    Alien::FillOutTemplate(
+                "$main::libdir/to-$main::desttype/$main::filetype/spec",
+                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
+                %fields );
+
+when formatted with the single parameter B<-lp>.  A number of similar examples
+were found in testing. The problem was traced to the treatment of the space
+which perltidy tentatively adds wherever there is a newline, just in case 
+the formatted output has different line breaks.  The problem was that the
+indentation level of these spaces was being set as the level of the next token
+rather than the previous token. Normally the indentation level of a space has
+no effect, but the B<-lp> option does use it and this caused the problem.
+This was fixed 23 Jan 2021.
+
 =item B<added rule for -wn, do not weld to a hash brace>
 
 In random testing, the following two alternating states
@@ -42,57 +73,6 @@ this change, the above snippet formats in the stable state
 
 20 Jan 2021.
 
-=item B<Some issues with the -lp option>
-
-Random testing revealed dome problems involving the B<-lp> option which are
-fixed with this update.
-
-The first problem is illustrated with the following snippet
-
-    $cron =
-      pkgfile( $PACKAGE,
-              "cron.$type" ) ;
-
-which alternately switches to this format
-    
-    $cron =
-      pkgfile( $PACKAGE,
-               "cron.$type"
-      ) ;
-
-when processed with these particular parameters:
-
-    --indent-columns=1
-    --maximum-line-length=26
-    --line-up-parentheses
-    --space-terminal-semicolon
-
-The last parameter, a space before the semicolon, is the main cause of
-the problem. Without it the problem does not occur.
-
-Another problem is illustrated with the following snippet
-
-    Alien::FillOutTemplate(
-                "$main::libdir/to-$main::desttype/$main::filetype/spec",
-                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
-                %fields
-    );
-
-which alternately formats to this form
-
-    # perltidy -lp
-    Alien::FillOutTemplate(
-                "$main::libdir/to-$main::desttype/$main::filetype/spec",
-                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
-                %fields );
-
-when formatted with the single parameter B<-lp>.  These problems can be corrected by
-not processing blank tokens in the sub which sets the leading whitespace for
-the -lp option, 'sub set_leading_whitespace'.  However, this fix can change
-some existing formatting with the -lp flag, so this coding is not yet activated.
-It can be turned on for testing with the internal flag 'TEST_LP_FIX'.
-
-
 =item B<Do not let -kgb option delete essential blank after =cut>
 
 A blinking state was found in random testing for the following snippet