From: Steve Hancock Date: Sat, 25 May 2019 13:30:48 +0000 (-0700) Subject: updated -bom to handle cuddled style chain calls X-Git-Tag: 20190601~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3c23aa1f0f013b684ccf52f1a22087c6bdc09c8e;p=perltidy.git updated -bom to handle cuddled style chain calls --- diff --git a/CHANGES.md b/CHANGES.md index a1b68cb9..3d277eb5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,13 @@ ## 2018 11 20.01 + - added option -bom (--break-at-old-method-breakpoints) by + merrillymeredith which preserves breakpoints of method chains + + - merged patch to fix Windows EOL translation error with UTF-8 written by + Ron Ivy. This update prevents automatic conversion to 'DOS' CRLF line + endings. + - RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) to control semicolons in one-line blocks. The values of n are: n=0 means no semicolons termininating simple one-line blocks diff --git a/bin/perltidy b/bin/perltidy index 6dc2034f..c23dad6b 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2460,6 +2460,22 @@ It will B these breaks, rather than become this: 'track.id' => {-ident => 'none_search.id'}, })->as_query; +This flag will also look for and keep a 'cuddled' style of calls, +in which lines begin with a closing paren followed by a call arrow, +as in this example: + + my $q = $rs->related_resultset( + 'CDs' + )->related_resultset( + 'Tracks' + )->search( { + 'track.id' => { -ident => 'none_search.id' }, + } )->as_query; + +You may want to include the B<-weld-nested-containers> flag in this case to keep +nested braces and parens together, as in the last line. + + =item B<-bok>, B<--break-at-old-keyword-breakpoints> By default, perltidy will retain a breakpoint before keywords which may diff --git a/docs/ChangeLog.html b/docs/ChangeLog.html index 3a7b04ff..5b326de0 100644 --- a/docs/ChangeLog.html +++ b/docs/ChangeLog.html @@ -2,7 +2,14 @@

2018 11 20.01

-
- RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) 
+
- added option -bom  (--break-at-old-method-breakpoints) by
+  merrillymeredith which preserves breakpoints of method chains
+
+- merged patch to fix Windows EOL translation error with UTF-8 written by
+  Ron Ivy. This update prevents automatic conversion to 'DOS' CRLF line
+  endings.
+
+- RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) 
   to control semicolons in one-line blocks.  The values of n are:
     n=0 means no semicolons termininating simple one-line blocks
     n=1 means stable; do not change from input file [DEFAULT and current]
diff --git a/docs/perltidy.html b/docs/perltidy.html
index f2f0b873..3785c316 100644
--- a/docs/perltidy.html
+++ b/docs/perltidy.html
@@ -165,7 +165,7 @@
 
-o=filename, --outfile=filename
-

Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output, the output will go to filename.tdy.

+

Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output (see -st), the output will go to filename.tdy. [Note: - does not redirect to standard output. Use -st instead.]

-st, --standard-output
@@ -1927,6 +1927,37 @@

By default, if a logical expression is broken at a &&, ||, and, or or, then the container will remain broken. Also, breaks at internal keywords if and unless will normally be retained. To prevent this, and thus form longer lines, use -nbol.

+ +
-bom, --break-at-old-method-breakpoints
+
+ +

By default, a method call arrow -> is considered a candidate for a breakpoint, but method chains will fill to the line width before a break is considered. With -bom, breaks before the arrow are preserved, so if you have preformatted a method chain:

+ +
  my $q = $rs
+    ->related_resultset('CDs')
+    ->related_resultset('Tracks')
+    ->search({
+      'track.id' => {-ident => 'none_search.id'},
+    })->as_query;
+ +

It will keep these breaks, rather than become this:

+ +
  my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search({
+      'track.id' => {-ident => 'none_search.id'},
+    })->as_query;
+ +

This flag will also look for and keep a 'cuddled' style of calls, in which lines begin with a closing paren followed by a call arrow, as in this example:

+ +
  my $q = $rs->related_resultset(
+      'CDs'
+  )->related_resultset(
+      'Tracks'
+  )->search( {
+      'track.id' => { -ident => 'none_search.id' },
+  } )->as_query;
+ +

You may want to include the -weld-nested-containers flag in this case to keep nested braces and parens together, as in the last line.

+
-bok, --break-at-old-keyword-breakpoints
@@ -2885,25 +2916,25 @@
-
Around line 2693:
+
Around line 2731:

'=item' outside of any '=over'

-
Around line 2881:
+
Around line 2919:

You forgot a '=back' before '=head2'

-
Around line 2939:
+
Around line 2977:

'=item' outside of any '=over'

-
Around line 3020:
+
Around line 3058:

You forgot a '=back' before '=head2'

diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 96194897..f2ab17ee 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -12867,10 +12867,36 @@ sub pad_array_to_go { # remember locations of -> if this is a pre-broken method chain if ( $type eq '->' ) { - set_forced_breakpoint($i - 1) - if ( ( $i == $i_line_start ) - && $rOpts_break_at_old_method_breakpoints ); +## set_forced_breakpoint($i - 1) +## if ( ( $i == $i_line_start ) +## && $rOpts_break_at_old_method_breakpoints ); + if ($rOpts_break_at_old_method_breakpoints) { + + # Case 1: look for lines with leading pointers + if ( $i == $i_line_start ) { + set_forced_breakpoint( $i - 1 ); + } + + # Case 2: look for cuddled pointer calls + else { + + # look for old lines with leading ')->' or ') ->' + # and, when found, force a break before the + # opening paren and previous closing paren. + if ( + $types_to_go[$i_line_start] eq '}' + && ( $i == $i_line_start + 1 + || $i == $i_line_start + 2 + && $types_to_go[ $i - 1 ] eq 'b' ) + ) + { + set_forced_breakpoint( $i_line_start - 1 ); + set_forced_breakpoint($mate_index_to_go[$i_line_start]); + } + } + } } ## end if ( $type eq '->' ) + # remember locations of '||' and '&&' for possible breaks if we # decide this is a long logical expression. elsif ( $type eq '||' ) { diff --git a/t/snippets/bom.par b/t/snippets/bom.par new file mode 100644 index 00000000..f96505b4 --- /dev/null +++ b/t/snippets/bom.par @@ -0,0 +1 @@ +-bom -wn diff --git a/t/snippets/bom1.in b/t/snippets/bom1.in new file mode 100644 index 00000000..e5b0be4d --- /dev/null +++ b/t/snippets/bom1.in @@ -0,0 +1,11 @@ +# keep cuddled call chain with -bom +return Mojo::Promise->resolve( + $query_params +)->then( + &_reveal_event +)->then(sub ($code) { + return $c->render(text => '', status => $code); +})->catch(sub { + # 1. return error + return $c->render(json => {}, status => 400); +}); diff --git a/t/snippets/expect/bom1.bom b/t/snippets/expect/bom1.bom new file mode 100644 index 00000000..69290c4a --- /dev/null +++ b/t/snippets/expect/bom1.bom @@ -0,0 +1,12 @@ +# keep cuddled call chain with -bom +return Mojo::Promise->resolve( + $query_params +)->then( + &_reveal_event +)->then( sub ($code) { + return $c->render( text => '', status => $code ); +} )->catch( sub { + + # 1. return error + return $c->render( json => {}, status => 400 ); +} ); diff --git a/t/snippets/expect/bom1.def b/t/snippets/expect/bom1.def new file mode 100644 index 00000000..152fe33d --- /dev/null +++ b/t/snippets/expect/bom1.def @@ -0,0 +1,11 @@ +# keep cuddled call chain with -bom +return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then( + sub ($code) { + return $c->render( text => '', status => $code ); + } +)->catch( + sub { + # 1. return error + return $c->render( json => {}, status => 400 ); + } +); diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 2fd2c11c..0bf4d911 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -122,6 +122,8 @@ ../snippets15.t olbs.def ../snippets15.t olbs.olbs0 ../snippets15.t olbs.olbs2 +../snippets15.t break_old_methods.break_old_methods +../snippets15.t break_old_methods.def ../snippets2.t angle.def ../snippets2.t arrows1.def ../snippets2.t arrows2.def @@ -282,5 +284,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets15.t break_old_methods.break_old_methods -../snippets15.t break_old_methods.def +../snippets15.t bom1.bom +../snippets15.t bom1.def diff --git a/t/snippets15.t b/t/snippets15.t index 8455c325..68dfef6d 100644 --- a/t/snippets15.t +++ b/t/snippets15.t @@ -8,6 +8,8 @@ #5 olbs.olbs2 #6 break_old_methods.break_old_methods #7 break_old_methods.def +#8 bom1.bom +#9 bom1.def # To locate test #13 you can search for its name or the string '#13' @@ -25,6 +27,7 @@ BEGIN { # BEGIN SECTION 1: Parameter combinations # ########################################### $rparams = { + 'bom' => "-bom -wn", 'break_old_methods' => "--break-at-old-method-breakpoints", 'def' => "", 'gnu' => "-gnu", @@ -37,6 +40,20 @@ BEGIN { ############################ $rsources = { + 'bom1' => <<'----------', +# keep cuddled call chain with -bom +return Mojo::Promise->resolve( + $query_params +)->then( + &_reveal_event +)->then(sub ($code) { + return $c->render(text => '', status => $code); +})->catch(sub { + # 1. return error + return $c->render(json => {}, status => 400); +}); +---------- + 'break_old_methods' => <<'----------', my $q = $rs ->related_resultset('CDs') @@ -195,6 +212,43 @@ my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search( )->as_query; #7........... }, + + 'bom1.bom' => { + source => "bom1", + params => "bom", + expect => <<'#8...........', +# keep cuddled call chain with -bom +return Mojo::Promise->resolve( + $query_params +)->then( + &_reveal_event +)->then( sub ($code) { + return $c->render( text => '', status => $code ); +} )->catch( sub { + + # 1. return error + return $c->render( json => {}, status => 400 ); +} ); +#8........... + }, + + 'bom1.def' => { + source => "bom1", + params => "def", + expect => <<'#9...........', +# keep cuddled call chain with -bom +return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then( + sub ($code) { + return $c->render( text => '', status => $code ); + } +)->catch( + sub { + # 1. return error + return $c->render( json => {}, status => 400 ); + } +); +#9........... + }, }; my $ntests = 0 + keys %{$rtests};