From f99793fdbaeeeeb8e4d16288d007a0244940765d Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 30 Apr 2024 07:47:17 -0700 Subject: [PATCH] remove unused code, update comments --- lib/Perl/Tidy/Formatter.pm | 34 ++++++++++++++------------------ lib/Perl/Tidy/Tokenizer.pm | 18 ----------------- lib/Perl/Tidy/VerticalAligner.pm | 2 -- 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index c92db3c9..56b0faf7 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -12979,12 +12979,15 @@ sub parent_sub_seqno { sub parent_sub_seqno_by_K { my ( $self, $KK ) = @_; + # NOTE: not currently called but keep for possible future development + # Find sequence number of the sub or asub which contains a given token # Given: # $K = index K of a token # Returns: # $seqno of the sub (or asub), or # nothing if no sub found + return unless defined($KK); my $seqno_sub; @@ -13726,7 +13729,6 @@ sub count_sub_args { my $rLL = $self->[_rLL_]; my $K_opening_block = $self->[_K_opening_container_]->{$seqno_block}; my $rlines = $self->[_rlines_]; - my $Klimit = @{$rLL} - 1; my $ix_HERE_END = -1; # Optimization: find the previous type 'S' token with the sub name .. this @@ -14605,13 +14607,11 @@ sub cross_check_call_args { # Skip external method calls next if ( $rcall_item->{is_external_call} ); - my $arg_count = $rcall_item->{arg_count}; - my $package = $rcall_item->{package}; - my $name = $rcall_item->{name}; - my $line_number = $rcall_item->{line_number}; - my $call_type = $rcall_item->{call_type}; - my $caller_name = $rcall_item->{caller_name}; - my $key = $package . '::' . $name; + my $arg_count = $rcall_item->{arg_count}; + my $package = $rcall_item->{package}; + my $name = $rcall_item->{name}; + my $call_type = $rcall_item->{call_type}; + my $key = $package . '::' . $name; my ( $shift_count_min, $shift_count_max, $self_name ); my $seqno_sub = $rsub_seqno_by_key->{$key}; @@ -14689,7 +14689,6 @@ sub cross_check_call_args { my $rdirect_calls = $item->{direct_calls}; my $num_self = defined($rself_calls) ? @{$rself_calls} : 0; my $num_direct = defined($rdirect_calls) ? @{$rdirect_calls} : 0; - my $num_method = defined($rmethod_calls) ? @{$rmethod_calls} : 0; my $shift_count_min = $rsub_item->{shift_count_min}; my $shift_count_max = $rsub_item->{shift_count_max}; @@ -14987,6 +14986,7 @@ sub warn_mismatched_args { # - warn-mismatched-arg-types # - warn-mismatched-arg-exclusion-list # - warn-mismatched-arg-undercount-cutoff + # - warn-mismatched-arg-overcount-cutoff my ( $rwarnings, $hint ) = $self->cross_check_call_args(1); return unless ( $rwarnings && @{$rwarnings} ); @@ -18100,9 +18100,8 @@ EOM # works well but is currently only activated when the -xci flag is set. # The reason is to avoid unexpected changes in formatting. if ($rOpts_extended_continuation_indentation) { - while ( my ( $qw_seqno_x, $rKrange ) = - each %{$rKrange_multiline_qw_by_seqno} ) - { + foreach my $qw_seqno_x ( keys %{$rKrange_multiline_qw_by_seqno} ) { + my $rKrange = $rKrange_multiline_qw_by_seqno->{$qw_seqno_x}; my ( $Kbeg, $Kend ) = @{$rKrange}; # require isolated closing token @@ -18136,9 +18135,8 @@ EOM # multiline quotes if ( $rOpts_line_up_parentheses && !$rOpts_extended_line_up_parentheses ) { - while ( my ( $qw_seqno_x, $rKrange ) = - each %{$rKrange_multiline_qw_by_seqno} ) - { + foreach my $qw_seqno_x ( keys %{$rKrange_multiline_qw_by_seqno} ) { + my $rKrange = $rKrange_multiline_qw_by_seqno->{$qw_seqno_x}; my ( $Kbeg, $Kend ) = @{$rKrange}; my $parent_seqno = $self->parent_seqno_by_K($Kend); next unless ($parent_seqno); @@ -26217,7 +26215,7 @@ sub break_long_lines { #------------------------------------------------------------------ # Find the best next breakpoint based on token-token bond strengths #------------------------------------------------------------------ - my ( $i_lowest, $lowest_strength, $leading_alignment_type, $Msg ) = + my ( $i_lowest, $lowest_strength, $Msg ) = $self->break_lines_inner_loop( $i_begin, @@ -26404,7 +26402,6 @@ sub break_lines_inner_loop { # Returns: # $i_lowest = index of best breakpoint # $lowest_strength = 'bond strength' at best breakpoint - # $leading_alignment_type = special token type after break # $Msg = string of debug info my $Msg = EMPTY_STRING; @@ -26876,7 +26873,7 @@ sub break_lines_inner_loop { # We will break at imax if no other break was found. if ( $i_lowest < 0 ) { $i_lowest = $imax } - return ( $i_lowest, $lowest_strength, $leading_alignment_type, $Msg ); + return ( $i_lowest, $lowest_strength, $Msg ); } ## end sub break_lines_inner_loop sub do_colon_breaks { @@ -32879,7 +32876,6 @@ sub undo_contained_ci { # opening container token does not end a line, and this causes the double # jump. - my $rLL = $self->[_rLL_]; my $max_line = @{$ri_first} - 1; return if ( $max_line < 1 ); diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 77c31ee1..68881b53 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -3652,16 +3652,6 @@ EOM ( $i, $type ) = $self->find_angle_operator_termination( $input_line, $i, $rtoken_map, $expecting, $max_token_index ); - - ## This message is not very helpful and quite confusing if the above - ## routine decided not to write a message with the line number. - ## if ( $type eq '<' && $expecting == TERM ) { - ## $self->error_if_expecting_TERM(); - ## $self->interrupt_logfile(); - ## $self->warning("Unterminated <> operator?\n"); - ## $self->resume_logfile(); - ## } - } else { } @@ -4470,7 +4460,6 @@ EOM elsif ( $tok eq 'elsif' ) { if ( - ## !~ /^(if|elsif|unless)$/ !$is_if_elsif_unless{$last_nonblank_block_type} # Allow isolated blocks of any kind during editing @@ -4495,13 +4484,11 @@ EOM # patched for SWITCH/CASE if ( - ## !~ /^(if|elsif|unless|case|when)$/ !$is_if_elsif_unless_case_when{$last_nonblank_block_type} # patch to avoid an unwanted error message for # the case of a parenless 'case' (RT 105484): # switch ( 1 ) { case x { 2 } else { } } - ## !~ /^(if|elsif|unless|case|when)$/ && !$is_if_elsif_unless_case_when{$statement_type} # Allow isolated blocks of any kind during editing (c272) @@ -6538,7 +6525,6 @@ sub operator_expected { # use Module VERSION LIST # We could avoid this exception by writing a special sub to parse 'use' # statements and perhaps mark these numbers with a new type V (for VERSION) - ##elsif ( $last_nonblank_type =~ /^[nv]$/ ) { if ( $is_n_v{$last_nonblank_type} ) { if ( $statement_type eq 'use' ) { return UNKNOWN; @@ -6958,7 +6944,6 @@ sub decide_if_code_block { # it is a comma which is not a pattern delimiter except for qw ( $pre_types[$j] eq ',' - ## !~ /^(s|m|y|tr|qr|q|qq|qx)$/ && !$is_q_qq_qx_qr_s_y_tr_m{ $pre_tokens[$jbeg] } ) @@ -9066,8 +9051,6 @@ EOM # In something like '$${' we have type '$$' (and only # part of an identifier) && !( $identifier =~ /\$$/ && $tok eq '{' ) - - ## && ( $identifier !~ /^(sub |package )$/ ) && $identifier ne 'sub ' && $identifier ne 'package ' ) @@ -10406,7 +10389,6 @@ sub follow_quoted_string { while ( $i < $max_token_index ) { $tok = $rtokens->[ ++$i ]; - ##if ( $tok !~ /^\s*$/ ) { if ( $rtoken_type->[$i] ne 'b' ) { if ( ( $tok eq '#' ) && ($allow_quote_comments) ) { diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index b47278c8..f8db5b5e 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -4951,7 +4951,6 @@ EOM # Form groups of unsigned numbers from the list of signed numbers. #----------------------------------------------------------------- my @unsigned_subgroups; - my $ix_u = $rsigned_lines->[0]; my $ix_last_negative = $ix_first - 1; my %is_signed; foreach my $ix ( @{$rsigned_lines} ) { @@ -5115,7 +5114,6 @@ EOM my $movable_count = 0; foreach my $item (@unsigned_subgroups) { my ( $ix_min, $ix_max ) = @{$item}; - my $num = $ix_max - $ix_min + 1; foreach my $ix ( $ix_min .. $ix_max ) { my $line = $rgroup_lines->[$ix]; my $leading_space_count = $line->{'leading_space_count'}; -- 2.39.5