]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix vertical alignment issue raised in rt #136416
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 May 2021 00:05:41 +0000 (17:05 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 May 2021 00:05:41 +0000 (17:05 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/align35.in [new file with mode: 0644]
t/snippets/expect/align35.def [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets24.t

index 4ad58f2c7764c002ab3a9694d5c1d02780a0647c..c1092bee9254b2268b2a7538047c8836d5c323b4 100644 (file)
@@ -20073,8 +20073,16 @@ sub pad_token {
         my @field_lengths = ();
         my $i_start       = $ibeg;
 
+        # For a 'use' statement, use the module name as container name.
+        # Fixes issue rt136416.
+        my $cname = "";
+        if ( $types_to_go[$ibeg] eq 'k' && $tokens_to_go[$ibeg] eq 'use' ) {
+            my $inext = $inext_to_go[$ibeg];
+            if ( $inext <= $iend ) { $cname = $tokens_to_go[$inext] }
+        }
+
         my $depth          = 0;
-        my %container_name = ( 0 => "" );
+        my %container_name = ( 0 => "$cname" );
 
         my $j = 0;    # field index
 
@@ -20354,6 +20362,12 @@ sub pad_token {
                 if ( $type eq '!' ) { $type_fix = '' }
 
                 $patterns[$j] .= $type_fix;
+
+                # remove any zero-level name at first fat comma
+                if ( $depth == 0 && $type eq '=>' ) {
+                    $container_name{$depth} = "";
+                }
+
             }
         }
 
index efbe2b9f97961435a390a4a8cdfc5a95ac63bf1f..e5344c0c24144f61c0272426ab5d913ef6900a34 100644 (file)
@@ -2,13 +2,26 @@
 
 =over 4
 
+=item B<Fix vertical alignment issue in rt136416>
+
+This update fixes a problem with unwanted vertical alignment rasied in
+rt#136416.  The example is
+
+    use File::Spec::Functions 'catfile', 'catdir';
+    use Mojo::Base 'Mojolicious',        '-signatures';
+
+An update was made to reject alignments in use statements with different module names.
+The test file t/snippets/align35.in has more examples.
+
+3 May 2021.
+
 =item B<Fix some rare issues with the -lp option>
 
 Random testing produced some rare cases of unstable formatting involving the
 B<-lp> option which are fixed with this update.  This is a generalization of
 commit edc7878 of 23 Jan 2021.  This fixes cases b1109 b1110.
 
-2 May 2021.
+2 May 2021, a8d1c8b.
 
 =item B<Correct brace types mismarked by tokenizer>
 
@@ -18,7 +31,7 @@ determined in the tokenizer and was not being corrected by the formatter.
 
 This fixes cases b1125 b1126 b1127.
 
-2 May 2021.
+2 May 2021i, dac97cb.
 
 =item B<Avoid instability of combination -bbx=2 -lp and -xci>
 
@@ -28,7 +41,7 @@ were causing formatting instability.  The fix is to locally turn off -xci when
 
 This fixes cases b1090 b1095 b1101 b1116 b1118 b1121 b1122 b1099
 
-1 May 2021.
+1 May 2021, 4cb81ba.
 
 =item B<Restrict use of flag -cab=3 to simple structures>
 
diff --git a/t/snippets/align35.in b/t/snippets/align35.in
new file mode 100644 (file)
index 0000000..9f3aecb
--- /dev/null
@@ -0,0 +1,18 @@
+# differnt module names, do not align commas (fixes rt136416)
+use File::Spec::Functions 'catfile', 'catdir';
+use Mojo::Base 'Mojolicious', '-signatures';
+
+# same module names, align fat commas
+use constant PI => 4 * atan2 1, 1;
+use constant TWOPI => 2 * PI;
+use constant FOURPI => 4 * PI;
+
+# same module names, align commas
+use TestCounter '3rd-party', 0, '3rd-party no longer visible';
+use TestCounter 'replace', 1, 'replacement now visible';
+use TestCounter 'root';
+
+# same module name, align fat commas but not commas
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+use constant COUNTUP => reverse 1, 2, 3, 4, 5;
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
diff --git a/t/snippets/expect/align35.def b/t/snippets/expect/align35.def
new file mode 100644 (file)
index 0000000..5cfd61d
--- /dev/null
@@ -0,0 +1,18 @@
+# differnt module names, do not align commas (fixes rt136416)
+use File::Spec::Functions 'catfile', 'catdir';
+use Mojo::Base 'Mojolicious', '-signatures';
+
+# same module names, align fat commas
+use constant PI     => 4 * atan2 1, 1;
+use constant TWOPI  => 2 * PI;
+use constant FOURPI => 4 * PI;
+
+# same module names, align commas
+use TestCounter '3rd-party', 0, '3rd-party no longer visible';
+use TestCounter 'replace',   1, 'replacement now visible';
+use TestCounter 'root';
+
+# same module name, align fat commas but not commas
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+use constant COUNTUP   => reverse 1, 2, 3, 4, 5;
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
index 03dd273f4e458b69bfe1c0827ec6a07846d0623b..fdb8571fc92d58467778af65d60f0e9e46583469 100644 (file)
 ../snippets24.t        lpxl.lpxl3
 ../snippets24.t        lpxl.lpxl4
 ../snippets24.t        lpxl.lpxl5
+../snippets24.t        git63.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets24.t        git63.def
+../snippets24.t        align35.def
index 540d6ffb25518d77afc8d5b9205c39118cd80336..7b944a7942ed60fee76689737a219ccd1e8c2565 100644 (file)
@@ -12,6 +12,7 @@
 #9 lpxl.lpxl4
 #10 lpxl.lpxl5
 #11 git63.def
+#12 align35.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -50,6 +51,27 @@ BEGIN {
     ############################
     $rsources = {
 
+        'align35' => <<'----------',
+# differnt module names, do not align commas (fixes rt136416)
+use File::Spec::Functions 'catfile', 'catdir';
+use Mojo::Base 'Mojolicious', '-signatures';
+
+# same module names, align fat commas
+use constant PI => 4 * atan2 1, 1;
+use constant TWOPI => 2 * PI;
+use constant FOURPI => 4 * PI;
+
+# same module names, align commas
+use TestCounter '3rd-party', 0, '3rd-party no longer visible';
+use TestCounter 'replace', 1, 'replacement now visible';
+use TestCounter 'root';
+
+# same module name, align fat commas but not commas
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+use constant COUNTUP => reverse 1, 2, 3, 4, 5;
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+----------
+
         'fpva' => <<'----------',
 log_something_with_long_function( 'This is a log message.', 2 );
 Coro::AnyEvent::sleep( 3, 4 );
@@ -684,6 +706,31 @@ my $fragment = $parser->    #parse_html_string
   parse_balanced_chunk($I);
 #11...........
         },
+
+        'align35.def' => {
+            source => "align35",
+            params => "def",
+            expect => <<'#12...........',
+# differnt module names, do not align commas (fixes rt136416)
+use File::Spec::Functions 'catfile', 'catdir';
+use Mojo::Base 'Mojolicious', '-signatures';
+
+# same module names, align fat commas
+use constant PI     => 4 * atan2 1, 1;
+use constant TWOPI  => 2 * PI;
+use constant FOURPI => 4 * PI;
+
+# same module names, align commas
+use TestCounter '3rd-party', 0, '3rd-party no longer visible';
+use TestCounter 'replace',   1, 'replacement now visible';
+use TestCounter 'root';
+
+# same module name, align fat commas but not commas
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+use constant COUNTUP   => reverse 1, 2, 3, 4, 5;
+use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
+#12...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};