From b16238389c83e3416feed83297ce84b66ee09ba0 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 14 Feb 2024 16:57:09 -0800 Subject: [PATCH] adjust -drc for repeated commas across line breaks --- bin/perltidy | 16 ++++++---------- lib/Perl/Tidy/Formatter.pm | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index cc44d3e9..c6853af9 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3714,15 +3714,10 @@ actions taken when this flag is set are as follows: =item * -Repeated commas like ',,' on the same line are removed with a warning. +Repeated commas like ',,' 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. +Repeated fat commas like '=> =>' are removed with a warning. =item * @@ -3731,12 +3726,13 @@ likely an error but only its author would know how to fix it). =item * -Note that the remaining combination ',=>' (sometimes called a -'winking fat comma') is ignored by this parameter. +The remaining combination ',=>' (sometimes called a 'winking fat comma') is +ignored by this parameter. =item * -These warnings are only output if the B<-w> flag is set. +These warnings are only output if the B<--warning-output>, or B<-w>, flag is +set. =back diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0b3d93a2..7393537d 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -11326,19 +11326,16 @@ EOM && $rOpts->{'delete-repeated-commas'} ) { - # 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' + # Do not delete the leading comma of a line with a side + # comment. This could promote the side comment to a block + # comment. See test 'mangle4.in' my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_]; - if ( $KK == $Kfirst ) { + if ( $KK eq $Kfirst && $rLL->[$Klast]->[_TYPE_] eq '#' ) { complain( - "repeated commas across multiple lines, not deleted\n", - $lno - ); + "repeated comma before side comment, 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; } @@ -11373,13 +11370,13 @@ EOM # 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' + # Do not delete the leading fat comma of a line with a side + # comment. This could promote the side comment to a block + # comment. See test 'mangle4.in' my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_]; - if ( $KK == $Kfirst ) { + if ( $KK eq $Kfirst && $rLL->[$Klast]->[_TYPE_] eq '#' ) { complain( - "-repeated '=>' acriss multiple lines, not deleted\n", + "-repeated '=>' before side comment, not deleted\n", $lno ); } else { -- 2.39.5