]> git.donarmstrong.com Git - perltidy.git/commitdiff
added rule for -wn flag: do not weld to a hash brace
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 20 Jan 2021 15:12:33 +0000 (07:12 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 20 Jan 2021 15:12:33 +0000 (07:12 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index b1573e2febc4e0582b2c18a29efa2ee1b0daa5db..138cef9a60bf7e5ced5c1138fd74ea9922526934 100644 (file)
@@ -6683,6 +6683,12 @@ sub weld_nested_containers {
         my $iline_io = $inner_opening->[_LINE_INDEX_];
         my $iline_ic = $inner_closing->[_LINE_INDEX_];
 
+        # RULE: do not weld to a hash brace unless it is preceded by @
+        if ( $inner_opening->[_TYPE_] eq 'L' ) {
+            my $Kp  = $self->K_previous_nonblank($Kinner_opening);
+            next unless ( defined($Kp) && $rLL->[$Kp]->[_TOKEN_] eq '@' );
+        }
+
         # Set flag saying if this pair starts a new weld
         my $starting_new_weld = !( @welds && $outer_seqno == $welds[-1]->[0] );
 
index 777aea468b3add704c625ad5248fd9a15020ed90..41396c1235e1f3d5d1cc58b9ec1cb8915de90689 100644 (file)
@@ -2,6 +2,97 @@
 
 =over 4
 
+=item B<added rule for -wn, do not weld to a hash brace>
+
+In random testing, the following two alternating states
+
+    # State 1
+    {
+        if ( defined
+        ($symbol_table{$direccion}) )
+    }
+    
+    # State 2
+    {
+        if (defined (
+                $symbol_table{
+                    $direccion}
+            )
+        )
+    }
+
+were occuring with the following particular parameter set
+
+    --weld-nested-containers
+    --maximum-line-length=40
+    --continuation-indentation=7
+    --paren-tightness=2
+    --extended-continuation-indentation
+
+The problem was traced to welding to the opening hash brace.  A rule
+was added to prevent this, and testing with a large body of code
+showed that it did not significantly change existing formatting. With
+this change, the above snippet formats in the stable state
+
+    {
+        if (defined(
+            $symbol_table{$direccion}
+        ))
+    }
+
+20 Jan 2021.
+
+=item B<Some issues with the -lp option>
+
+Random testing revealed dome problems involving the B<-lp> option which are
+fixed with this update.
+
+The first problem is illustrated with the following snippet
+
+    $cron =
+      pkgfile( $PACKAGE,
+              "cron.$type" ) ;
+
+which alternately switches to this format
+    
+    $cron =
+      pkgfile( $PACKAGE,
+               "cron.$type"
+      ) ;
+
+when processed with these particular parameters:
+
+    --indent-columns=1
+    --maximum-line-length=26
+    --line-up-parentheses
+    --space-terminal-semicolon
+
+The last parameter, a space before the semicolon, is the main cause of
+the problem. Without it the problem does not occur.
+
+Another problem is illustrated with the following snippet
+
+    Alien::FillOutTemplate(
+                "$main::libdir/to-$main::desttype/$main::filetype/spec",
+                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
+                %fields
+    );
+
+which alternately formats to this form
+
+    # perltidy -lp
+    Alien::FillOutTemplate(
+                "$main::libdir/to-$main::desttype/$main::filetype/spec",
+                "$workdir/$fields{NAME}-$fields{VERSION}-$fields{RELEASE}.spec",
+                %fields );
+
+when formatted with the single parameter B<-lp>.  These problems can be corrected by
+not processing blank tokens in the sub which sets the leading whitespace for
+the -lp option, 'sub set_leading_whitespace'.  However, this fix can change
+some existing formatting with the -lp flag, so this coding is not yet activated.
+It can be turned on for testing with the internal flag 'TEST_LP_FIX'.
+
+
 =item B<Do not let -kgb option delete essential blank after =cut>
 
 A blinking state was found in random testing for the following snippet