From: Steve Hancock Date: Thu, 24 Aug 2023 16:25:40 +0000 (-0700) Subject: activate PC -RegularExpressions::RequireBracesForMultiline X-Git-Tag: 20230701.04~21 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4fdb3d6305d911c2bf83c93f40a4559fae5fcac7;p=perltidy.git activate PC -RegularExpressions::RequireBracesForMultiline --- diff --git a/.perlcriticrc b/.perlcriticrc index f6f7424d..b6a2fc8f 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -162,8 +162,10 @@ max_nests=9 # $self->weld_cuddled_blocks() # } -# The extra braces just add clutter. - +# The first form highlights the most important thing, a sub call, +# and the conditional is just an optimization to skip it if not needed. +# The second form buries the important thing in braces, making it harder +# to see what is going on. [-ControlStructures::ProhibitPostfixControls] # Sometimes an unless statement is clearer than an if block, so why not use @@ -197,9 +199,6 @@ max_nests=9 # you have a comparison of the form $b->[*] <=> $a->[*]. So skip this. [-BuiltinFunctions::ProhibitReverseSortBlock] -# There are a few of these in perltidy that should be changed. -[-RegularExpressions::RequireBracesForMultiline] - # There are too many of these in perltidy to change, and they seem fine. [-RegularExpressions::ProhibitEscapedMetacharacters] diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 3e700190..4c1e51dd 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -4830,7 +4830,7 @@ sub check_vms_filename { $base =~ s/;-?\d*$// # remove explicit . version ie two dots in filename NB ^ escapes a dot - or $base =~ s/( # begin capture $1 + or $base =~ s{( # begin capture $1 (?:^|[^^])\. # match a dot not preceded by a caret (?: # followed by nothing | # or @@ -4838,7 +4838,7 @@ sub check_vms_filename { ) ) # end capture $1 \.-?\d*$ # match . version number - /$1/x; + }{$1}x; # normalize filename, if there are no unescaped dots then append one $base .= '.' unless $base =~ /(?:^|[^^])\./; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7212d7ab..454de5b4 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7778,10 +7778,10 @@ sub set_CODE_type { # example: '# line 42 "new_filename.plx"' if ( $no_leading_space - && $input_line =~ /^\# \s* + && $input_line =~ m{^\# \s* line \s+ (\d+) \s* (?:\s("?)([^"]+)\2)? \s* - $/x + $}x ) { $is_static_block_comment = 1; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index a7457dd8..da595ee8 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -2449,10 +2449,10 @@ EOM # TEST 1: look a valid sub NAME if ( - $input_line =~ m/\G\s* + $input_line =~ m{\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required - /gcx + }gcx ) { # For possible future use.. @@ -2528,10 +2528,10 @@ EOM # TEST 2: look for a valid NAME if ( - $input_line =~ m/\G\s* + $input_line =~ m{\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required - /gcx + }gcx ) { # For possible future use.. @@ -8661,10 +8661,10 @@ EOM # Look for the sub NAME if this is a SUB call if ( $call_type == SUB_CALL - && $input_line =~ m/\G\s* + && $input_line =~ m{\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required - /gcx + }gcx ) { $match = 1; @@ -8731,9 +8731,9 @@ EOM # $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))? # PROTO my $saw_opening_paren = $input_line =~ /\G\s*\(/; if ( - $input_line =~ m/\G(\s*\([^\)\(\}\{\,#A-Za-z]*\))? # PROTO + $input_line =~ m{\G(\s*\([^\)\(\}\{\,#A-Za-z]*\))? # PROTO (\s*:)? # ATTRS leading ':' - /gcx + }gcx && ( $1 || $2 ) ) { @@ -9395,9 +9395,9 @@ EOM # /\G[+-]?0(([xX][0-9a-fA-F_]+)|([0-7_]+)|([bB][01_]+))/g ) # (hex) (octal) (binary) if ( - $input_line =~ + $input_line =~ m{ - /\G[+-]?0( # leading [signed] 0 + \G[+-]?0( # leading [signed] 0 # a hex float, i.e. '0x0.b17217f7d1cf78p0' ([xX][0-9a-fA-F_]* # X and optional leading digits @@ -9426,7 +9426,7 @@ EOM # or binary integer |([bB][01_]+) # 'b' with string of binary digits - )/gx + )}gx ) { $pos = pos($input_line); @@ -10024,12 +10024,14 @@ sub pre_tokenize { while ( $max_tokens_wanted-- ) { if ( - $str =~ /\G( - (\s+) # type 'b' = whitespace - this must come before \W - | (\W) # or type=char = single-character, non-whitespace punct - | (\d+) # or type 'd' = sequence of digits - must come before \w - | (\w+) # or type 'w' = words not starting with a digit - )/gcx + $str =~ m{ + \G( + (\s+) # type 'b' = whitespace - this must come before \W + | (\W) # or type=char = single-character, non-whitespace punct + | (\d+) # or type 'd' = sequence of digits - must come before \w + | (\w+) # or type 'w' = words not starting with a digit + ) + }gcx ) { push @tokens, $1;