From 61ddd164115e44ec462751d46793fdce123d0f93 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 3 Nov 2021 05:49:15 -0700 Subject: [PATCH] fix b1236, incorrect -kpit function with parenless for --- dev-bin/run_convergence_tests.pl.data | 30 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 17 ++++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 6bdff02f..907df0f8 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -7853,6 +7853,36 @@ $obj= {foo => sub { "bar" ; } --paren-vertical-tightness=1 --weld-nested-containers +==> b1236.in <== +# Added level test when applying kpit +# S1 + delete $ENV{$_} + for + map {$_, uc ($_)} + qw/http_proxy https_proxy all_proxy/; + +# S2 + delete $ENV{$_} + for map { + $_, + uc ( $_ ) + } qw/http_proxy https_proxy all_proxy/; + +# S3 + delete $ENV{$_} for map { + $_, uc ( $_ ) + } qw/http_proxy https_proxy all_proxy/; + + +==> b1236.par <== +--block-brace-tightness=2 +--continuation-indentation=8 +--ignore-old-breakpoints +--keyword-paren-inner-tightness=0 +--maximum-line-length=26 +--space-keyword-paren +--variable-maximum-line-length + ==> b131.in <== unless ( open( SCORE, "+>>$Score_File" ) ) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 87a6ea36..36653c4b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -2619,21 +2619,24 @@ sub set_whitespace_flags { elsif ( $type eq 'k' ) { - # Keywords 'for', 'foreach' are special cases for -kpit since the - # opening paren does not always immediately follow the keyword. So - # we have to search forward for the paren in this case. I have - # limited the search to 10 tokens ahead, just in case somebody - # has a big file and no opening paren. This should be enough for - # all normal code. + # Keywords 'for', 'foreach' are special cases for -kpit since + # the opening paren does not always immediately follow the + # keyword. So we have to search forward for the paren in this + # case. I have limited the search to 10 tokens ahead, just in + # case somebody has a big file and no opening paren. This + # should be enough for all normal code. Added the level check + # to fix b1236. if ( $is_for_foreach{$token} && %keyword_paren_inner_tightness && defined( $keyword_paren_inner_tightness{$token} ) && $j < $jmax ) { - my $jp = $j; + my $level = $rLL->[$j]->[_LEVEL_]; + my $jp = $j; for ( my $inc = 1 ; $inc < 10 ; $inc++ ) { $jp++; last if ( $jp > $jmax ); + last if ( $rLL->[$jp]->[_LEVEL_] != $level ); # b1236 next unless ( $rLL->[$jp]->[_TOKEN_] eq '(' ); my $seqno_p = $rLL->[$jp]->[_TYPE_SEQUENCE_]; $set_container_ws_by_keyword->( $token, $seqno_p ); -- 2.39.5