From: Steve Hancock Date: Thu, 13 May 2021 15:07:23 +0000 (-0700) Subject: Adjust tolerances for some line length tests X-Git-Tag: 20210402.01~42 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=24a11d3caf30b0af288cda5131ab1ccb29ef7fe0;p=perltidy.git Adjust tolerances for some line length tests --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 1704e69d..5fecb7b3 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 0a6fcc1a..c044d1d9 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,16 @@ =over 4 +=item B + +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 If a container contains text of a here-doc then the indentation is fixed by