]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix c093, a minor vertical alignment issue
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Oct 2021 18:14:51 +0000 (11:14 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 24 Oct 2021 18:14:51 +0000 (11:14 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
t/snippets/align32.in
t/snippets/expect/align32.def
t/snippets17.t

index 5ae134bd45a0a31cd3daa61f25e721fa37d72d9c..a154df536ccb0e6edac5220ac3fb2c294f732124 100644 (file)
@@ -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,
       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
 
index 794d5e29d80ed0ba6aa347c3a541dee2be00c94d..ff7c10e9529b8fd45d8ce72aa85c55c46672eab2 100644 (file)
@@ -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] )
             {
index 204be660a428d0f78cae3237329ec77c2c6de51d..df7640b8793aeedc1c8a53ed8d3754f3ce261225 100644 (file)
@@ -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];
+};
index 5e2d791cb3355d6b322673809158d1362ba82260..d386d6709355d20c78f865c86f8ff9085206fdd0 100644 (file)
@@ -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];
+};
index 784c5f41d4df4e673ac2dd28c8178b17020e4957..033da5f9b17710b1c642118a154f085cbcabdb88 100644 (file)
@@ -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...........
         },