]> git.donarmstrong.com Git - perltidy.git/commitdiff
adjust -vsn rules
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Feb 2024 16:01:57 +0000 (08:01 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Feb 2024 16:01:57 +0000 (08:01 -0800)
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm
lib/Perl/Tidy/VerticalAligner.pm
perltidyrc

index ab431fb0262c77cd3883702cf473805a8c84ff82..9048ee4e2df91787a534dcfb9c43a1aee042c51d 100755 (executable)
@@ -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
 
index 2fe8e3805aa0faa60038382342a5af6979e4a915..5d0f56246b9a3269c621d213f09366fd414b914a 100644 (file)
@@ -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();
 
     #--------------------------------------------------------------
index 17077de3be5801eb50aaff44c7a22c537ce30669..0b3d93a24087c70af56437fcde2592a1d7a80b0c 100644 (file)
@@ -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) {
index 96265d1a1b8b26e7a046403dd6cf3d4e3d5697da..b7cc49fae69a186e4a855ed0380bd950edb1eb69 100644 (file)
@@ -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
index bc01ec6a3625fae4c2dc140911abea4115f9e2ee..d1d1f89eabb8dbd290cf58daf9e9245c62be539b 100644 (file)
@@ -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
 
index 6600fdacbc86741f1835205bcdeb9ebaa99205a1..6af5e92e6455a0b2a0f3534d114f9b5f5a2c8696 100644 (file)
 --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=']->{ }->['