]> git.donarmstrong.com Git - perltidy.git/commitdiff
update -drc to delete repeated fat commas
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Feb 2024 02:32:18 +0000 (18:32 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Feb 2024 02:32:18 +0000 (18:32 -0800)
CHANGES.md
bin/perltidy
lib/Perl/Tidy/Formatter.pm

index 122432b7ee3ad07d420c6504030a124fcfc47a6a..719c42c89fa977ac17519c75084fffa45acfc825 100644 (file)
@@ -2,6 +2,17 @@
 
 ## 2024 02 02.01
 
+    - The option --delete-repeated-commas, -drc has been expanded as follows:
+      - Repeated commas like ',,' on the same line are removed with a warning
+      - Repeated fat commas like '=> =>' on the same line are removed with a
+        warning
+      - Repeated commas and fat commas on different lines remain unchanged
+        but produce a warning
+      - The combination '=>,' produces a warning but is not changed (it is
+        likely a serious error but only its author would know how to fix it).
+      These warnings are only output if the --warnings flag is set.
+      The -drc option is off by default; this could change in the future.
+
     - Added control --delete-interbracket-arrows, or -dia, to delete optional
       hash ref and array ref arrows between brackets as in the following
       expression (see git #131)
index 97e4b865ea72d53af8059f0496c1f80720d9d088..ab431fb0262c77cd3883702cf473805a8c84ff82 100755 (executable)
@@ -3707,8 +3707,40 @@ we can remove it with -drc
       # perltidy -drc:
       ignoreSpec( $file, "file", \%spec, \%Rspec );
 
-Since the default is not to add or delete commas, this feature is off by default and must be requested.
+This parameter also deletes repeated fat commas, '=>'. The complete list of
+actions taken when this flag is set are as follows:
 
+=over 4
+
+=item *
+
+Repeated commas like ',,' on the same line are removed with a warning.
+
+=item *
+Repeated fat commas like '=> =>' on the same line are removed with a warning.
+
+=item *
+
+Repeated commas and fat commas on different lines remain unchanged
+but produce a warning.
+
+=item *
+
+The combination '=>,' produces a warning but is not changed (it is
+likely an error but only its author would know how to fix it).
+
+=item *
+
+Note that the special combination ',=>' ('winking fat comma') is ignored
+by this parameter.
+
+=item *
+
+These warnings are only output if the B<--warnings> flag is set.
+
+=back
+
+This feature is currently off by default and must be requested.
 
 =item B<--want-trailing-commas=s> or B<-wtc=s>, B<--add-trailing-commas> or B<-atc>, and B<--delete-trailing-commas> or B<-dtc>
 
index 173a029e4fc82d7673d0bfb9d955c0d737144ba5..4dd8280889072be80e21a018400a7f94bd2535a5 100644 (file)
@@ -11329,15 +11329,26 @@ EOM
                 # do not delete a comma repeated on a different line -
                 # this can cause problems, such as promoting a side comment
                 # to a block comment. See test 'mangle4.in'
+                my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_];
                 if ( $KK == $Kfirst ) {
-                    ## but a warning could be issued
+                    complain(
+                        "repeated commas across multiple lines, not deleted\n",
+                        $lno
+                    );
                 }
                 else {
                     # Could note this deletion as a possible future update:
                     ## $self->note_deleted_comma($input_line_number);
+                    complain( "deleted repeated ','\n", $lno );
                     next;
                 }
             }
+            elsif ($last_nonblank_code_type eq '=>'
+                && $rOpts->{'delete-repeated-commas'} )
+            {
+                my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_];
+                complain( "found '=>,' ... error?\n", $lno );
+            }
 
             # remember input line index of first comma if -wtc is used
             if (%trailing_comma_rules) {
@@ -11351,6 +11362,29 @@ EOM
                 }
             }
         }
+        elsif ( $type eq '=>' ) {
+            if (   $last_nonblank_code_type eq '=>'
+                && $rOpts->{'delete-repeated-commas'} )
+            {
+
+                # Check for repeated '=>'s
+                # Note that ',=>' is useful and called a winking fat comma
+
+                # Do not delete a fat comma repeated on a different line -
+                # this can cause problems, such as promoting a side comment
+                # to a block comment. See test 'mangle4.in'
+                my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_];
+                if ( $KK == $Kfirst ) {
+                    complain(
+                        "-repeated '=>' acriss multiple lines, not deleted\n",
+                        $lno );
+                }
+                else {
+                    complain( "deleted repeated '=>'\n", $lno );
+                    next;
+                }
+            }
+        }
 
         # change 'LABEL   :'   to 'LABEL:'
         elsif ( $type eq 'J' ) {