From: Steve Hancock Date: Tue, 1 Oct 2024 14:08:33 +0000 (-0700) Subject: use uniform paren style for several keywords X-Git-Tag: 20240903.04~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=39c8010f54f3f2703afc690ea0463f9d7036604b;p=perltidy.git use uniform paren style for several keywords --- diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index a85c7830..30c83552 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -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; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7551f52a..e92f0fbc 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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. diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index 5d8fd9b6..cdd75e5a 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -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->('
');
                     $html_print->( ${$rpre_string} );
@@ -937,7 +937,7 @@ sub pod_to_html {
                 if ( $self->{_pod_cut_count} <= 1 ) {
                     $html_print->('
'); } - while ( my $rpre_string = shift( @{$rpre_string_stack} ) ) { + while ( my $rpre_string = shift @{$rpre_string_stack} ) { $html_print->('
');
                     $html_print->( ${$rpre_string} );
                     $html_print->('
'); diff --git a/lib/Perl/Tidy/IOScalar.pm b/lib/Perl/Tidy/IOScalar.pm index 358c040e..7829379b 100644 --- a/lib/Perl/Tidy/IOScalar.pm +++ b/lib/Perl/Tidy/IOScalar.pm @@ -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 <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'