]> git.donarmstrong.com Git - perltidy.git/commitdiff
adjust line length and token count tolerances for -wn stability
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 30 Jan 2021 16:03:32 +0000 (08:03 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 30 Jan 2021 16:03:32 +0000 (08:03 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/wn6.def
t/snippets/expect/wn6.wn
t/snippets/expect/wn8.def
t/snippets/expect/wn8.wn
t/snippets/wn6.in
t/snippets/wn8.in
t/snippets12.t
t/snippets18.t

index ca5ff27e61d993b88627b3a8b231c7672d0b7b29..fee112f704601679206f73ef9c5ff46b7fd7c505 100644 (file)
@@ -6653,6 +6653,12 @@ sub weld_nested_containers {
     # line length and gets broken in a bad spot.
     my $length_tol = 1;
 
+    # Sometimes the total starting indentation can increase at a later stage,
+    # for example the -bli command will move an opening brace inward one level
+    # instead of one ci.  To avoid blinkers, we add an extra length tolerance.
+    $length_tol +=
+      abs( $rOpts_indent_columns - $rOpts_continuation_indentation );
+
     my $excess_length_to_K = sub {
         my ($K) = @_;
 
@@ -6698,6 +6704,15 @@ sub weld_nested_containers {
         my $Kouter_closing = $K_closing_container->{$outer_seqno};
         my $Kinner_closing = $K_closing_container->{$inner_seqno};
 
+        # RULE: do not weld if inner container has <= 3 tokens unless the next
+        # token is a heredoc (so we know there will be multiple lines)
+        if ( $Kinner_closing - $Kinner_opening <= 4 ) {
+            my $Knext_nonblank = $self->K_next_nonblank($Kinner_opening);
+            next unless defined($Knext_nonblank);
+            my $type = $rLL->[$Knext_nonblank]->[_TYPE_];
+            next unless ( $type eq 'h' );
+        }
+
         my $outer_opening = $rLL->[$Kouter_opening];
         my $inner_opening = $rLL->[$Kinner_opening];
         my $outer_closing = $rLL->[$Kouter_closing];
@@ -6762,7 +6777,9 @@ sub weld_nested_containers {
             # (1) the containers are all on one line, and
             # (2) the line does not exceed the allowable length, and
             # This flag is used to avoid creating blinkers.
-            if ( $iline_oo == $iline_oc && $excess_length_to_K->($Klast) <= 0 )
+            # For stability, we remove the length tolerance which has been added
+            if (   $iline_oo == $iline_oc
+                && $excess_length_to_K->($Klast) <= $length_tol )
             {
                 $is_one_line_weld = 1;
             }
@@ -7610,7 +7627,7 @@ sub adjust_container_indentation {
         my $min_req = 2;
 
         # But for -boc we want to see a break at an interior list comma to be
-        # sure the list stays broken.  It is sufficient to require at least two 
+        # sure the list stays broken.  It is sufficient to require at least two
         # non-blank lines within the block.
         if ($rOpts_break_at_old_comma_breakpoints) {
             my $iline = $rLL->[$KK]->[_LINE_INDEX_];
index 74721122a6aade29457352988188c0f1e608c50d..16ebd38ae766a380fa9054f79accbdc8df64bb3d 100644 (file)
@@ -2,6 +2,18 @@
 
 =over 4
 
+=item B<adjust line length and token count tolerances for -wn>
+
+Most remaining edge cases of blinking states involving the -wn parameter have
+been fixed by adjusting some tolerances in sub weld_nested_containers.  The
+following cases are fixed with this update:
+
+b156 b157 b186 b196 b454 b520 b527 b530 b532 b533 b534 b612 b614 b625 b627
+
+This update has no effect for realistic parameter settings.
+
+30 Jan 2021.
+
 =item B<fix additional edge blinker cases involving -wn>
 
 Some blinking cases produced in random testing were traced to welding in
@@ -14,7 +26,7 @@ with the update:
 b002 b003 b005 b006 b007 b009 b010 b014 b015 b017 b020 b111 b112 b113 b124 b126
 b128 b151 b153 b439 b606
 
-29 Jan 2021.
+29 Jan 2021, 33f1f2b.
 
 =item B<fix additional edge blinker cases involving -wn>
 
@@ -33,7 +45,7 @@ The following cases were fixed with this update:
 b025 b075 b091 b109 b110 b152 b154 b155 b162 b168 b176 b422 b423 b424 b425 b426
 b565
 
-29 Jan 2021.
+29 Jan 2021, 33f1f2b.
 
 =item B<fix some edge blinker cases involving -wn>
 
@@ -43,7 +55,7 @@ weld_nested_containers.  The following cases were fixed with this update:
 
 b131 b134 b136 b205 b233 b238 b284 b350 b352 b358 b385 b487 b604 b605
 
-29 Jan 2021.
+29 Jan 2021, 33f1f2b.
 
 =item B<fix some edge blinker cases involving -bbxi=n esp. with -boc>
 
index dbfdd3a70c2bf552ba10adb1233808d97a56c84f..7c3fd75999f764d7c346c3a508eaad0ac688f171 100644 (file)
@@ -13,8 +13,9 @@
                 )
             );
 
-      # do not weld to a one-line block because the function could get separated
-      # from its opening paren
+            # OLD: do not weld to a one-line block because the function could
+            # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
             $_[0]->code_handler(
                 sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
index d40ccd563db3aab982477d0bbbb50ad610284b0f..213b2ad8568c0b81d71ef943e2c04ceca1d2fa18 100644 (file)
@@ -9,10 +9,11 @@
                 @{ $coords[0] }, @{ $coords[1] }
             ) ) );
 
-      # do not weld to a one-line block because the function could get separated
-      # from its opening paren
-            $_[0]->code_handler(
-                sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
+            # OLD: do not weld to a one-line block because the function could
+            # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
+            $_[0]->code_handler
+              ( sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
             # another example; do not weld because the sub is not broken
             $wrapped->add_around_modifier(
index 98b4d186ed77bd04541f64999958b9074fcc9a00..9bdccf3960a3cc43883ae88a9f89eacb7ccf67d1 100644 (file)
@@ -15,7 +15,8 @@
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-            # fixed RULE 1: this is now a stable state with -wn
+            # OLD: fixed RULE 1: this is now a stable state with -wn
+            # NEW (30 jan 2021): do not weld if one interior token
             $app->FORM->{'appbar1'}->set_status(
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
index 921d5ec5989de004ba3182dadac39b2dfd3916ba..39e2970b622aacc9de0090d46d00047c6e3cef74 100644 (file)
@@ -11,6 +11,8 @@
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-            # fixed RULE 1: this is now a stable state with -wn
-            $app->FORM->{'appbar1'}->set_status( _(
-                "Cannot delete zone $name: sub-zones or appellations exist.") );
+            # OLD: fixed RULE 1: this is now a stable state with -wn
+            # NEW (30 jan 2021): do not weld if one interior token
+            $app->FORM->{'appbar1'}->set_status(
+                _("Cannot delete zone $name: sub-zones or appellations exist.")
+            );
index 6ca69a57d13d5f97ba447c60234cf669956dc13e..356e7b086344ceaff4611810be84451a15aabdca 100644 (file)
@@ -7,8 +7,9 @@
             my $compass = uc( opposite_direction( line_to_canvas_direction(
                 @{ $coords[0] }, @{ $coords[1] } ) ) );
         
-            # do not weld to a one-line block because the function could get separated
-           # from its opening paren 
+            # OLD: do not weld to a one-line block because the function could
+           # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
             $_[0]->code_handler
                  ( sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
index 3e07557f23b840be7c110c787e18dab29b0a198e..fe642f0b41d61751c45556798687472272ab0ec2 100644 (file)
@@ -13,6 +13,7 @@
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-           # fixed RULE 1: this is now a stable state with -wn
+           # OLD: fixed RULE 1: this is now a stable state with -wn
+           # NEW (30 jan 2021): do not weld if one interior token
             $app->FORM->{'appbar1'}->set_status(_(
                  "Cannot delete zone $name: sub-zones or appellations exist."));
index e36c9b4be6babeacb553b8e3541f3a485127d614..89172f42c71c42799dcdc1ed0994be6e0266d2ae 100644 (file)
@@ -166,8 +166,9 @@ use_all_ok(
             my $compass = uc( opposite_direction( line_to_canvas_direction(
                 @{ $coords[0] }, @{ $coords[1] } ) ) );
         
-            # do not weld to a one-line block because the function could get separated
-           # from its opening paren 
+            # OLD: do not weld to a one-line block because the function could
+           # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
             $_[0]->code_handler
                  ( sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
@@ -512,8 +513,9 @@ use_all_ok( qw{
                 )
             );
 
-      # do not weld to a one-line block because the function could get separated
-      # from its opening paren
+            # OLD: do not weld to a one-line block because the function could
+            # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
             $_[0]->code_handler(
                 sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
@@ -546,10 +548,11 @@ use_all_ok( qw{
                 @{ $coords[0] }, @{ $coords[1] }
             ) ) );
 
-      # do not weld to a one-line block because the function could get separated
-      # from its opening paren
-            $_[0]->code_handler(
-                sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
+            # OLD: do not weld to a one-line block because the function could
+            # get separated from its opening paren.
+            # NEW: (30-jan-2021): keep one-line block together for stability
+            $_[0]->code_handler
+              ( sub { $morexxxxxxxxxxxxxxxxxx .= $_[1] . ":" . $_[0] . "\n" } );
 
             # another example; do not weld because the sub is not broken
             $wrapped->add_around_modifier(
index 15866b91c1f35a9dc775c6d92f62f6e2929cb0b5..5cd0e2eda38224e3e06df7196749ab79844f9af1 100644 (file)
@@ -273,7 +273,8 @@ my ( $a, $b, $c ) = @_;    # test -nsak="my for"
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-           # fixed RULE 1: this is now a stable state with -wn
+           # OLD: fixed RULE 1: this is now a stable state with -wn
+           # NEW (30 jan 2021): do not weld if one interior token
             $app->FORM->{'appbar1'}->set_status(_(
                  "Cannot delete zone $name: sub-zones or appellations exist."));
 ----------
@@ -321,7 +322,8 @@ my ( $a, $b, $c ) = @_;    # test -nsak="my for"
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-            # fixed RULE 1: this is now a stable state with -wn
+            # OLD: fixed RULE 1: this is now a stable state with -wn
+            # NEW (30 jan 2021): do not weld if one interior token
             $app->FORM->{'appbar1'}->set_status(
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
@@ -345,9 +347,11 @@ my ( $a, $b, $c ) = @_;    # test -nsak="my for"
                 _("Cannot delete zone $name: sub-zones or appellations exist.")
             );
 
-            # fixed RULE 1: this is now a stable state with -wn
-            $app->FORM->{'appbar1'}->set_status( _(
-                "Cannot delete zone $name: sub-zones or appellations exist.") );
+            # OLD: fixed RULE 1: this is now a stable state with -wn
+            # NEW (30 jan 2021): do not weld if one interior token
+            $app->FORM->{'appbar1'}->set_status(
+                _("Cannot delete zone $name: sub-zones or appellations exist.")
+            );
 #3...........
         },