From: Steve Hancock Date: Sat, 17 Jul 2021 01:45:04 +0000 (-0700) Subject: Fix to make -wn and -bbxx=n flags work together X-Git-Tag: 20210717~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c71f882357391d58ceb46f92b8d2dbc591ebdbb6;p=perltidy.git Fix to make -wn and -bbxx=n flags work together --- diff --git a/CHANGES.md b/CHANGES.md index 45d6a1fb..fa8ba4fa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,8 +17,8 @@ - A warning will no longer be given if a script has an opening code-skipping comment '#<>V'. This - makes code-skipping and format-skipping behave in a similar way: a - '#>>V' or '#>>>' comment without a corresponding closing comment will cause + makes code-skipping and format-skipping behave in a similar way: an + opening comment without a corresponding closing comment will cause the rest of a file to be skipped. If there is a question about which lines are skipped, a .LOG file can be produced with the -g flag and it will have this information. @@ -29,6 +29,9 @@ This limit had been placed to avoid some formatting instabilities, but recent coding improvements allow the limit to be removed. + - The -wn and -bbxx=n flags were not working together correctly. This has + been fixed. + - Numerous minor fixes have been made. A complete list is at: https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod diff --git a/dev-bin/run_convergence_tests.pl b/dev-bin/run_convergence_tests.pl index 471040a1..6258f242 100755 --- a/dev-bin/run_convergence_tests.pl +++ b/dev-bin/run_convergence_tests.pl @@ -9,7 +9,7 @@ my $usage = < b1173.in <== +# problem caused by -wn and -bbhbi not working together + +# S1 + my $two = + $CLASS + ->new( + facet_data => + { hubs => [ { + details => +"DO NOT SHOW" + } ], + } + ); + +# S2 + + my $two = + $CLASS + ->new( + facet_data => + { hubs => + [ + { details => +"DO NOT SHOW" + } + ], + } + ); + +==> b1173.par <== +--break-before-hash-brace-and-indent=1 +--break-before-hash-brace=2 +--break-before-square-bracket=2 +--continuation-indentation=5 +--indent-columns=3 +--maximum-line-length=16 +--variable-maximum-line-length +--vertical-tightness=2 +--weld-nested-containers + ==> b120.in <== # Same as bug96 # State 1 diff --git a/docs/BugLog.html b/docs/BugLog.html index c382cffa..8af72619 100644 --- a/docs/BugLog.html +++ b/docs/BugLog.html @@ -26,6 +26,62 @@
+
Fix to make -wn and -bbxx=n flags work together
+
+ +

Testing with random parameters produced some cases where the combination of -wn and various -bbxx=n flags were not working together. To illustrate, consider the following script (-sil=1 just means start at 1 indentation level)

+ +
    # perltidy -sil=1
+    $$d{"day_name"} = [
+        [
+            "lundi",    "mardi",  "mercredi", "jeudi",
+            "vendredi", "samedi", "dimanche"
+        ]
+    ];
+ +

With welding we get:

+ +
    # -sil=1 -wn
+    $$d{"day_name"} = [ [
+        "lundi",    "mardi",  "mercredi", "jeudi",
+        "vendredi", "samedi", "dimanche"
+    ] ];
+ +

With -bbsb=3 (--break-before-square-brackets) we get:

+ +
    # -sil=1 -bbsb=3
+    $$d{"day_name"} =
+      [
+        [
+            "lundi",    "mardi",  "mercredi", "jeudi",
+            "vendredi", "samedi", "dimanche"
+        ]
+      ];
+ +

So far, so good. But for the combination -bbsb=3 -wn we get

+ +
    # OLD: ERROR
+    # -sil=1 -bbsb=3 -wn
+    $$d{"day_name"} = [ [
+        "lundi",    "mardi",  "mercredi", "jeudi",
+        "vendredi", "samedi", "dimanche"
+    ] ];
+ +

which is incorrect because it ignors the -bbsb flag. The corrected result is

+ +
    # NEW: OK
