From 6880efdae091441d550c750a14bbf0a62d6944f0 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 24 Aug 2023 10:36:06 -0700 Subject: [PATCH] activate ProhibitUnusedCapture and ProhibitCaptureWithoutTest 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 | 5 ----- lib/Perl/Tidy.pm | 2 +- lib/Perl/Tidy/Formatter.pm | 9 +++++---- lib/Perl/Tidy/Tokenizer.pm | 6 +++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index b6a2fc8f..a8133409 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -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] diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 4c1e51dd..ff72fad2 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -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(<)/ + && $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); -- 2.39.5