From cae1764ba79b77ab32cb96e4369f1163510dab4c Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 10 Aug 2024 09:01:13 -0700 Subject: [PATCH] updates for git #159 --- bin/perltidy | 26 ++++++++++++++------- lib/Perl/Tidy/Formatter.pm | 12 ++++++---- t/snippets/expect/git159.def | 6 +++++ t/snippets/expect/git159.git159 | 7 ++++++ t/snippets/git159.in | 7 ++++++ t/snippets/git159.par | 1 + t/snippets/packing_list.txt | 4 +++- t/snippets30.t | 40 +++++++++++++++++++++++++++++++++ 8 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 t/snippets/expect/git159.def create mode 100644 t/snippets/expect/git159.git159 create mode 100644 t/snippets/git159.in create mode 100644 t/snippets/git159.par diff --git a/bin/perltidy b/bin/perltidy index 44f7cc6c..4ea7cba9 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2657,13 +2657,17 @@ the default settings B<-bll='*'> and B<-blxl='sort map grep eval asub'> mean all blocks except B and anonymous sub blocks. Note that the lists B<-bll=s> and B<-blxl=s> control the behavior of the -B<-bl> flag but have no effect unless the B<-bl> flag is set. +B<-bl> flag but have no effect unless the B<-bl> flag is set. These +two lists provide complete control for this flag, but two shortcut +flags are available and described in the next sections. =item B<-sbl>, B<--opening-sub-brace-on-new-line> -The flag B<-sbl> provides a shortcut way to turn on B<-bl> just for named -subs. The same effect can be achieved by turning on B<-bl> -with the block list set as B<-bll='sub'>. +The flag B<-sbl> provides a shortcut way to turn on B<-bl> just for named subs. +The same effect can be achieved by turning on B<-bl> with the block list set as +B<-bll='sub'>. To avoid conflicts, it is recommended to either use the more +general list method described above to control B<-bl>, or this shortcut method, +but not both. For example, @@ -2681,12 +2685,17 @@ produces this result: } } -This flag is negated with B<-nsbl>, which is the default. +This negative version of this flag, B<-nsbl>, turns off B<-bl> for +named subs. The same effect can be achieved with the exclusion +list method, B<-blxl=sub>. =item B<-asbl>, B<--opening-anonymous-sub-brace-on-new-line> -The flag B<-asbl> is like the B<-sbl> flag except that it applies -to anonymous sub's instead of named subs. For example +The flag B<-asbl> is like the B<-sbl> flag except that it applies to anonymous +sub's instead of named subs. The same effect can be achieved by turning on +B<-bl> with the block list set to include B<-bll='asub'>. + +For example perltidy -asbl @@ -2702,7 +2711,8 @@ produces this result: } }; -This flag is negated with B<-nasbl>, and the default is B<-nasbl>. +This negative version of this flag, B<-nasbl>, turns off B<-bl> for +anonymous subs. =item B<-bli>, B<--brace-left-and-indent> diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 3be3fc83..0cea196c 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5860,10 +5860,14 @@ sub make_bl_pattern { # for -bl, a list with '*' turns on -sbl and -asbl if ( $bl_pattern =~ /\.\*/ ) { - $rOpts->{'opening-sub-brace-on-new-line'} ||= - $rOpts->{'opening-brace-on-new-line'}; - $rOpts->{'opening-anonymous-sub-brace-on-new-line'} ||= - $rOpts->{'opening-anonymous-brace-on-new-line'}; + if ( !defined( $rOpts->{'opening-sub-brace-on-new-line'} ) ) { + $rOpts->{'opening-sub-brace-on-new-line'} = + $rOpts->{'opening-brace-on-new-line'}; + } + if ( !defined( $rOpts->{'opening-anonymous-sub-brace-on-new-line'} ) ) { + $rOpts->{'opening-anonymous-sub-brace-on-new-line'} = + $rOpts->{'opening-anonymous-brace-on-new-line'}; + } } if ( defined( $rOpts->{'brace-left-exclusion-list'} ) diff --git a/t/snippets/expect/git159.def b/t/snippets/expect/git159.def new file mode 100644 index 00000000..e1dbbeac --- /dev/null +++ b/t/snippets/expect/git159.def @@ -0,0 +1,6 @@ +sub example { + my $ex = 0; + if ($ex) { + print "yay\n"; + } +} diff --git a/t/snippets/expect/git159.git159 b/t/snippets/expect/git159.git159 new file mode 100644 index 00000000..24400499 --- /dev/null +++ b/t/snippets/expect/git159.git159 @@ -0,0 +1,7 @@ +sub example { + my $ex = 0; + if ($ex) + { + print "yay\n"; + } +} diff --git a/t/snippets/git159.in b/t/snippets/git159.in new file mode 100644 index 00000000..24400499 --- /dev/null +++ b/t/snippets/git159.in @@ -0,0 +1,7 @@ +sub example { + my $ex = 0; + if ($ex) + { + print "yay\n"; + } +} diff --git a/t/snippets/git159.par b/t/snippets/git159.par new file mode 100644 index 00000000..bd7dfffc --- /dev/null +++ b/t/snippets/git159.par @@ -0,0 +1 @@ +-bl -nsbl diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 2636797b..958b8746 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -453,6 +453,7 @@ ../snippets30.t dltc.dltc1 ../snippets30.t dltc.dltc2 ../snippets30.t logical_xor.def +../snippets30.t csc.csc3 ../snippets4.t gnu1.gnu ../snippets4.t gnu2.def ../snippets4.t gnu2.gnu @@ -573,4 +574,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets30.t csc.csc3 +../snippets30.t git159.def +../snippets30.t git159.git159 diff --git a/t/snippets30.t b/t/snippets30.t index ea2307ce..81d94526 100644 --- a/t/snippets30.t +++ b/t/snippets30.t @@ -13,6 +13,8 @@ #10 dltc.dltc2 #11 logical_xor.def #12 csc.csc3 +#13 git159.def +#14 git159.git159 # To locate test #13 you can search for its name or the string '#13' @@ -43,6 +45,7 @@ BEGIN { ---unknown-future-option ---wtc=h ---------- + 'git159' => "-bl -nsbl", }; ############################ @@ -109,6 +112,16 @@ $self->make_grammar( ); ---------- + 'git159' => <<'----------', +sub example { + my $ex = 0; + if ($ex) + { + print "yay\n"; + } +} +---------- + 'logical_xor' => <<'----------', $x^^$y and say "One of x or y is true, but not both"; ---------- @@ -288,6 +301,33 @@ $x ^^ $y and say "One of x or y is true, but not both"; }; ## end $message = sub #12........... }, + + 'git159.def' => { + source => "git159", + params => "def", + expect => <<'#13...........', +sub example { + my $ex = 0; + if ($ex) { + print "yay\n"; + } +} +#13........... + }, + + 'git159.git159' => { + source => "git159", + params => "git159", + expect => <<'#14...........', +sub example { + my $ex = 0; + if ($ex) + { + print "yay\n"; + } +} +#14........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5