+    # -sil=1 -bbsb=3 -wn
+    $$d{"day_name"} =
+      [ [
+        "lundi",    "mardi",  "mercredi", "jeudi",
+        "vendredi", "samedi", "dimanche"
+      ] ];
+ +

This update fixes case b1173. It works for any number of welded containers, and the -bbxxi=n flags also work correctly.

+ +

16 Jul 2021.

+ +
Fix problem with side comment after pattern
diff --git a/docs/ChangeLog.html b/docs/ChangeLog.html index 5da04d46..eff6bf75 100644 --- a/docs/ChangeLog.html +++ b/docs/ChangeLog.html @@ -17,8 +17,8 @@ - A warning will no longer be given if a script has an opening code-skipping comment '#<<V' which is not terminated with a closing comment '#>>V'. This - makes code-skipping and format-skipping behave in a similar way: a - '#>>V' or '#>>>' comment without a corresponding closing comment will cause + makes code-skipping and format-skipping behave in a similar way: an + opening comment without a corresponding closing comment will cause the rest of a file to be skipped. If there is a question about which lines are skipped, a .LOG file can be produced with the -g flag and it will have this information. @@ -29,6 +29,9 @@ This limit had been placed to avoid some formatting instabilities, but recent coding improvements allow the limit to be removed. +- The -wn and -bbxx=n flags were not working together correctly. This has + been fixed. + - Numerous minor fixes have been made. A complete list is at: https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index a83e1c43..6d4c2785 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6913,8 +6913,8 @@ sub weld_containers { } # Update the end index and lengths of any long welds to extend to the far - # end. We only need to do this for the right links, not for the left links. - # This has to be processed in sorted order. + # end. This has to be processed in sorted order. + # Left links added for b1173. my $Kend = -1; foreach my $Kstart ( sort { $a <=> $b } @K_multi_weld ) { @@ -6924,11 +6924,13 @@ sub weld_containers { my @Klist; push @Klist, $Kstart; $Kend = $rK_weld_right->{$Kstart}; + $rK_weld_left->{$Kend} = $Kstart; my $Knext = $rK_weld_right->{$Kend}; while ( defined($Knext) ) { push @Klist, $Kend; - $Kend = $Knext; - $Knext = $rK_weld_right->{$Kend}; + $Kend = $Knext; + $rK_weld_left->{$Kend} = $Kstart; + $Knext = $rK_weld_right->{$Kend}; } pop @Klist; # values for last entry are already correct foreach my $KK (@Klist) { @@ -8714,6 +8716,7 @@ sub break_before_list_opening_containers { my $rtype_count_by_seqno = $self->[_rtype_count_by_seqno_]; my $rlec_count_by_seqno = $self->[_rlec_count_by_seqno_]; my $rno_xci_by_seqno = $self->[_rno_xci_by_seqno_]; + my $rK_weld_right = $self->[_rK_weld_right_]; my $length_tol = max( 1, $rOpts_continuation_indentation, $rOpts_indent_columns ); @@ -8738,6 +8741,19 @@ sub break_before_list_opening_containers { # a depth of just 1 my $is_list = $self->is_list_by_seqno($seqno); my $has_list = $rhas_list->{$seqno}; + + # Fix for b1173: if welded opening container, use flag of innermost + # seqno. Otherwise, the restriction $has_list==1 prevents triple and + # higher welds from following the -BBX parameters. + if ($total_weld_count) { + my $KK_test = $rK_weld_right->{$KK}; + if ( defined($KK_test) ) { + my $seqno_inner = $rLL->[$KK_test]->[_TYPE_SEQUENCE_]; + $is_list ||= $self->is_list_by_seqno($seqno_inner); + $has_list = $rhas_list->{$seqno_inner}; + } + } + next unless ( $is_list || $has_list && $has_list == 1 ); my $has_broken_list = $rhas_broken_list->{$seqno}; @@ -14478,7 +14494,6 @@ sub insert_breaks_before_list_opening_containers { my $Kl = $K_to_go[$il]; my $Kr = $K_to_go[$ir]; my $Kend = $Kr; - my $iend = $ir; my $type_end = $rLL->[$Kr]->[_TYPE_]; # Backup before any side comment @@ -14486,8 +14501,21 @@ sub insert_breaks_before_list_opening_containers { $Kend = $self->K_previous_nonblank($Kr); next unless defined($Kend); $type_end = $rLL->[$Kend]->[_TYPE_]; - $iend = $ir + ( $Kend - $Kr ); } + + # Backup to the start of any weld; fix for b1173. + if ($total_weld_count) { + my $Kend_test = $rK_weld_left->{$Kend}; + if ( defined($Kend_test) && $Kend_test > $Kl ) { + $Kend = $Kend_test; + $Kend_test = $rK_weld_left->{$Kend}; + } + + # Do not break if we did not back up to the start of a weld + # (shouldn't happen) + next if ( defined($Kend_test) ); + } + my $token = $rLL->[$Kend]->[_TOKEN_]; next unless ( $is_opening_token{$token} ); next unless ( $Kl < $Kend - 1 ); @@ -14498,9 +14526,6 @@ sub insert_breaks_before_list_opening_containers { # Use the flag which was previously set next unless ( $rbreak_before_container_by_seqno->{$seqno} ); - # But never break a weld - next if ( $total_weld_count && defined( $rK_weld_left->{$Kend} ) ); - # Install a break before this opening token. my $Kbreak = $self->K_previous_nonblank($Kend); my $ibreak = $Kbreak - $Kl + $il; @@ -20883,17 +20908,19 @@ sub make_paren_name { # Honor any flag to reduce -ci set by the -bbxi=n option if ( $seqno_beg && $rwant_reduced_ci->{$seqno_beg} ) { - # if this is an opening, it must be alone on the line - if ( $is_closing_type{$type_beg} || $ibeg == $iend ) { + # if this is an opening, it must be alone on the line ... + if ( $is_closing_type{$type_beg} || $ibeg == $i_terminal ) { $adjust_indentation = 1; } - elsif ( $iend <= $ibeg + 2 ) { - my $inext = $inext_to_go[$ibeg]; - if ( $inext - && ( $inext > $iend || $types_to_go[$inext] eq '#' ) ) - { - $adjust_indentation = 1; + + # ... or a single welded unit (fix for b1173) + elsif ($total_weld_count) { + my $Kterm = $K_to_go[$i_terminal]; + my $Kterm_test = $rK_weld_left->{$Kterm}; + if ( defined($Kterm_test) && $Kterm_test >= $K_beg ) { + $Kterm = $Kterm_test; } + if ( $Kterm == $K_beg ) { $adjust_indentation = 1 } } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 4e79e066..1d5c05ba 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,63 @@ =over 4 +=item B + +Testing with random parameters produced some cases where the combination of -wn +and various -bbxx=n flags were not working together. To illustrate, consider +the following script (-sil=1 just means start at 1 indentation level) + + # perltidy -sil=1 + $$d{"day_name"} = [ + [ + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche" + ] + ]; + +With welding we get: + + # -sil=1 -wn + $$d{"day_name"} = [ [ + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche" + ] ]; + +With -bbsb=3 (--break-before-square-brackets) we get: + + # -sil=1 -bbsb=3 + $$d{"day_name"} = + [ + [ + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche" + ] + ]; + +So far, so good. But for the combination -bbsb=3 -wn we get + + # OLD: ERROR + # -sil=1 -bbsb=3 -wn + $$d{"day_name"} = [ [ + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche" + ] ]; + +which is incorrect because it ignors the -bbsb flag. The corrected result is + + # NEW: OK + # -sil=1 -bbsb=3 -wn + $$d{"day_name"} = + [ [ + "lundi", "mardi", "mercredi", "jeudi", + "vendredi", "samedi", "dimanche" + ] ]; + +This update fixes case b1173. It works for any number of welded containers, +and the -bbxxi=n flags also work correctly. + +16 Jul 2021. + =item B Testing with randomly placed side comments produced an error illustrated