From: Steve Hancock Date: Tue, 13 Feb 2024 16:01:57 +0000 (-0800) Subject: adjust -vsn rules X-Git-Tag: 20240202.02~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1f0a04c3cd5fb6fa301f7f0e91f48bea247ed7d7;p=perltidy.git adjust -vsn rules --- diff --git a/bin/perltidy b/bin/perltidy index ab431fb0..9048ee4e 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3736,7 +3736,7 @@ by this parameter. =item * -These warnings are only output if the B<--warnings> flag is set. +These warnings are only output if the B<-w> flag is set. =back diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 2fe8e380..5d0f5624 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1094,7 +1094,7 @@ EOM } my $logfile_header = make_logfile_header( $rOpts, $config_file, - $rraw_options, $Windows_type, $readable_options, ); + $rraw_options, $Windows_type, $readable_options ); # Store some values needed by lower level routines $self->[_diagnostics_object_] = $diagnostics_object; @@ -4340,7 +4340,7 @@ q(wbb=% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= # Uncomment next line to dump all expansions for debugging: # dump_short_names(\%expansion); return ( \@option_string, \@defaults, \%expansion, \%option_category, - \%option_range, \%integer_option_range, ); + \%option_range, \%integer_option_range ); } ## end sub generate_options @@ -4406,7 +4406,7 @@ sub _process_command_line { else { $glc = undef } my ( $roption_string, $rdefaults, $rexpansion, - $roption_category, $roption_range, $rinteger_option_range, ) + $roption_category, $roption_range, $rinteger_option_range ) = generate_options(); #-------------------------------------------------------------- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 17077de3..0b3d93a2 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4864,7 +4864,7 @@ EOM my ( $block_type, $i_next, $i_next_nonblank, $next_nonblank_token, $next_nonblank_type, $next_token, $next_type, - $total_nesting_depth, ); + $total_nesting_depth ); # main loop to compute bond strengths between each pair of tokens foreach my $i ( 0 .. $max_index_to_go ) { @@ -11349,6 +11349,9 @@ EOM my $lno = 1 + $rLL->[$KK]->[_LINE_INDEX_]; complain( "found '=>,' ... error?\n", $lno ); } + else { + # not a repeated comma type + } # remember input line index of first comma if -wtc is used if (%trailing_comma_rules) { diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 96265d1a..b7cc49fa 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -1953,7 +1953,7 @@ sub prepare_for_a_new_file { # TV3: SCALARS for quote variables. These are initialized with a # subroutine call and continually updated as lines are processed. my ( $in_quote, $quote_type, $quote_character, $quote_pos, $quote_depth, - $quoted_string_1, $quoted_string_2, $allowed_quote_modifiers, ); + $quoted_string_1, $quoted_string_2, $allowed_quote_modifiers ); # TV4: SCALARS for multi-line identifiers and # statements. These are initialized with a subroutine call diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index bc01ec6a..d1d1f89e 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -220,6 +220,7 @@ my ( $rOpts_tabs, $rOpts_entab_leading_whitespace, $rOpts_fixed_position_side_comment, + $rOpts_maximum_line_length, $rOpts_minimum_space_to_comment, $rOpts_valign_code, $rOpts_valign_block_comments, @@ -292,6 +293,7 @@ sub check_options { $rOpts_fixed_position_side_comment = $rOpts->{'fixed-position-side-comment'}; + $rOpts_maximum_line_length = $rOpts->{'maximum-line-length'}; $rOpts_minimum_space_to_comment = $rOpts->{'minimum-space-to-comment'}; $rOpts_valign_code = $rOpts->{'valign-code'}; $rOpts_valign_block_comments = $rOpts->{'valign-block-comments'}; @@ -4917,14 +4919,19 @@ EOM return; } - # Form groups of unsigned numbers from the list of signed numbers. Exclude - # groups with more than about 20 consecutive numbers. Little visual + #----------------------------------------------------------------- + # Form groups of unsigned numbers from the list of signed numbers. + #----------------------------------------------------------------- + + # Exclude groups with more than about 20 consecutive numbers. Little visual # improvement is gained by padding more than this, and this avoids # large numbers of differences in a file when a single line is changed. my @unsigned_subgroups; my $ix_u = $rsigned_lines->[0]; my $ix_last_negative = $ix_first - 1; + my %is_signed; foreach my $ix ( @{$rsigned_lines} ) { + $is_signed{$ix} = 1; my $Nu = $ix - $ix_last_negative - 1; if ( $Nu > 0 && $Nu <= $rOpts_valign_signed_numbers_limit ) { push @unsigned_subgroups, [ $ix_last_negative + 1, $ix - 1 ]; @@ -4938,7 +4945,59 @@ EOM if ( !@unsigned_subgroups ) { return } # shouldn't happen + #--------------------------------------------------------------- + # Check number lengths; do not pad some irregular number lengths + #--------------------------------------------------------------- + + # Compute range of number lengths. The 'field_lengths' are unreliable + # because they may include some arbitrary trailing text; see 'substr.t' + my $max_unsigned_length = 0; + my $max_signed_length = 0; + my $min_unsigned_length = $rOpts_maximum_line_length; + my $min_signed_length = $rOpts_maximum_line_length; + foreach my $ix ( $ix_first .. $ix_last ) { + my $line = $rgroup_lines->[$ix]; + my $rfield = $line->{'rfields'}; + my $str = substr( $rfield->[$jcol], $pos_start_number ); + if ( $str =~ /^([^\s\,\)\]\}]*)/ ) { $str = $1 } + my $len = length($str); + if ( $is_signed{$ix} ) { + if ( $len > $max_signed_length ) { $max_signed_length = $len } + if ( $len < $min_signed_length ) { $min_signed_length = $len } + } + else { + if ( $len > $max_unsigned_length ) { $max_unsigned_length = $len } + if ( $len < $min_unsigned_length ) { $min_unsigned_length = $len } + } + } + + # Is this an isolated column of leading values? + my $is_single_col; + if ( $jcol == 0 && $pos_start_number == 0 ) { + my $line_first = $rgroup_lines->[$ix_first]; + my $jmax = $line_first->{jmax}; + $is_single_col = $jmax == 1; + } + + # Skip padding if no signed numbers exceed unsigned numbers in length + # For example, a column of two digit unsigned numbers with some -1's + if ( $max_signed_length <= $min_unsigned_length ) { + return; + } + + # Skip padding if max unsigned length exceeds max signed length and + # this is a large table, or a single leading column. + if ( $max_unsigned_length > $max_signed_length ) { + if ( $is_single_col + || $unsigned + $signed > $rOpts_valign_signed_numbers_limit ) + { + return; + } + } + + #-------------------------------------- # Compute available space for each line + #-------------------------------------- my %excess_space; foreach my $item (@unsigned_subgroups) { my ( $ix_min, $ix_max ) = @{$item}; @@ -4960,8 +5019,9 @@ EOM $jcol == 0 ? $leading_space_count : $alignments[ $jcol - 1 ]->{'column'}; - my $avail = $col - $col_start; - $excess_space{$ix} = $avail - $rfield_lengths->[$jcol]; + my $avail = $col - $col_start; + my $field_length = $rfield_lengths->[$jcol]; + $excess_space{$ix} = $avail - $field_length; } } @@ -4979,10 +5039,12 @@ EOM return; } - # Go ahead and insert an extra space before the unsigned numbers - # if space is available + #------------------------------------------------------------------------ + # Insert an extra space before the unsigned numbers if space is available + #------------------------------------------------------------------------ foreach my $item (@unsigned_subgroups) { my ( $ix_min, $ix_max ) = @{$item}; + foreach my $ix ( $ix_min .. $ix_max ) { next if ( $excess_space{$ix} <= 0 ); my $line = $rgroup_lines->[$ix]; @@ -6070,7 +6132,7 @@ sub get_output_line_number { } } return ( $str, $str_length, $leading_string, $leading_string_length, - $leading_space_count, $level, $maximum_line_length, ); + $leading_space_count, $level, $maximum_line_length ); } ## end sub handle_cached_line diff --git a/perltidyrc b/perltidyrc index 6600fdac..6af5e92e 100644 --- a/perltidyrc +++ b/perltidyrc @@ -22,13 +22,13 @@ --closing-side-comments --closing-side-comment-list='sub' -# add trailing commas to last item of a bare hash list ---want-trailing-commas='h' ---add-trailing-commas +# remove trailing commas followed by paren +--want-trailing-commas='b' +--delete-trailing-commas # this should eventually become the default --delete-repeated-commas -# This will become -ias='*' +# For now, require arrows at asymmetric bracket combinations --add-interbracket-arrows --interbracket-arrow-style=']->{ }->['