]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix to make -wn and -bbxx=n flags work together
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 17 Jul 2021 01:45:04 +0000 (18:45 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 17 Jul 2021 01:45:04 +0000 (18:45 -0700)
CHANGES.md
dev-bin/run_convergence_tests.pl
dev-bin/run_convergence_tests.pl.data
docs/BugLog.html
docs/ChangeLog.html
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 45d6a1fb158fae9ab969778db22e1b1150031087..fa8ba4facf24b9be7ca9e79d691b78c6ade16256 100644 (file)
@@ -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
index 471040a1ec438b0cc01dcd99fca9e0d22f374af4..6258f242a60ce2ecb1d5ee18790463fa7aea8e78 100755 (executable)
@@ -9,7 +9,7 @@ my $usage = <<EOM;
 This utility runs perltidy on a database of stability test cases. 
 It can:
 
-  - run perttidy on the stability test cases
+  - run perltidy on the stability test cases
   - do maintenance of the database of test cases
 
 There are four options: run [DEFAULT], pack, merge, unpack ( -r -p -m -u )
index fd0f4dab97cc71e90edf990343bdaad1a614fbf1..c4b29812a0724929b9c517fc03d4f8122d3cd794 100644 (file)
@@ -6507,6 +6507,47 @@ ok('[{"1":[5]}]' eq
 --line-up-parentheses
 --maximum-line-length=27
 
+==> 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
index c382cffa04d5b04b5c99bce6298b42ae9bc65482..8af72619126b0a630b94d7818e8aa127624f71ab 100644 (file)
 
 <dl>
 
+<dt id="Fix-to-make--wn-and--bbxx-n-flags-work-together"><b>Fix to make -wn and -bbxx=n flags work together</b></dt>
+<dd>
+
+<p>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)</p>
+
+<pre><code>    # perltidy -sil=1
+    $$d{&quot;day_name&quot;} = [
+        [
+            &quot;lundi&quot;,    &quot;mardi&quot;,  &quot;mercredi&quot;, &quot;jeudi&quot;,
+            &quot;vendredi&quot;, &quot;samedi&quot;, &quot;dimanche&quot;
+        ]
+    ];</code></pre>
+
+<p>With welding we get:</p>
+
+<pre><code>    # -sil=1 -wn
+    $$d{&quot;day_name&quot;} = [ [
+        &quot;lundi&quot;,    &quot;mardi&quot;,  &quot;mercredi&quot;, &quot;jeudi&quot;,
+        &quot;vendredi&quot;, &quot;samedi&quot;, &quot;dimanche&quot;
+    ] ];</code></pre>
+
+<p>With -bbsb=3 (--break-before-square-brackets) we get:</p>
+
+<pre><code>    # -sil=1 -bbsb=3
+    $$d{&quot;day_name&quot;} =
+      [
+        [
+            &quot;lundi&quot;,    &quot;mardi&quot;,  &quot;mercredi&quot;, &quot;jeudi&quot;,
+            &quot;vendredi&quot;, &quot;samedi&quot;, &quot;dimanche&quot;
+        ]
+      ];</code></pre>
+
+<p>So far, so good. But for the combination -bbsb=3 -wn we get</p>
+
+<pre><code>    # OLD: ERROR
+    # -sil=1 -bbsb=3 -wn
+    $$d{&quot;day_name&quot;} = [ [
+        &quot;lundi&quot;,    &quot;mardi&quot;,  &quot;mercredi&quot;, &quot;jeudi&quot;,
+        &quot;vendredi&quot;, &quot;samedi&quot;, &quot;dimanche&quot;
+    ] ];</code></pre>
+
+<p>which is incorrect because it ignors the -bbsb flag. The corrected result is</p>
+
+<pre><code>    # NEW: OK
+    # -sil=1 -bbsb=3 -wn
+    $$d{&quot;day_name&quot;} =
+      [ [
+        &quot;lundi&quot;,    &quot;mardi&quot;,  &quot;mercredi&quot;, &quot;jeudi&quot;,
+        &quot;vendredi&quot;, &quot;samedi&quot;, &quot;dimanche&quot;
+      ] ];</code></pre>
+
+<p>This update fixes case b1173. It works for any number of welded containers, and the -bbxxi=n flags also work correctly.</p>
+
+<p>16 Jul 2021.</p>
+
+</dd>
 <dt id="Fix-problem-with-side-comment-after-pattern"><b>Fix problem with side comment after pattern</b></dt>
 <dd>
 
index 5da04d461d82b0df3836f19e83bf182c010b0e8b..eff6bf7581190114a3d3510691193d8fceb17189 100644 (file)
@@ -17,8 +17,8 @@
 
 - A warning will no longer be given if a script has an opening code-skipping
   comment '#&lt;&lt;V' which is not terminated with a closing comment '#&gt;&gt;V'. This
-  makes code-skipping and format-skipping behave in a similar way: a
-  '#&gt;&gt;V' or '#&gt;&gt;&gt;' 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
index a83e1c436fdd55717600caea6909ad6cbb40e75a..6d4c2785a94e6a3feb2238749b25d6fff0739d91 100644 (file)
@@ -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 }
             }
         }
 
index 4e79e066b0de4457ae29d4a521ac01af76819e6d..1d5c05ba2c3e89f52a9ffa4ac26f02ab61e0c1ab 100644 (file)
@@ -2,6 +2,63 @@
 
 =over 4
 
+=item B<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.
+
 =item B<Fix problem with side comment after pattern>
 
 Testing with randomly placed side comments produced an error illustrated