From 71dfe662a8b5c694b941695ad4f6cfbdf8eb11ff Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 15 Sep 2024 06:32:18 -0700 Subject: [PATCH] fix b1487, b1488 --- bin/perltidy | 2 +- dev-bin/run_convergence_tests.pl.data | 31 +++++++++++++++++++++++++ dev-bin/run_convergence_tests.pl.expect | 17 ++++++++++++++ lib/Perl/Tidy/Formatter.pm | 28 +++++++++++++++++----- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index ab0b8ec1..c15f98d2 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3939,7 +3939,7 @@ The parameter B<--want-trailing-commas=s>, or B<-wtc=s>, defines a preferred sty s=0 : no list should have a trailing comma s=1 or * : every list should have a trailing comma - s=m a multi-line list should have a trailing commas + s=m a multi-line list should have a trailing comma s=b trailing commas should be 'bare' (comma followed by newline) s=h lists of key=>value pairs, with about one one '=>' and one ',' per line, with a bare trailing comma diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index a2a0fde9..e65f53da 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -12264,6 +12264,37 @@ use --noadd-whitespace --qw-as-function +==> b1487.in <== +use Net::Domain qw(hostname domainname + hostdomain); +use Net::Domain qw( + hostname + domainname + hostdomain +); + +==> b1487.par <== +--maximum-line-length=41 +--continuation-indentation=7 +--line-up-parentheses +--noadd-whitespace +--qw-as-function + +==> b1488.in <== +use vars qw( + $VERSION @ISA + @EXPORT_OK %EXPORT_TAGS +); +use vars qw($VERSION @ISA + @EXPORT_OK %EXPORT_TAGS); + +==> b1488.par <== +--maximum-line-length=48 +--continuation-indentation=6 +--noadd-whitespace +--extended-line-up-parentheses +--qw-as-function + ==> b156.in <== # State 1 { diff --git a/dev-bin/run_convergence_tests.pl.expect b/dev-bin/run_convergence_tests.pl.expect index cdc9f126..a73b4d6d 100644 --- a/dev-bin/run_convergence_tests.pl.expect +++ b/dev-bin/run_convergence_tests.pl.expect @@ -8309,6 +8309,23 @@ use UnixODBC :all ); +==> b1487 <== +use Net::Domain qw(hostname domainname + hostdomain); +use Net::Domain qw( + hostname + domainname + hostdomain +); + +==> b1488 <== +use vars qw( + $VERSION @ISA + @EXPORT_OK %EXPORT_TAGS +); +use vars qw($VERSION @ISA + @EXPORT_OK %EXPORT_TAGS); + ==> b156 <== # State 1 { diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0863c28d..49810c48 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6753,6 +6753,15 @@ EOM return; } + # The combination -naws -lp can currently be unstable for multi-line qw + # (b1487, b1488). + if ( !$rOpts_add_whitespace + && $rOpts_line_up_parentheses + && ( !$opening || !$closing ) ) + { + return; + } + #--------------------------------------------------------------------- # This is the point of no return if the transformation has not started #--------------------------------------------------------------------- @@ -14202,16 +14211,23 @@ sub match_trailing_comma_rule { $has_multiline_commas = $line_diff_commas > 0; } - # To avoid instability in edge cases, when adding commas we uses the - # multiline_commas definition, but when deleting we use multiline - # containers. This fixes b1384, b1396, b1397, b1398, b1400. - # Added fat_comma_count to handle one-line with key=>value, git143 + # To avoid instability in edge cases, we must make it somewhat easier + # to delete commas than to add commas. The following prescription + # fixes b1384, b1396, b1397, b1398, b1400. my $is_multiline = $if_add - ? $has_multiline_commas || $has_multiline_containers && $fat_comma_count + ? $has_multiline_commas : $has_multiline_containers; - my $is_bare_multiline_comma = $is_multiline && $KK == $Kfirst; + # Old coding for bare comma, very stable: + # my $is_bare_multiline_comma = $KK == $Kfirst && $is_multiline; + + # Testing new coding for bare comma adds fat_comma_count to handle adding + # comma to one-line with key=>value, git143 + my $is_bare_multiline_comma = $KK == $Kfirst; + if ($if_add) { + $is_bare_multiline_comma &&= $has_multiline_commas || $fat_comma_count; + } my $match; -- 2.39.5