]> git.donarmstrong.com Git - perltidy.git/commitdiff
changed new parameter name from -tcs to -wtc
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Oct 2022 14:29:58 +0000 (07:29 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Oct 2022 14:29:58 +0000 (07:29 -0700)
CHANGES.md
bin/perltidy
dev-bin/perltidy_random_setup.pl
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index 0eba24c709905bfbddf90ae023261ecc5a097085..5105d1ee5fb293002396d7ddfc532c0dafb2dad9 100644 (file)
             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
 
index 7c2b66b4e4e929f730372160efb9f4380a9ce6b2..97bd2b966a9abbb4e5619e80422857a59362560d 100755 (executable)
@@ -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<Vertical tightness> 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<s> 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<list> 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<multiline> list is meant a list for which the opening and closing tokens
+are on different lines.
+
+=item *
+
+A B<bare> 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<input> 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
index f4991e6c50286e595372ca52310269ca112f31ac..0e8e8ad4682402b9b054052cc0c3181e67c27cb1 100755 (executable)
@@ -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 ],
index fb62b4fbf978a7c56b6fb0b6290385d28797df0d..bd8e73fefc3ff696bb8d4614ea45f49a2cebc418 100644 (file)
@@ -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
 
index 875fff112da8fbfb5737d92e401ca7c6689c06c6..4567304b40932bf9d173a1fe8a3b3a650e957f01 100644 (file)
@@ -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',   '!' );
index 6ccd0e1a6900d0204f81786236a6874af77e1082..4ecdade29fb42b698f217a07eb551e95feff949a 100644 (file)
@@ -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(<<EOM);
-Error parsing --trailing-comma-style='$option':
+Error parsing --want-trailing-commas='$option':
 $error_message
 EOM
         }