]> git.donarmstrong.com Git - perltidy.git/commitdiff
use uniform paren style for several keywords
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 1 Oct 2024 14:08:33 +0000 (07:08 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 1 Oct 2024 14:08:33 +0000 (07:08 -0700)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/HtmlWriter.pm
lib/Perl/Tidy/IOScalar.pm
lib/Perl/Tidy/IOScalarArray.pm
lib/Perl/Tidy/Tokenizer.pm
lib/Perl/Tidy/VerticalAligner.pm
perltidyrc

index a85c78301aba6d6050948373b9b40e4f25b10e08..30c835525e66f144b4afdfa2b731df295e73a06e 100644 (file)
@@ -801,7 +801,7 @@ EOM
     # see if ARGV is overridden
     if ( defined($argv) ) {
 
-        my $rargv = ref $argv;
+        my $rargv = ref($argv);
         if ( $rargv eq 'SCALAR' ) { $argv = ${$argv}; $rargv = undef }
 
         # ref to ARRAY
@@ -1239,7 +1239,7 @@ sub check_in_place_modify {
     if ($in_place_modify) {
         if (   $rOpts->{'standard-output'}
             || $destination_stream
-            || ref $source_stream
+            || ref($source_stream)
             || $rOpts->{'outfile'}
             || defined( $rOpts->{'output-path'} ) )
         {
@@ -4984,21 +4984,21 @@ EOM
     # seen as 2 parameters, vtc and 1, so the abbreviations
     # won't be seen.  Therefore, we will catch them here if
     # they get through.
-    if ( defined $rOpts->{'vertical-tightness'} ) {
+    if ( defined( $rOpts->{'vertical-tightness'} ) ) {
         my $vt = $rOpts->{'vertical-tightness'};
         $rOpts->{'paren-vertical-tightness'}          = $vt;
         $rOpts->{'square-bracket-vertical-tightness'} = $vt;
         $rOpts->{'brace-vertical-tightness'}          = $vt;
     }
 
-    if ( defined $rOpts->{'vertical-tightness-closing'} ) {
+    if ( defined( $rOpts->{'vertical-tightness-closing'} ) ) {
         my $vtc = $rOpts->{'vertical-tightness-closing'};
         $rOpts->{'paren-vertical-tightness-closing'}          = $vtc;
         $rOpts->{'square-bracket-vertical-tightness-closing'} = $vtc;
         $rOpts->{'brace-vertical-tightness-closing'}          = $vtc;
     }
 
-    if ( defined $rOpts->{'closing-token-indentation'} ) {
+    if ( defined( $rOpts->{'closing-token-indentation'} ) ) {
         my $cti = $rOpts->{'closing-token-indentation'};
         $rOpts->{'closing-square-bracket-indentation'} = $cti;
         $rOpts->{'closing-brace-indentation'}          = $cti;
index 7551f52a955825d53311108f3bd3aa07dedaab14..e92f0fbcc0d87e4bc4b2898089361c6ba964c0ae 100644 (file)
@@ -1987,7 +1987,7 @@ sub initialize_weld_nested_exclusion_rules {
     my $msg2;
     foreach my $item (@items) {
         my $item_save = $item;
-        my $tok       = chop($item);
+        my $tok       = chop $item;
         my $key       = $token_keys{$tok};
         if ( !defined($key) ) {
             $msg1 .= " '$item_save'";
@@ -12819,7 +12819,7 @@ sub respace_tokens_inner_loop {
 
                 # remember the new K of this package; this may be
                 # off by 1 if a blank gets inserted before it
-                push @{$rK_package_list}, scalar @{$rLL_new};
+                push @{$rK_package_list}, scalar( @{$rLL_new} );
             }
             elsif ( $type eq 'i' ) {
                 if ( $token eq '@_' && $current_sub_seqno ) {
@@ -12828,13 +12828,13 @@ sub respace_tokens_inner_loop {
                     # off by 1 if a blank gets inserted before it
                     push
                       @{ $rK_AT_underscore_by_sub_seqno->{$current_sub_seqno} },
-                      scalar @{$rLL_new};
+                      scalar( @{$rLL_new} );
                 }
 
                 # Remember new K of the first '$self' in a sub for -dma option
                 if ( $token eq '$self' && $current_sub_seqno ) {
                     $rK_first_self_by_sub_seqno->{$current_sub_seqno} ||=
-                      scalar @{$rLL_new};
+                      scalar( @{$rLL_new} );
                 }
 
                 # Remember new K and name of blessed objects for -dma option
@@ -12855,7 +12855,7 @@ sub respace_tokens_inner_loop {
                   )
                 {
                     push @{ $rK_bless_by_sub_seqno->{$current_sub_seqno} },
-                      [ scalar @{$rLL_new}, $token ];
+                      [ scalar( @{$rLL_new} ), $token ];
                 }
             }
             elsif ( $type eq 'w' ) {
@@ -12878,12 +12878,12 @@ sub respace_tokens_inner_loop {
                 # off by 1 if a blank gets inserted before it
                 push
                   @{ $rK_return_by_sub_seqno->{$current_sub_seqno} },
-                  scalar @{$rLL_new};
+                  scalar( @{$rLL_new} );
             }
             if ( $token eq 'wantarray' ) {
                 push
                   @{ $rK_wantarray_by_sub_seqno->{$current_sub_seqno} },
-                  scalar @{$rLL_new};
+                  scalar( @{$rLL_new} );
             }
         }
 
@@ -22503,7 +22503,7 @@ EOM
         return unless ($rOpts_kgb_inside);
 
         # loop over sub-groups, index k
-        push @subgroup, scalar @group;
+        push @subgroup, scalar(@group);
         my $kbeg = 1;
         my $kend = @subgroup - 1;
         foreach my $k ( $kbeg .. $kend ) {
@@ -32350,7 +32350,7 @@ EOM
 
             # How many spaces across the page will we fill?
             my $columns_per_line =
-              ( int $number_of_fields / 2 ) * $pair_width +
+              int( $number_of_fields / 2 ) * $pair_width +
               ( $number_of_fields % 2 ) * $max_width;
 
             print {*STDOUT}
@@ -32845,9 +32845,9 @@ EOM
         #------------------------------------------------------------------
 
         # How many lines will this require?
-        my $formatted_lines = $item_count / ($number_of_fields);
-        if ( $formatted_lines != int $formatted_lines ) {
-            $formatted_lines = 1 + int $formatted_lines;
+        my $formatted_lines = $item_count / $number_of_fields;
+        if ( $formatted_lines != int($formatted_lines) ) {
+            $formatted_lines = 1 + int($formatted_lines);
         }
 
         # So far we've been trying to fill out to the right margin.  But
@@ -39681,7 +39681,7 @@ sub set_vertical_tightness_flags {
             next unless ( $matching_char{$char} );
 
             # pop most recently appended character
-            my $top = chop($csc);
+            my $top = chop $csc;
 
             # push it back plus the mate to the newest character
             # unless they balance each other.
index 5d8fd9b6392fee16237bea85e2336e66b920afeb..cdd75e5a613dddefd5394c86ed42e82c49f96e35 100644 (file)
@@ -678,9 +678,9 @@ sub set_default_properties {
     set_default_color( "html-color-$short_to_long_names{$short_name}", $color );
     my $key;
     $key           = "html-bold-$short_to_long_names{$short_name}";
-    $rOpts->{$key} = ( defined $rOpts->{$key} ) ? $rOpts->{$key} : $bold;
+    $rOpts->{$key} = defined( $rOpts->{$key} ) ? $rOpts->{$key} : $bold;
     $key           = "html-italic-$short_to_long_names{$short_name}";
-    $rOpts->{$key} = ( defined $rOpts->{$key} ) ? $rOpts->{$key} : $italic;
+    $rOpts->{$key} = defined( $rOpts->{$key} ) ? $rOpts->{$key} : $italic;
     return;
 } ## end sub set_default_properties
 
@@ -760,7 +760,7 @@ sub pod_to_html {
         # Must clean up if pod2html dies (it can);
         # Be careful not to overwrite callers __DIE__ routine
         local $SIG{__DIE__} = sub {
-            unlink $tmpfile if -e $tmpfile;
+            unlink($tmpfile) if -e $tmpfile;
             Perl::Tidy::Die( $_[0] );
         };
 
@@ -903,7 +903,7 @@ sub pod_to_html {
 
             # Intermingle code and pod sections if we saw multiple =cut's.
             if ( $self->{_pod_cut_count} > 1 ) {
-                my $rpre_string = shift( @{$rpre_string_stack} );
+                my $rpre_string = shift @{$rpre_string_stack};
                 if ( ${$rpre_string} ) {
                     $html_print->('<pre>');
                     $html_print->( ${$rpre_string} );
@@ -937,7 +937,7 @@ sub pod_to_html {
                 if ( $self->{_pod_cut_count} <= 1 ) {
                     $html_print->('<hr />');
                 }
-                while ( my $rpre_string = shift( @{$rpre_string_stack} ) ) {
+                while ( my $rpre_string = shift @{$rpre_string_stack} ) {
                     $html_print->('<pre>');
                     $html_print->( ${$rpre_string} );
                     $html_print->('</pre>');
index 358c040e72e588299bda390d3548c25500a7994f..7829379b727d71aebeb22cc78ea22d8ba97260e5 100644 (file)
@@ -47,7 +47,7 @@ sub DESTROY {
 
 sub new {
     my ( $package, $rscalar, $mode ) = @_;
-    my $ref = ref $rscalar;
+    my $ref = ref($rscalar);
     if ( $ref ne 'SCALAR' ) {
         confess <<EOM;
 ------------------------------------------------------------------------
index 210f30ada83b5ec223197c11a4efed2dd0813267..b6aedd4f2a87ca466085f736a8c718eb0ef2649e 100644 (file)
@@ -50,7 +50,7 @@ sub DESTROY {
 
 sub new {
     my ( $package, $rarray, $mode ) = @_;
-    my $ref = ref $rarray;
+    my $ref = ref($rarray);
     if ( $ref ne 'ARRAY' ) {
         confess <<EOM;
 ------------------------------------------------------------------------
index fca14ba6635ed565e7d8276039af3d4dab7767fe..c34f47076fe08c2e69d494c4921aef7c485c3d9e 100644 (file)
@@ -1232,7 +1232,7 @@ sub get_line {
     # Find and remove what characters terminate this line, including any
     # control r
     my $input_line_separator = EMPTY_STRING;
-    if ( chomp($input_line) ) {
+    if ( chomp $input_line ) {
         $input_line_separator = $INPUT_RECORD_SEPARATOR;
     }
 
@@ -1891,7 +1891,7 @@ sub prepare_for_a_new_file {
     $paren_depth              = 0;
     $brace_depth              = 0;
     $square_bracket_depth     = 0;
-    $rcurrent_depth           = [ (0) x scalar @closing_brace_names ];
+    $rcurrent_depth           = [ (0) x scalar(@closing_brace_names) ];
     $total_depth              = 0;
     $rtotal_depth             = [];
     $rcurrent_sequence_number = [];
index c4890852cf891e96dd8b38a5ec3c70e63639c605..f2519e0ff8310399031f44a50caefa816351c07f 100644 (file)
@@ -4920,7 +4920,7 @@ sub min_max_median {
 
     my $min  = $sorted[0];
     my $max  = $sorted[-1];
-    my $imid = int $num / 2;
+    my $imid = int( $num / 2 );
     my $median =
         @sorted % 2
       ? $sorted[$imid]
index 556c0a4655e42b6e2807d726ba57cd8512fbd23b..93fa710515bff152766fe6d1a0249d89c096cb9a 100644 (file)
@@ -32,8 +32,9 @@
 --closing-side-comments
 --closing-side-comment-list='sub asub'
 
-# remove non-bare trailing commas (followed by paren)
+# remove non-bare trailing commas
 # add trailing commas to key=>value hash lists
+# The + - notation requires version >= 20240903.03
 --want-trailing-commas='-b +h'
 --delete-trailing-commas
 --add-trailing-commas
@@ -41,3 +42,7 @@
 # For now, require arrows at asymmetric bracket combinations
 --add-interbracket-arrows
 --interbracket-arrow-style=']->{ }->['
+
+# use 'perltidy -dmcp filename' to find mixed call paren usage
+# prefer call parens for these keywords:
+--want-call-parens='open unlink substr defined ref scalar int'