]> git.donarmstrong.com Git - perltidy.git/commitdiff
Add tolerance to one-line block length tests
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 21 Feb 2021 15:54:23 +0000 (07:54 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 21 Feb 2021 15:54:23 +0000 (07:54 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index ec34c960f165b22e51e0843ca1d3b2e8dabd4e04..d7ea25dec31bece83354be87b8f7f13acc0ce763 100644 (file)
@@ -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;
     }
 
index 940aa7edf486342b3c7b67760d93356f4d394acd..ae680a673a0db608e82027048da0928b7a73724f 100644 (file)
@@ -2,6 +2,17 @@
 
 =over 4
 
+=item B<Add tolerance to one-line block length tests>
+
+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<Restrict -bom at cuddled method calls>
 
 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<Add weld rule to avoid conflict between -wn and -bom>