From: Steve Hancock Date: Wed, 20 Jan 2021 15:12:33 +0000 (-0800) Subject: added rule for -wn flag: do not weld to a hash brace X-Git-Tag: 20210402~76 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=40214361bf5e83ca9696c27809e801b2123bc5b4;p=perltidy.git added rule for -wn flag: do not weld to a hash brace --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index b1573e2f..138cef9a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6683,6 +6683,12 @@ sub weld_nested_containers { my $iline_io = $inner_opening->[_LINE_INDEX_]; my $iline_ic = $inner_closing->[_LINE_INDEX_]; + # 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); + next unless ( defined($Kp) && $rLL->[$Kp]->[_TOKEN_] eq '@' ); + } + # Set flag saying if this pair starts a new weld my $starting_new_weld = !( @welds && $outer_seqno == $welds[-1]->[0] ); diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 777aea46..41396c12 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,97 @@ =over 4 +=item B + +In random testing, the following two alternating states + + # State 1 + { + if ( defined + ($symbol_table{$direccion}) ) + } + + # State 2 + { + if (defined ( + $symbol_table{ + $direccion} + ) + ) + } + +were occuring with the following particular parameter set + + --weld-nested-containers + --maximum-line-length=40 + --continuation-indentation=7 + --paren-tightness=2 + --extended-continuation-indentation + +The problem was traced to welding to the opening hash brace. A rule +was added to prevent this, and testing with a large body of code +showed that it did not significantly change existing formatting. With +this change, the above snippet formats in the stable state + + { + if (defined( + $symbol_table{$direccion} + )) + } + +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