From 0b97b9445d39d7da46359b420110643690e33570 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 21 Feb 2021 07:54:23 -0800 Subject: [PATCH] Add tolerance to one-line block length tests --- lib/Perl/Tidy/Formatter.pm | 16 +++++++++++++++- local-docs/BugLog.pod | 13 ++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index ec34c960..d7ea25de 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -10273,6 +10273,14 @@ sub starting_one_line_block { return 0; } + # TESTING: Patch to leave this block broken if it contains a broken + # sub-container. This patch fixes cases b069 b070 b077 b078. It improved + # coding in most cases but there are still a few issues so it was not + # implemented. + ##if ( $self->[_rhas_broken_container_]->{$type_sequence} ) { + ## return 0; + ##} + my $ris_bli_container = $self->[_ris_bli_container_]; my $is_bli = $ris_bli_container->{$type_sequence}; @@ -10380,8 +10388,14 @@ sub starting_one_line_block { my $pos = total_line_length( $i_start, $max_index_to_go ) - 1; + # Use a small tolerence in the length test to avoid blinking states. + # This patch fixes cases b069 b070 b077 b078. See comments above for + # another way to fix these cases. We would need at least 2 spaces if + # this is going to be an empty block, like '{ }' + my $tol = 2; + # see if length is too long to even start - if ( $pos > $maximum_line_length[ $levels_to_go[$i_start] ] ) { + if ( $pos + $tol > $maximum_line_length[ $levels_to_go[$i_start] ] ) { return 1; } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 940aa7ed..ae680a67 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,17 @@ =over 4 +=item B + +Testing with random input parameters produced some cases in which a stable +solution could not be found due to attempts to form one-line blocks near the +end of a long line. The problem was fixed by adding a small tolerance to the +line length test. This does not change existing formatting. + +This fixes cases b069 b070 b077 b078. + +21 Feb 2021 + =item B The -bom flag tries to keep old breakpoints at lines beginning with '->' and @@ -12,7 +23,7 @@ and closing parens should be more than 1. This fixes case b977. -21 Feb 2021 +21 Feb 2021, 28114e9. =item B -- 2.39.5