]> git.donarmstrong.com Git - perltidy.git/commitdiff
activate ProhibitUnusedCapture and ProhibitCaptureWithoutTest
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Aug 2023 17:36:06 +0000 (10:36 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Aug 2023 17:36:06 +0000 (10:36 -0700)
This makes a few changes to allow perltidy to pass these these tests. But
PerlCritic misses many of these, so I'll fix them as I find them.

.perlcriticrc
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index b6a2fc8f63c74abd6449e1832965bbf8a552e25c..a8133409782af897758484582e1192141f27a8b4 100644 (file)
@@ -113,11 +113,6 @@ max_nests=9
 # substr.  So skip this one.
 [-BuiltinFunctions::ProhibitLvalueSubstr]
 
-# There are a few of these in Tidy.pm, Formatter.pm, Tokenizer.pm that
-# could be fixed. Then these lines could be removed.
-[-RegularExpressions::ProhibitUnusedCapture]
-[-RegularExpressions::ProhibitCaptureWithoutTest]
-
 # There is one complex regex in Tokenizer.pm that should be simplified. Then
 # this line can be removed.
 [-RegularExpressions::ProhibitComplexRegexes]
index 4c1e51dd86a6bb70f63571bd48adafcc64daa70c..ff72fad2578b0259d7bbd9dc0429575b0be88368 100644 (file)
@@ -4436,7 +4436,7 @@ sub check_options {
     # Since perltidy only encodes in utf8, problems can occur if we let it
     # decode anything else.  See discussions for issue git #83.
     my $encoding = $rOpts->{'character-encoding'};
-    if ( $encoding !~ /^\s*(guess|none|utf8|utf-8)\s*$/i ) {
+    if ( $encoding !~ /^\s*(?:guess|none|utf8|utf-8)\s*$/i ) {
         Die(<<EOM);
 --character-encoding = '$encoding' is not allowed; the options are: 'none', 'guess', 'utf8'
 EOM
index 454de5b424ca76741ca9504dd73e0778b4883243..0b1b75511713f926bd2d99e7d4fb5cc8dfc0e0fa 100644 (file)
@@ -15053,7 +15053,7 @@ EOM
 
                     # Do not insert a blank after a comment
                     # (this could be subject to a flag in the future)
-                    if ( $code_type !~ /(BC|SBC|SBCX)/ ) {
+                    if ( $code_type !~ /(?:BC|SBC|SBCX)/ ) {
                         if ( $rOpts_kgb_before == INSERT ) {
                             kgb_insert_blank_after( $ibeg - 1 );
 
@@ -31417,9 +31417,10 @@ sub add_closing_side_comment {
                 $old_csc =~ s/\s+//g;            # trim all whitespace
                 $new_csc =~ s/[\]\)\}\s]*$//;    # trim trailing structures
                 $old_csc =~ s/[\]\)\}\s]*$//;    # trim trailing structures
-                $new_csc =~ s/(\.\.\.)$//;       # trim trailing '...'
-                my $new_trailing_dots = $1;
-                $old_csc =~ s/(\.\.\.)\s*$//;    # trim trailing '...'
+
+                # trim trailing '...'
+                my $new_trailing_dots = $new_csc =~ s/\.\.\.$//;
+                $old_csc =~ s/\.\.\.\s*$//;
 
                 # Patch to handle multiple closing side comments at
                 # else and elsif's.  These have become too complicated
index da595ee8f32de2f908ef45fa67d6990e1e31d4eb..9654dd255a5ee60b6e1cda868774fe6cfdfcc9b1 100644 (file)
@@ -2825,7 +2825,7 @@ EOM
                 # NOTE: at present, braces in something like &{ xxx }
                 # are not marked as a block, we might have a method call.
                 # Added ')' to fix case c017, something like ()()()
-                && $last_nonblank_token !~ /^([\]\}\)\&]|\-\>)/
+                && $last_nonblank_token !~ /^(?:[\]\}\)\&]|\-\>)/
               )
             {
 
@@ -4628,7 +4628,7 @@ EOM
             # 'method' in older scripts.
             if ( $tok_kw eq 'method' && $guess_if_method ) {
                 if (   $expecting == OPERATOR
-                    || $next_nonblank_token !~ /^(\w|\:)/
+                    || $next_nonblank_token !~ /^[\w\:]/
                     || !$self->method_ok_here() )
                 {
                     $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
@@ -4656,7 +4656,7 @@ EOM
             #   package($x) - error
             if ( $tok_kw eq 'class' ) {
                 if (   $expecting == OPERATOR
-                    || $next_nonblank_token !~ /^(\w|\:)/
+                    || $next_nonblank_token !~ /^[\w\:]/
                     || !$self->class_ok_here() )
                 {
                     $self->do_UNKNOWN_BAREWORD($next_nonblank_token);