From: Steve Hancock Date: Tue, 7 Jan 2020 01:15:16 +0000 (-0800) Subject: added flag -olbn to control breaking nested one-line blocks X-Git-Tag: 20200110~2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=eb012fac3594cbbbb093d2f10c47e6307c8ad2ee;p=perltidy.git added flag -olbn to control breaking nested one-line blocks --- diff --git a/CHANGES.md b/CHANGES.md index 0f8d4d7f..d65ea3e9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,9 +2,24 @@ ## 2019 12 03.01 + - Added a flag to control the feature RT#130394, allow short nested blocks, + introduced in the previous release. This feature breaks existing RPerl + installations, so a control flag has been introduced and the feature is + off by default. The flag is: + + --one-line-block-nesting=i, or -olbn=i, where: + + -olbn=0 do not allow nested one-line blocks [DEFAULT] + -olbn=1 allow nested-one line blocks + - Fixed issue RT#131288: parse error for un-prototyped constant function followed by ternary. + - Fixed issue RT#131360, installation documentation. Metacpan generates + instructions for the perltidy binary which are incorrect. The binary + comes with Perl::Tidy. They can both be installed with 'cpanm Perl::Tidy' + + ## 2019 12 03 - Fixed issue RT#131115: -bli option not working correctly. diff --git a/bin/perltidy b/bin/perltidy index a858927c..e3bd70d1 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3085,7 +3085,6 @@ the result is This shows that blocks with a single statement become one-line blocks. - =item B<-olbs=n>, B<--one-line-block-semicolons=n> This flag controls the placement of semicolons at the end of one-line blocks. @@ -3104,6 +3103,29 @@ all one-line blocks, regardless of complexity, the B option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses. +=item B<-olbn=n>, B<--one-line-block-nesting=n> + +One-line blocks which themselves contain code blocks will normally be broken +into multiple lines. This behavior can be controlled with this flag. The +values of n are: + + n=0 do not allow nested one-line blocks [DEFAULT] + n=1 stable: keep existing nested-one line blocks + +For example, given the following line: + + sub nospacesplit { map { /^\s*$/ ? () : $_ } split $_[0], $_[1] } + + +the default behavior (B<-olbn=0>) is to break it into multiple lines: + + sub nospacesplit { + map { /^\s*$/ ? () : $_ } split $_[0], $_[1]; + } + +The line will be left intact with B<-olbn=1>. + + =back @@ -3805,6 +3827,10 @@ detected in any single file will produce this type of exit condition. perlstyle(1), Perl::Tidy(3) +=head1 INSTALLATION + +The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. On many systems, the command 'cpanm Perl::Tidy' will install them. + =head1 VERSION This man page documents perltidy version 20191203.01 diff --git a/docs/ChangeLog.html b/docs/ChangeLog.html index c01fc67c..a9971b38 100644 --- a/docs/ChangeLog.html +++ b/docs/ChangeLog.html @@ -1,5 +1,25 @@

Perltidy Change Log

+

2019 12 03.01

+ +
- Added a flag to control the feature RT#130394, allow short nested blocks,
+  introduced in the previous release.  This feature breaks existing RPerl
+  installations, so a control flag has been introduced and the feature is
+  off by default.  The flag is:
+
+  --one-line-block-nesting=i, or -olbn=i, where: 
+
+  -olbn=0 do not allow nested one-line blocks [DEFAULT]
+  -olbn=1 allow nested-one line blocks
+
+- Fixed issue RT#131288: parse error for un-prototyped constant function
+  followed by ternary.
+
+- Fixed issue RT#131360, installation documentation.  Metacpan generates
+  instructions for the perltidy binary which are incorrect. The binary
+  comes with Perl::Tidy. They can both be installed with 'cpanm Perl::Tidy'
+
+

2019 12 03

