From: Steve Hancock Date: Tue, 4 May 2021 00:05:41 +0000 (-0700) Subject: Fix vertical alignment issue raised in rt #136416 X-Git-Tag: 20210402.01~56 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=048126cdf5b5f1ddc82f3a56ddd03cbc643d8105;p=perltidy.git Fix vertical alignment issue raised in rt #136416 --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 4ad58f2c..c1092bee 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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} = ""; + } + } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index efbe2b9f..e5344c0c 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,13 +2,26 @@ =over 4 +=item B + +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 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 @@ -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 @@ -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 diff --git a/t/snippets/align35.in b/t/snippets/align35.in new file mode 100644 index 00000000..9f3aecb7 --- /dev/null +++ b/t/snippets/align35.in @@ -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 index 00000000..5cfd61dd --- /dev/null +++ b/t/snippets/expect/align35.def @@ -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/packing_list.txt b/t/snippets/packing_list.txt index 03dd273f..fdb8571f 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -318,6 +318,7 @@ ../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 @@ -458,4 +459,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets24.t git63.def +../snippets24.t align35.def diff --git a/t/snippets24.t b/t/snippets24.t index 540d6ffb..7b944a79 100644 --- a/t/snippets24.t +++ b/t/snippets24.t @@ -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};