From: Steve Hancock Date: Sun, 24 Jan 2021 01:01:05 +0000 (-0800) Subject: fixed rare problem with when -lp parameter is set X-Git-Tag: 20210402~75 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=dc49614c70de521ac3d162cbeaf76c8e0e3cc8ff;p=perltidy.git fixed rare problem with when -lp parameter is set --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 138cef9a..6ef5b969 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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_]; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 41396c12..055c539d 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,37 @@ =over 4 +=item B + +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 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 - -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 A blinking state was found in random testing for the following snippet