- Fixed issue RT#131115: -bli option not working correctly.
diff --git a/docs/Tidy.html b/docs/Tidy.html
index 562960e6..93fc0155 100644
--- a/docs/Tidy.html
+++ b/docs/Tidy.html
@@ -20,6 +20,7 @@
   
  • EXAMPLES
  • Using the formatter Callback Object
  • EXPORT
  • +
  • INSTALLATION
  • VERSION
  • LICENSE
  • BUG REPORTS
  • @@ -351,9 +352,13 @@
      &perltidy
    +

    INSTALLATION

    + +

    On many systems, the command 'cpanm Perl::Tidy' will install both the module Perl::Tidy and a binary perltidy.

    +

    VERSION

    -

    This man page documents Perl::Tidy version 20191203

    +

    This man page documents Perl::Tidy version 20191203.01

    LICENSE

    diff --git a/docs/perltidy.html b/docs/perltidy.html index 0dd1af27..8edae50b 100644 --- a/docs/perltidy.html +++ b/docs/perltidy.html @@ -49,6 +49,7 @@
  • FILES
  • ERROR HANDLING
  • SEE ALSO
  • +
  • INSTALLATION
  • VERSION
  • BUG REPORTS
  • COPYRIGHT
  • @@ -2440,6 +2441,27 @@

    Note that the n=2 option has no effect if adding semicolons is prohibited with the -nasc flag. Also not that while n=2 adds missing semicolons to all one-line blocks, regardless of complexity, the n=0 option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.

    + +
    -olbn=n, --one-line-block-nesting=n
    +
    + +

    One-line blocks which themselves contain code blocks will normally be broken into multiple lines. This behavior can be controlled with this flag. The values of n are:

    + +
      n=0 do not allow nested one-line blocks [DEFAULT]
    +  n=1 stable: keep existing nested-one line blocks
    + +

    For example, given the following line:

    + +
        sub nospacesplit { map { /^\s*$/ ? () : $_ } split $_[0], $_[1] }
    + +

    the default behavior (-olbn=0) is to break it into multiple lines:

    + +
        sub nospacesplit {
    +        map { /^\s*$/ ? () : $_ } split $_[0], $_[1];
    +    }
    + +

    The line will be left intact with -olbn=1.

    +
    @@ -2928,9 +2950,13 @@

    perlstyle(1), Perl::Tidy(3)

    +

    INSTALLATION

    + +

    The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. On many systems, the command 'cpanm Perl::Tidy' will install them.

    +

    VERSION

    -

    This man page documents perltidy version 20191203

    +

    This man page documents perltidy version 20191203.01

    BUG REPORTS

    diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index a107d08b..05dcebb9 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1178,7 +1178,7 @@ EOM # stop iterations if errors or converged my $stop_now = $tokenizer->report_tokenization_errors(); - $stop_now ||= $tokenizer->get_unexpected_error_count(); + $stop_now ||= $tokenizer->get_unexpected_error_count(); if ($stop_now) { $convergence_log_message = <( 'break-before-all-operators', 'bbao', '!' ); $add_option->( 'keep-interior-semicolons', 'kis', '!' ); $add_option->( 'one-line-block-semicolons', 'olbs', '=i' ); + $add_option->( 'one-line-block-nesting', 'olbn', '=i' ); ######################################## $category = 6; # Controlling list formatting @@ -2108,6 +2109,7 @@ sub generate_options { nowarning-output character-encoding=none one-line-block-semicolons=1 + one-line-block-nesting=0 outdent-labels outdent-long-quotes outdent-long-comments diff --git a/lib/Perl/Tidy.pod b/lib/Perl/Tidy.pod index 1e5003d9..a98ba8dd 100644 --- a/lib/Perl/Tidy.pod +++ b/lib/Perl/Tidy.pod @@ -412,6 +412,11 @@ C in Tidy.pm. &perltidy +=head1 INSTALLATION + +On many systems, the command 'cpanm Perl::Tidy' will install both the module Perl::Tidy and a binary perltidy. + + =head1 VERSION This man page documents Perl::Tidy version 20191203.01 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e5946c03..3519412e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3690,6 +3690,8 @@ sub mark_short_nested_blocks { my $rLL = $self->{rLL}; return unless ( defined($rLL) && @{$rLL} ); + return unless ( $rOpts->{'one-line-block-nesting'} ); + my $K_opening_container = $self->{K_opening_container}; my $K_closing_container = $self->{K_closing_container}; my $rbreak_container = $self->{rbreak_container}; @@ -11471,8 +11473,8 @@ sub mate_index_to_go { sub K_mate_index { - # Given the index K of an opening or closing container, or ?/: ternary pair, - # return the index K of the other member of the pair. + # Given the index K of an opening or closing container, or ?/: ternary pair, + # return the index K of the other member of the pair. my ( $self, $K ) = @_; return unless defined($K); my $rLL = $self->{rLL}; @@ -15426,6 +15428,7 @@ sub sync_token_K { else { # shouldn't happen } + return; } { # begin recombine_breakpoints diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 3f931966..561d6a6b 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -2100,9 +2100,9 @@ sub my_flush { elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact ) { # There are no matching tokens, so now check side comments. - # Programming note: accessing arrays with index -1 is - # risky in Perl, but we have verified there is at least one - # line in the group and that there is at least one field. + # Programming note: accessing arrays with index -1 is + # risky in Perl, but we have verified there is at least one + # line in the group and that there is at least one field. my $prev_comment = $group_lines[-1]->get_rfields()->[-1]; my $side_comment = $new_line->get_rfields()->[-1]; my_flush_code() unless ( $side_comment && $prev_comment ); diff --git a/t/snippets/expect/rt130394.def b/t/snippets/expect/rt130394.def index 62b95362..7c27c33f 100644 --- a/t/snippets/expect/rt130394.def +++ b/t/snippets/expect/rt130394.def @@ -1,2 +1,4 @@ -# rt130394: keep on one line -$factorial = sub { reduce { $a * $b } 1 .. 11 }; +# rt130394: keep on one line with -olbn=1 +$factorial = sub { + reduce { $a * $b } 1 .. 11; +}; diff --git a/t/snippets/expect/rt130394.rt130394 b/t/snippets/expect/rt130394.rt130394 new file mode 100644 index 00000000..c48c8f5b --- /dev/null +++ b/t/snippets/expect/rt130394.rt130394 @@ -0,0 +1,2 @@ +# rt130394: keep on one line with -olbn=1 +$factorial = sub { reduce { $a * $b } 1 .. 11 }; diff --git a/t/snippets/expect/rt94338.def b/t/snippets/expect/rt94338.def index e29b4264..b6eaedce 100644 --- a/t/snippets/expect/rt94338.def +++ b/t/snippets/expect/rt94338.def @@ -1,2 +1,6 @@ # for-loop in a parenthesized block-map triggered an error message -map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) ); +map( { + foreach my $item ( '0', '1' ) { + print $item; + } +} qw(a b c) ); diff --git a/t/snippets/expect/side_comments1.def b/t/snippets/expect/side_comments1.def index ed598aa9..8bf131af 100644 --- a/t/snippets/expect/side_comments1.def +++ b/t/snippets/expect/side_comments1.def @@ -3,10 +3,7 @@ { { { - { - ${msg} = "Hello World!"; - print "My message: ${msg}\n"; - } + { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4 } # end level 3 } # end level 2 diff --git a/t/snippets/expect/smart.def b/t/snippets/expect/smart.def index 0e2c0a4f..d0278562 100644 --- a/t/snippets/expect/smart.def +++ b/t/snippets/expect/smart.def @@ -34,7 +34,9 @@ b_const ~~ a_const; { 1 => 2 } ~~ { 2 => 3 }; { 2 => 3 } ~~ { 1 => 2 }; \%main:: ~~ { map { $_ => 'x' } keys %main:: }; -{ map { $_ => 'x' } keys %main:: } +{ + map { $_ => 'x' } keys %main:: +} ~~ \%main::; \%hash ~~ \%tied_hash; \%tied_hash ~~ \%hash; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 690938da..a2716b10 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -312,3 +312,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets16.t rt130394.rt130394 diff --git a/t/snippets/rt130394.in b/t/snippets/rt130394.in index 62b95362..c48c8f5b 100644 --- a/t/snippets/rt130394.in +++ b/t/snippets/rt130394.in @@ -1,2 +1,2 @@ -# rt130394: keep on one line +# rt130394: keep on one line with -olbn=1 $factorial = sub { reduce { $a * $b } 1 .. 11 }; diff --git a/t/snippets/rt130394.par b/t/snippets/rt130394.par new file mode 100644 index 00000000..d7b923ac --- /dev/null +++ b/t/snippets/rt130394.par @@ -0,0 +1 @@ +-olbn=1 diff --git a/t/snippets10.t b/t/snippets10.t index 143f6d8f..2bda303f 100644 --- a/t/snippets10.t +++ b/t/snippets10.t @@ -427,10 +427,7 @@ sub arrange_topframe { { { { - { - ${msg} = "Hello World!"; - print "My message: ${msg}\n"; - } + { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4 } # end level 3 } # end level 2 @@ -532,7 +529,9 @@ b_const ~~ a_const; { 1 => 2 } ~~ { 2 => 3 }; { 2 => 3 } ~~ { 1 => 2 }; \%main:: ~~ { map { $_ => 'x' } keys %main:: }; -{ map { $_ => 'x' } keys %main:: } +{ + map { $_ => 'x' } keys %main:: +} ~~ \%main::; \%hash ~~ \%tied_hash; \%tied_hash ~~ \%hash; diff --git a/t/snippets16.t b/t/snippets16.t index 3377c69a..50c33172 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -17,6 +17,7 @@ #14 ndsm1.def #15 ndsm1.ndsm #16 rt131288.def +#17 rt130394.rt130394 # To locate test #13 you can search for its name or the string '#13' @@ -37,6 +38,7 @@ BEGIN { 'def' => "", 'git10' => "-wn -ce -cbl=sort,map,grep", 'ndsm' => "-ndsm", + 'rt130394' => "-olbn=1", 'rt131115' => "-bli", 'spp1' => "-spp=1", 'spp2' => "-spp=2", @@ -115,7 +117,7 @@ sub Numerically {$a <=> $b}; # trapped semicolon ---------- 'rt130394' => <<'----------', -# rt130394: keep on one line +# rt130394: keep on one line with -olbn=1 $factorial = sub { reduce { $a * $b } 1 .. 11 }; ---------- @@ -273,8 +275,10 @@ sub head { source => "rt130394", params => "def", expect => <<'#11...........', -# rt130394: keep on one line -$factorial = sub { reduce { $a * $b } 1 .. 11 }; +# rt130394: keep on one line with -olbn=1 +$factorial = sub { + reduce { $a * $b } 1 .. 11; +}; #11........... }, @@ -355,6 +359,15 @@ $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage', 'usage: ' . $usage . "\n"; #16........... }, + + 'rt130394.rt130394' => { + source => "rt130394", + params => "rt130394", + expect => <<'#17...........', +# rt130394: keep on one line with -olbn=1 +$factorial = sub { reduce { $a * $b } 1 .. 11 }; +#17........... + }, }; my $ntests = 0 + keys %{$rtests}; diff --git a/t/snippets9.t b/t/snippets9.t index aba445bf..734ca624 100644 --- a/t/snippets9.t +++ b/t/snippets9.t @@ -350,7 +350,11 @@ else { 3; } params => "def", expect => <<'#13...........', # for-loop in a parenthesized block-map triggered an error message -map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) ); +map( { + foreach my $item ( '0', '1' ) { + print $item; + } +} qw(a b c) ); #13........... },