From fe9219d9e56b8ed0ba57034dfb3194d279130722 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 5 Apr 2020 09:17:38 -0700 Subject: [PATCH] adjust -wn rules to avoid blinkers --- lib/Perl/Tidy/Formatter.pm | 8 ++--- t/snippets/expect/wn8.def | 19 ++++++++++ t/snippets/expect/wn8.wn | 15 ++++++++ t/snippets/packing_list.txt | 2 ++ t/snippets/wn8.in | 16 +++++++++ t/snippets17.t | 69 +++++++++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 t/snippets/expect/wn8.def create mode 100644 t/snippets/expect/wn8.wn create mode 100644 t/snippets/wn8.in diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7f59c627..0fa3c26b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4127,7 +4127,8 @@ sub weld_nested_containers { # ->GenerateFieldForSelectSQL() } ); my $iline_oc = $outer_closing->[_LINE_INDEX_]; - if ( $iline_oc <= $iline_oo + 1 ) { + my $token_oo = $outer_opening->[_TOKEN_]; + if ( $iline_oc <= $iline_oo + 1 && $token_oo eq '(') { # Look for following semicolon... my $Knext_nonblank = $self->K_next_nonblank($Kouter_closing); @@ -4135,7 +4136,7 @@ sub weld_nested_containers { defined($Knext_nonblank) ? $rLL->[$Knext_nonblank]->[_TYPE_] : 'b'; - if ( $next_nonblank_type eq ';' ) { + if ( $next_nonblank_type eq ';') { # Then do not weld if no other containers between inner # opening and closing. @@ -4175,8 +4176,7 @@ sub weld_nested_containers { if ( $iline_ic == $iline_io ) { my $token_oo = $outer_opening->[_TOKEN_]; - my $token_io = $inner_opening->[_TOKEN_]; - $do_not_weld ||= $token_oo eq '(' && $token_io ne '('; + $do_not_weld ||= $token_oo eq '('; } # DO-NOT-WELD RULE 3: diff --git a/t/snippets/expect/wn8.def b/t/snippets/expect/wn8.def new file mode 100644 index 00000000..c31a77b0 --- /dev/null +++ b/t/snippets/expect/wn8.def @@ -0,0 +1,19 @@ + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { + { $die_on_fetch, 0 } + }; + + my $res = eval { + { $die_on_fetch, 0 } + }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); diff --git a/t/snippets/expect/wn8.wn b/t/snippets/expect/wn8.wn new file mode 100644 index 00000000..00a672ab --- /dev/null +++ b/t/snippets/expect/wn8.wn @@ -0,0 +1,15 @@ + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { { $die_on_fetch, 0 } }; + + my $res = eval { { $die_on_fetch, 0 } }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 0c4d130b..591731ba 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -322,3 +322,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets17.t wn8.def +../snippets17.t wn8.wn diff --git a/t/snippets/wn8.in b/t/snippets/wn8.in new file mode 100644 index 00000000..9cce7487 --- /dev/null +++ b/t/snippets/wn8.in @@ -0,0 +1,16 @@ + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { { $die_on_fetch, 0 } }; + + my $res = eval { + { $die_on_fetch, 0 } + }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status(_( + "Cannot delete zone $name: sub-zones or appellations exist.")); diff --git a/t/snippets17.t b/t/snippets17.t index 2623786e..73362e4c 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -8,6 +8,8 @@ #5 rperl.rperl #6 wn7.def #7 wn7.wn +#8 wn8.def +#9 wn8.wn # To locate test #13 you can search for its name or the string '#13' @@ -95,6 +97,25 @@ my $subref = sub ( $cat, $id = do { state $auto_id = 0; $auto_id++ } ) { do { 1; !!(my $x = bless []); } ); ---------- + + 'wn8' => <<'----------', + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { { $die_on_fetch, 0 } }; + + my $res = eval { + { $die_on_fetch, 0 } + }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status(_( + "Cannot delete zone $name: sub-zones or appellations exist.")); +---------- }; #################################### @@ -243,6 +264,54 @@ sub foo_subroutine_in_main { f( do { 1; !!( my $x = bless [] ); } ); #7........... }, + + 'wn8.def' => { + source => "wn8", + params => "def", + expect => <<'#8...........', + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { + { $die_on_fetch, 0 } + }; + + my $res = eval { + { $die_on_fetch, 0 } + }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); +#8........... + }, + + 'wn8.wn' => { + source => "wn8", + params => "wn", + expect => <<'#9...........', + # Former -wn blinkers, which oscillated between two states + + # fixed RULE 1 only applies to '(' + my $res = eval { { $die_on_fetch, 0 } }; + + my $res = eval { { $die_on_fetch, 0 } }; + + # fixed RULE 2 applies to any inner opening token + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); + + $app->FORM->{'appbar1'}->set_status( + _("Cannot delete zone $name: sub-zones or appellations exist.") + ); +#9........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5