]> git.donarmstrong.com Git - perltidy.git/commitdiff
Adjust tolerances for some line length tests
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 13 May 2021 15:07:23 +0000 (08:07 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 13 May 2021 15:07:23 +0000 (08:07 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 1704e69d846d29ac208155b0056c704178296161..5fecb7b399ea871106401c6d8f5696de46b670f6 100644 (file)
@@ -15347,17 +15347,34 @@ sub set_continuation_breaks {
     my ( @has_broken_sublist, @dont_align, @want_comma_break );
 
     my $length_tol;
+    my $length_tol_multiline_increase;
 
     sub initialize_scan_list {
         @dont_align         = ();
         @has_broken_sublist = ();
         @want_comma_break   = ();
 
-        # Use an increased line length tolerance when -ci > -i
-        # to avoid blinking states (case b923 and others).
+        # Define a tolerance to use a tolerance when checking if closed
+        # containers will fit on one line.  This is necessary to avoid
+        # formatting instability. The basic tolerance is based on the
+        # following:
+
+        # - Always allow for at least one extra space after a closing token so
+        # that we do not strand a comma or semicolon. (oneline.t).
+
+        # - Use an increased line length tolerance when -ci > -i to avoid
+        # blinking states (case b923 and others).
         $length_tol =
           1 + max( 0, $rOpts_continuation_indentation - $rOpts_indent_columns );
 
+        # In addition, use a few characters of extra tolerance for broken lines
+        # when -lp is used to help prevent instability. This is currently only
+        # necessary for -lp which has a more variable indentation.  At least 3
+        # characters have been found to be required.
+        # Fixes cases b1059 b1063 b1117.
+        $length_tol_multiline_increase = 0;
+        if ($rOpts_line_up_parentheses) { $length_tol_multiline_increase = 3 }
+
         return;
     }
 
@@ -16127,15 +16144,22 @@ sub set_continuation_breaks {
                 # mark term as long if the length between opening and closing
                 # parens exceeds allowed line length
                 if ( !$is_long_term && $saw_opening_structure ) {
+
                     my $i_opening_minus =
                       $self->find_token_starting_list($i_opening);
 
-                    # Note: we have to allow for at least one extra space after
-                    # a closing token so that we do not strand a comma or
-                    # semicolon. (oneline.t).
-                    $is_long_term =
-                      $self->excess_line_length( $i_opening_minus, $i ) >
-                      -$length_tol;
+                    my $excess =
+                      $self->excess_line_length( $i_opening_minus, $i );
+
+                    my $tol = $length_tol;
+                    if (   $length_tol_multiline_increase
+                        && $self->[_ris_broken_container_]->{$type_sequence} )
+                    {
+                        $tol += $length_tol_multiline_increase;
+                    }
+
+                    $is_long_term = $excess + $tol > 0;
+
                 } ## end if ( !$is_long_term &&...)
 
                 # We've set breaks after all comma-arrows.  Now we have to
index 0a6fcc1acb0067ddd0ab408379457f956ca7a9ca..c044d1d904a4c5433b8c25b25f9664a36b49d805 100644 (file)
@@ -2,6 +2,16 @@
 
 =over 4
 
+=item B<Adjust tolerances for some line length tests>
+
+Random testing produced some edge cases of unstable formatting involving the -lp
+format.  These were fixed by using a slightly larger tolerance in the length test
+for containers which were broken in the input file.
+
+This fixes cases b1059 b1063 b1117.
+
+13 May 2021.
+
 =item B<Do not apply -lp formatting to containers with here-doc text>
 
 If a container contains text of a here-doc then the indentation is fixed by