From: Steve Hancock Date: Tue, 23 Aug 2022 22:32:31 +0000 (-0700) Subject: reduce max_mccabe to 120 X-Git-Tag: 20220613.05~31 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e1a0535fe7c9a1594beeb5e5c652771725634ea6;p=perltidy.git reduce max_mccabe to 120 --- diff --git a/.perlcriticrc b/.perlcriticrc index 14592438..ade791d9 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -80,7 +80,7 @@ short_subroutine_statements = 2 # The max values below can be reduced to locate code which might be simplified. [Subroutines::ProhibitExcessComplexity] -max_mccabe=125 +max_mccabe=120 [ControlStructures::ProhibitDeepNests] max_nests=7 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index b1ca0350..2cc7ae61 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -15173,24 +15173,7 @@ EOM # unmask phantom semicolons #-------------------------- if ( !$tokens_to_go[$imax] && $types_to_go[$imax] eq ';' ) { - my $i = $imax; - my $tok = ';'; - my $tok_len = 1; - if ( $want_left_space{';'} != WS_NO ) { - $tok = ' ;'; - $tok_len = 2; - } - $tokens_to_go[$i] = $tok; - $token_lengths_to_go[$i] = $tok_len; - my $KK = $K_to_go[$i]; - $rLL->[$KK]->[_TOKEN_] = $tok; - $rLL->[$KK]->[_TOKEN_LENGTH_] = $tok_len; - my $line_number = 1 + $rLL->[$KK]->[_LINE_INDEX_]; - $self->note_added_semicolon($line_number); - - foreach ( $imax .. $max_index_to_go ) { - $summed_lengths_to_go[ $_ + 1 ] += $tok_len; - } + $self->unmask_phantom_semicolon($imax); } if ( $rOpts_one_line_block_semicolons == 0 ) { @@ -15242,6 +15225,30 @@ EOM return; } ## end sub grind_batch_of_CODE + sub unmask_phantom_semicolon { + my ( $self, $imax ) = @_; + my $rLL = $self->[_rLL_]; + my $i = $imax; + my $tok = ';'; + my $tok_len = 1; + if ( $want_left_space{';'} != WS_NO ) { + $tok = ' ;'; + $tok_len = 2; + } + $tokens_to_go[$i] = $tok; + $token_lengths_to_go[$i] = $tok_len; + my $KK = $K_to_go[$i]; + $rLL->[$KK]->[_TOKEN_] = $tok; + $rLL->[$KK]->[_TOKEN_LENGTH_] = $tok_len; + my $line_number = 1 + $rLL->[$KK]->[_LINE_INDEX_]; + $self->note_added_semicolon($line_number); + + foreach ( $imax .. $max_index_to_go ) { + $summed_lengths_to_go[ $_ + 1 ] += $tok_len; + } + return; + } + sub save_opening_indentation { # This should be called after each batch of tokens is output. It @@ -20762,46 +20769,19 @@ EOM ) ) { - my $available_spaces = - $self->get_available_spaces_to_go($i_first_comma); - if ( $available_spaces > 0 ) { - - my $spaces_wanted = $max_width - $columns; # for 1 field + ( $number_of_fields, $number_of_fields_best, $columns ) = + $self->lp_table_fix( + + $columns, + $i_first_comma, + $max_width, + $number_of_fields, + $number_of_fields_best, + $odd_or_even, + $pair_width, + $ritem_lengths, - if ( $number_of_fields_best == 0 ) { - $number_of_fields_best = - get_maximum_fields_wanted($ritem_lengths); - } - - if ( $number_of_fields_best != 1 ) { - my $spaces_wanted_2 = - 1 + $pair_width - $columns; # for 2 fields - if ( $available_spaces > $spaces_wanted_2 ) { - $spaces_wanted = $spaces_wanted_2; - } - } - - if ( $spaces_wanted > 0 ) { - my $deleted_spaces = - $self->reduce_lp_indentation( $i_first_comma, - $spaces_wanted ); - - # redo the math - if ( $deleted_spaces > 0 ) { - $columns = table_columns_available($i_first_comma); - $number_of_fields_max = - maximum_number_of_fields( $columns, $odd_or_even, - $max_width, $pair_width ); - $number_of_fields = $number_of_fields_max; - - if ( $number_of_fields_best == 1 - && $number_of_fields >= 1 ) - { - $number_of_fields = $number_of_fields_best; - } - } - } - } + ); } # try for one column if two won't work @@ -21076,6 +21056,66 @@ EOM return; } ## end sub set_comma_breakpoints_do + sub lp_table_fix { + + # try to undo some -lp indentation to improve table formatting + + my ( + + $self, + + $columns, + $i_first_comma, + $max_width, + $number_of_fields, + $number_of_fields_best, + $odd_or_even, + $pair_width, + $ritem_lengths, + + ) = @_; + + my $available_spaces = + $self->get_available_spaces_to_go($i_first_comma); + if ( $available_spaces > 0 ) { + + my $spaces_wanted = $max_width - $columns; # for 1 field + + if ( $number_of_fields_best == 0 ) { + $number_of_fields_best = + get_maximum_fields_wanted($ritem_lengths); + } + + if ( $number_of_fields_best != 1 ) { + my $spaces_wanted_2 = 1 + $pair_width - $columns; # for 2 fields + if ( $available_spaces > $spaces_wanted_2 ) { + $spaces_wanted = $spaces_wanted_2; + } + } + + if ( $spaces_wanted > 0 ) { + my $deleted_spaces = + $self->reduce_lp_indentation( $i_first_comma, + $spaces_wanted ); + + # redo the math + if ( $deleted_spaces > 0 ) { + $columns = table_columns_available($i_first_comma); + $number_of_fields = + maximum_number_of_fields( $columns, $odd_or_even, + $max_width, $pair_width ); + + if ( $number_of_fields_best == 1 + && $number_of_fields >= 1 ) + { + $number_of_fields = $number_of_fields_best; + } + } + } + } + return ( $number_of_fields, $number_of_fields_best, $columns ); + } ## end sub lp_table_fix + sub write_formatted_table { # Write a table of comma separated items with fixed number of fields