]> git.donarmstrong.com Git - perltidy.git/commitdiff
activate PC -RegularExpressions::RequireBracesForMultiline
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Aug 2023 16:25:40 +0000 (09:25 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Aug 2023 16:25:40 +0000 (09:25 -0700)
.perlcriticrc
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index f6f7424d4c1b7abe9cca59ade9ecb2250902f32f..b6a2fc8f63c74abd6449e1832965bbf8a552e25c 100644 (file)
@@ -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]
 
index 3e7001906db6791f2599bb9ec6696a691b305d8e..4c1e51dd86a6bb70f63571bd48adafcc64daa70c 100644 (file)
@@ -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 =~ /(?:^|[^^])\./;
index 7212d7ab1b6ad243b2ff2c74a157eefbe14b17c6..454de5b424ca76741ca9504dd73e0778b4883243 100644 (file)
@@ -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;
index a7457dd8d26dff59075723c0f1aee4198f65666a..da595ee8f32de2f908ef45fa67d6990e1e31d4eb 100644 (file)
@@ -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;