From e82a3183c0c938c4b2a3b1376469d08d5d6d1230 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 24 Oct 2021 11:14:51 -0700 Subject: [PATCH] fix c093, a minor vertical alignment issue --- CHANGES.md | 57 ++++++++++++++++++++++++----------- lib/Perl/Tidy/Formatter.pm | 8 ++++- t/snippets/align32.in | 6 ++++ t/snippets/expect/align32.def | 6 ++++ t/snippets17.t | 12 ++++++++ 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5ae134bd..a154df53 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,44 @@ ## 2021 07 17.04 + - No significant bugs have been found since the last release, but several + minor issues have been fixed. Vertical alignment has been improved for + lists of call args which are not contained within parens (next item). + + - Vertical alignment of function calls without parens has been improved with + the goal of making vertical alignment the essentially the same with or + without parens around the call args. Some examples: + + # OLD + mkTextConfig $c, $x, $y, -anchor => 'se', $color; + mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; + mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; + mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; + + # NEW + mkTextConfig $c, $x, $y, -anchor => 'se', $color; + mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; + mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; + mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; + + # OLD + is id_2obj($id), undef, "unregistered object not retrieved"; + is scalar keys %$ob_reg, 0, "object registry empty"; + is register($obj), $obj, "object returned by register"; + is scalar keys %$ob_reg, 1, "object registry nonempty"; + is id_2obj($id), $obj, "registered object retrieved"; + + # NEW + is id_2obj($id), undef, "unregistered object not retrieved"; + is scalar keys %$ob_reg, 0, "object registry empty"; + is register($obj), $obj, "object returned by register"; + is scalar keys %$ob_reg, 1, "object registry nonempty"; + is id_2obj($id), $obj, "registered object retrieved"; + + This will cause some changes in alignment, hopefully for the better, + particularly in test code which often uses numerous parenless function + calls with functions like 'ok', 'is', 'is_deeply', .... + - Two new parameters were added to control the block types to which the -bl (--opening-brace-on-new-line) flag applies. The new parameters are -block-left-list=s, or -bll=s, and --block-left-exclusion-list=s, @@ -33,28 +71,13 @@ comment, '#>>V', can be lost. A workaround for the previous version is to include the parameter '-mbl=2'. - - Vertical alignment of function calls without parens has been improved and - in many cases is closer to what alignment would be if parens had been used. - - # OLD - mkTextConfig $c, $x, $y, -anchor => 'se', $color; - mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; - mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; - mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; - - # NEW - mkTextConfig $c, $x, $y, -anchor => 'se', $color; - mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; - mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; - mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; - - This version runs 10 to 15 percent faster on large files than the previous release due to optimizations made with the help of NYTProf. - Numerous minor fixes have been made, mostly very rare formatting instabilities found in random testing. An effort has been made to minimize changes to - existing formatting, but some changes will invariably occur. Many of these - updates are listed at: + existing formatting that these fixes produce, but occasional changes + may occur. Many of these updates are listed at: https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 794d5e29..ff7c10e9 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -22066,8 +22066,14 @@ sub pad_token { if ( $types_to_go[$iterm] eq '#' ) { $iterm = $iprev_to_go[$iterm]; } + + # Alignment lines ending like '=> sub {'; fixes issue c093 + my $term_type_ok = $types_to_go[$iterm] eq ';'; + $term_type_ok ||= + $tokens_to_go[$iterm] eq '{' && $block_type_to_go[$iterm]; + if ( $iterm > $ibeg - && $types_to_go[$iterm] eq ';' + && $term_type_ok && !$is_my_local_our{ $tokens_to_go[$ibeg] } && $levels_to_go[$ibeg] eq $levels_to_go[$iterm] ) { diff --git a/t/snippets/align32.in b/t/snippets/align32.in index 204be660..df7640b8 100644 --- a/t/snippets/align32.in +++ b/t/snippets/align32.in @@ -13,3 +13,9 @@ permute_test [ 'a', 'b', 'c' ], '/', '/', [ 'a', 'b', 'c' ]; permute_test [ 'a,', 'b', 'c,' ], '/', '/', [ 'a,', 'b', 'c,' ]; permute_test [ 'a', ',', '#', 'c' ], '/', '/', [ 'a', ',', '#', 'c' ]; permute_test [ 'f_oo', 'b_ar' ], '/', '/', [ 'f_oo', 'b_ar' ]; + +# issue c093 - broken sub, but align fat commas +use constant UNDEF_ONLY => sub { not defined $_[0] }; +use constant EMPTY_OR_UNDEF => sub { + !@_ or @_ == 1 && !defined $_[0]; +}; diff --git a/t/snippets/expect/align32.def b/t/snippets/expect/align32.def index 5e2d791c..d386d670 100644 --- a/t/snippets/expect/align32.def +++ b/t/snippets/expect/align32.def @@ -13,3 +13,9 @@ permute_test [ 'a', 'b', 'c' ], '/', '/', [ 'a', 'b', 'c' ]; permute_test [ 'a,', 'b', 'c,' ], '/', '/', [ 'a,', 'b', 'c,' ]; permute_test [ 'a', ',', '#', 'c' ], '/', '/', [ 'a', ',', '#', 'c' ]; permute_test [ 'f_oo', 'b_ar' ], '/', '/', [ 'f_oo', 'b_ar' ]; + +# issue c093 - broken sub, but align fat commas +use constant UNDEF_ONLY => sub { not defined $_[0] }; +use constant EMPTY_OR_UNDEF => sub { + !@_ or @_ == 1 && !defined $_[0]; +}; diff --git a/t/snippets17.t b/t/snippets17.t index 784c5f41..033da5f9 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -91,6 +91,12 @@ permute_test [ 'a', 'b', 'c' ], '/', '/', [ 'a', 'b', 'c' ]; permute_test [ 'a,', 'b', 'c,' ], '/', '/', [ 'a,', 'b', 'c,' ]; permute_test [ 'a', ',', '#', 'c' ], '/', '/', [ 'a', ',', '#', 'c' ]; permute_test [ 'f_oo', 'b_ar' ], '/', '/', [ 'f_oo', 'b_ar' ]; + +# issue c093 - broken sub, but align fat commas +use constant UNDEF_ONLY => sub { not defined $_[0] }; +use constant EMPTY_OR_UNDEF => sub { + !@_ or @_ == 1 && !defined $_[0]; +}; ---------- 'bos' => <<'----------', @@ -340,6 +346,12 @@ permute_test [ 'a', 'b', 'c' ], '/', '/', [ 'a', 'b', 'c' ]; permute_test [ 'a,', 'b', 'c,' ], '/', '/', [ 'a,', 'b', 'c,' ]; permute_test [ 'a', ',', '#', 'c' ], '/', '/', [ 'a', ',', '#', 'c' ]; permute_test [ 'f_oo', 'b_ar' ], '/', '/', [ 'f_oo', 'b_ar' ]; + +# issue c093 - broken sub, but align fat commas +use constant UNDEF_ONLY => sub { not defined $_[0] }; +use constant EMPTY_OR_UNDEF => sub { + !@_ or @_ == 1 && !defined $_[0]; +}; #1........... }, -- 2.39.5