From: Steve Hancock Date: Tue, 11 Oct 2022 14:29:58 +0000 (-0700) Subject: changed new parameter name from -tcs to -wtc X-Git-Tag: 20220613.06~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4ee3bafb2771d115beeffb2fa7c4fe12ad5746ba;p=perltidy.git changed new parameter name from -tcs to -wtc --- diff --git a/CHANGES.md b/CHANGES.md index 0eba24c7..5105d1ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -101,8 +101,17 @@ my ($curr) = current(); err(@_); + - The following new parameters are available for manipulating + trailing commas: + + --want-trailing-commas=s, -wtc=s + --add-trailing-commas, -atc + --delete-trailing-commas, -dtc + --delete-weld-interfering-commas, -dwic + - This version runs about 10 to 15 percent faster than the previous - release on large files, depending on formatting parameters. + release on large files, depending on formatting parameters, due to + optimizations made with the help of Devel::NYTProf. ## 2022 06 13 diff --git a/bin/perltidy b/bin/perltidy index 7c2b66b4..97bd2b96 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2924,6 +2924,51 @@ Here are some additional example strings and their meanings: '[ {' - exclude all brackets and braces '[ ( ^K{' - exclude everything except nested structures like do {{ ... }} +=item B<-dwic>, B<--delete-weld-interfering-commas> + +If the closing tokens of two nested containers are separated by a comma, then +welding cannot occur. Any commas in this situation are optional trailing +commas and can be removed if desired. This can be done by hand, but on large +scripts it might be easier to use this parameter. The parameter B<-dwic> tells +perltidy to remove any such commas that it finds. For example, using a +previous example with an added comma, we see that the comma prevents welding: + + # perltidy -wn + skip_symbols( + [ qw( + Perl_dump_fds + Perl_ErrorNo + Perl_GetVars + PL_sys_intern + ) ], + ); + +If this is not desired, then the comma can be removed manually or by using B<-dwic>, as follows: + + # perltidy -wn -dwic + skip_symbols( [ qw( + Perl_dump_fds + Perl_ErrorNo + Perl_GetVars + PL_sys_intern + ) ] ); + +Here are some points to note about the B<-dwic> parameter + +=over 4 + +=item * + +This operation is not reversible, so please check results of using this parameter carefully. + +=item * + +Removing these isolated trailing commas is necessary for welding to be +possible, but not sufficient. + +=back + + =item B of non-block curly braces, parentheses, and square brackets. These parameters control what shall be called vertical tightness. Here are the @@ -3471,6 +3516,100 @@ Here is an example. "09" => 30, "10" => 31, "11" => 30, "12" => 31 ); +=item B<-wtc=s>, B<--want-trailing-commas=s> + +A trailing comma is a comma following the last item of a list. Perl allows +trailing commas but they are not required. By default, perltidy does not add +or delete trailing commas, but it is possible to do this with the following set of three related parameters: + + --want-trailing-commas=s, -wtc=s - defines where trailing commas are wanted + --add-trailing-commas, -atc - gives permission to add trailing commas to match the style + --delete-trailing-commas, -dtc - gives permission to delete trailing commas which do not match the style + +The parameter B<--want-trailing-commas=s>, or B<-wtc=s>, defines a preferred style. The string B indicates which lists should get trailing commas, as follows: + + 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=b trailing commas should be 'bare' (comma followed by newline) + s=h trailing commas should be 'bare' for lists of key=>value pairs, or other lists with about one comma per line. + s=' ', or -wtc not defined : leave trailing commas unchanged [DEFAULT]. + +This parameter by itself only indicates the where trailing commas are +wanted. Perltidy only adds these trailing commas if the flag B<--add-trailing-comma>, or B<-atc> is set. And perltidy only removes unwanted trailing commas +if the flag B<--delete-trailing-comma> is set. + +Here are some example parameter combinations and their meanings + + -wtc=0 -dtc : delete all trailing commas + -wtc=1 -atc : put trailing commas on all lists + -wtc=m -atc : all multi-line lists get trailing commas; + single line lists may or may not have trailing commas + -wtc=m -atc -dtc : all multi-line lists get trailing commas, and + any trailing commas on single line lists are removed. + +For example, we can add a comma after the variable C<$Root> in the example +a few lines above using + + # perltidy -wtc=m -atc + bless { + B => $B, + Root => $Root, + } => $package; + +This could also be achieved in this case with B<-wtc=b -atc> because +the trailing comma here is bare (separated from the closing brace by a newline). +And it could also be achieved with B<-wtc=h -atc> because this particular +list is a list of key=>value pairs. + +It is possible to apply a different style to different types of containing +tokens by including an opening token ahead of the style character in the above table. For example + + -wtc='(m [b' + +means that lists within parens should have multi-line trailing commas, and that +lists within square brackets have bare trailing commas. Since there is no +specification for curly braces in this example, their trailing commas would +remain unchanged. + +Here are some points regarding adding and deleting trailing commas: + +=over 4 + +=item * + +For the implementation of these parameters, a B is basically taken to be a sequence of items in a container (parens, square brackets, or braces) which is not a code block, separated by one or more commas. + +So a paren-less list of parameters is not a list by this definition. + +And note that if the only comma in a list is a trailing comma, and it is +deleted with these commands, then that container will no longer be a list by +this definition. Consequently, a trailing comma cannot later be added to that +container. + +=item * + +By B list is meant a list for which the opening and closing tokens +are on different lines. + +=item * + +A B trailing comma is a comma which is at the end of a line. That is, +the closing container token follows on a different line. + +=item * + +The decision regarding whether or not a list is multiline or bare is +made based on the B stream. In some cases it may take an iteration +or two to reach a final state. + +=item * + +When using these parameters for the first time it is a good idea to practice +on some test scripts and verify that the results are as expected. + +=back + =back =head2 Retaining or Ignoring Existing Line Breaks diff --git a/dev-bin/perltidy_random_setup.pl b/dev-bin/perltidy_random_setup.pl index f4991e6c..0e8e8ad4 100755 --- a/dev-bin/perltidy_random_setup.pl +++ b/dev-bin/perltidy_random_setup.pl @@ -1135,7 +1135,7 @@ EOM 'space-prototype-paren' => [ 0, 2 ], 'break-after-labels' => [ 0, 2 ], - 'trailing-comma-style' => [ '0', '*', 'm', 'b', 'h', ' ' ], + 'want-trailing-commas' => [ '0', '*', 'm', 'b', 'h', ' ' ], # Arbitrary limits to keep things readable 'blank-lines-after-opening-block' => [ 0, 4 ], diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index fb62b4fb..bd8e73fe 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -10190,7 +10190,7 @@ $font_size } ==> b1378.par <== --extrude -vtc=2 -dtc -tcs=0 +-extrude -vtc=2 -dtc -wtc=0 ==> b1379.in <== # S1 @@ -10217,7 +10217,7 @@ print star ( --maximum-fields-per-table=27 --maximum-line-length=40 --space-function-paren ---trailing-comma-style='b' +--want-trailing-commas='b' --variable-maximum-line-length --vertical-tightness-closing=2 diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 875fff11..4567304b 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -3187,8 +3187,8 @@ sub generate_options { $add_option->( 'trim-pod', 'trp', '!' ); $add_option->( 'want-left-space', 'wls', '=s' ); $add_option->( 'want-right-space', 'wrs', '=s' ); + $add_option->( 'want-trailing-commas', 'wtc', '=s' ); $add_option->( 'space-prototype-paren', 'spp', '=i' ); - $add_option->( 'trailing-comma-style', 'tcs', '=s' ); $add_option->( 'valign-code', 'vc', '!' ); $add_option->( 'valign-block-comments', 'vbc', '!' ); $add_option->( 'valign-side-comments', 'vsc', '!' ); diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6ccd0e1a..4ecdade2 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -2449,7 +2449,7 @@ sub initialize_trailing_comma_rules { # Setup control hash for trailing commas - # -tcs=s defines desired trailing comma policy: + # -wtc=s defines desired trailing comma policy: # # =" " stable # [ both -atc and -dtc ignored ] @@ -2469,7 +2469,7 @@ sub initialize_trailing_comma_rules { my $rvalid_flags = [qw(0 1 * m b h)]; - my $option = $rOpts->{'trailing-comma-style'}; + my $option = $rOpts->{'want-trailing-commas'}; if ($option) { $option =~ s/^\s+//; @@ -2542,7 +2542,7 @@ sub initialize_trailing_comma_rules { if ($error_message) { Warn(<