From d3e97547d03314943997aab27d07ca270fee7f53 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 15 Nov 2018 07:43:55 -0800 Subject: [PATCH] ran tidyall; updated version number --- .gitignore | 6 +- CHANGES.md | 65 ++++++++++++-- README.md | 56 ++++++++++++- bin/perltidy | 2 +- dev-bin/build.pl | 1 + lib/Perl/Tidy.pm | 8 +- lib/Perl/Tidy.pod | 2 +- lib/Perl/Tidy/Formatter.pm | 140 +++++++++++++++---------------- lib/Perl/Tidy/Tokenizer.pm | 60 ++++++------- lib/Perl/Tidy/VerticalAligner.pm | 60 ++++++------- local-docs/ChangeLog.pod | 27 +++--- local-docs/Release-Checklist.md | 2 +- local-docs/perltidy.md | 8 +- 13 files changed, 275 insertions(+), 162 deletions(-) diff --git a/.gitignore b/.gitignore index bba3e7d6..18c70113 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ *.DEBUG *.ERR *.LOG -*.bak *.ba1 +*.bak *.log *.sw? *.tar.gz @@ -18,12 +18,12 @@ MYMETA.json MYMETA.yml RUNME.sh RUNME.sh -blib/ archive/ +blib/ diff.txt +junk* local_docs/*.txt perltidy-*.pl perltidy.pl pm_to_blib tmp*/ -junk* diff --git a/CHANGES.md b/CHANGES.md index 4d026e41..0a63fa20 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,20 @@ # Perltidy Change Log -## 2018 02 20.01 +## 2018 11 16 + + - The packaging for this version has changed. The Tidy.pm file has + been split into a smaller Tidy.pm file plus supporting modules in the path + Perl/Tidy/*. + + - A number of new installation test cases have been added. + + - Fixed RT #126965, in which a ternary operator was misparsed if immediately + following a function call without arguments, such as: + my $restrict_customer = shift ? 1 : 0; + + - Fixed RT #125012: bug in -mangle --delete-all-comments + A needed blank space bareword tokens was being removed when comments were + deleted - Fixed RT #81852: Stacked containers and quoting operators. Quoted words (qw) delimited by container tokens ('{', '[', '(', '<') are now included in @@ -25,7 +39,10 @@ - Fixed RT #124594, license text desc. changed from 'GPL-2.0+' to 'gpl_2' - - Numerous installation test snippets have been added. + - RT #106493; source code repository is https://github.com/perltidy/perltidy + + - Fixed bug in which a warning about a possible code bug was issued in a + script with brace errors. - added option --notimestamp or -nts to eliminate any time stamps in output files. This is used to prevent differences in test scripts from causing @@ -33,9 +50,47 @@ stamp on certain closing side comments. We need to avoid this in order to test this feature in an installation test. - - The packaging for this version has changed. The Tidy.pm file has - been split into a smaller Tidy.pm file plus supporting modules in the path - Perl/Tidy/*. + - Fixed bug with the entab option, -et=8, in which the leading space of + some lines was was not entabbed. This happened in code which was adjusted + for vertical alignment and in hanging side comments. Thanks to Glenn. + + - Fixed RT #127633, undesirable line break after return when -baao flag is set + + - Vertical alignment has been improved in several ways. Thanks especially to + Glenn for sending helpful snippets. + + - In many cases, two lines which were previously left unaligned are now + aligned. + + OLD: + $expect = "1$expect" if $expect =~ /^e/i; + $p = "1$p" if defined $p and $p =~ /^e/i; + + NEW: + $expect = "1$expect" if $expect =~ /^e/i; + $p = "1$p" if defined $p and $p =~ /^e/i; + + - Alignment of the =~ operators has been reactivated. + + OLD: + $service_profile =~ s/^\s+|\s+$//g; + $host_profile =~ s/^\s+|\s+$//g; + + NEW: + $service_profile =~ s/^\s+|\s+$//g; + $host_profile =~ s/^\s+|\s+$//g; + + - Alignment of the // operator has been reactivated. + + OLD: + is( pop // 7, 7, 'pop // ... works' ); + is( pop() // 7, 0, 'pop() // ... works' ); + is( pop @ARGV // 7, 3, 'pop @array // ... works' ); + + NEW: + is( pop // 7, 7, 'pop // ... works' ); + is( pop() // 7, 0, 'pop() // ... works' ); + is( pop @ARGV // 7, 3, 'pop @array // ... works' ); ## 2018 02 20 diff --git a/README.md b/README.md index 57d0ce5a..3028be44 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,57 @@ # Welcome to Perltidy! -Perltidy is a tool to indent and reformat scripts written in Perl5. +Perltidy is a tool to indent and reformat perl scripts. It can also +write scripts in html format. -Documentation can be found on the [Perltidy GitHub page](https://perltidy.github.io/perltidy/) -and also at the [Perltidy Sourceforge page](http://perltidy.sourceforge.net). +Perltidy is free software released under the GNU General Public +License -- please see the included file "COPYING" for details. +# PREREQUISITES + +`perltidy` should work with most standard Perl installations. +The following modules are not required, but perltidy may use them if +detected: + + HTML::Entities will be used to encode HTML entities if detected + Pod::Html will be used to format pod text + +The total disk space needed after removing the installation directory will +about 2 Mb. + +# DOWNLOAD + +There are two source distribution files: + +- A `.tgz` "tarball", with Unix-style <lf> line endings, and +- A zip file, `.zip`, with Windows-style <cr><lf> line endings. + +In addition, the web site has links to debian and RPM packages. + +# INSTALLATION + +For most standard installations, the standard Makefile.PL method should work: + + perl Makefile.PL + make + make test + make install + +The INSTALL file has additional installation notes, and tells how +to use perltidy without doing an installation. + +# WHAT NEXT + +Please see the CHANGES file for notices of any recent updates. + +Please see the BUGS file for a list of all known open bugs. + +Documentation can be found in the `docs` directory, and it can also be +found at http://perltidy.sourceforge.net + +Reading the brief tutorial should help you use perltidy effectively. + +# FEEDBACK / BUG REPORTS + +A list of current bugs and issues can be found at the CPAN site [https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy](https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy) + +To report a new bug or problem, use the link on this page . diff --git a/bin/perltidy b/bin/perltidy index 242734f8..e7cb7e39 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3461,7 +3461,7 @@ perlstyle(1), Perl::Tidy(3) =head1 VERSION -This man page documents perltidy version 20180220.01 +This man page documents perltidy version 20181116 =head1 BUG REPORTS diff --git a/dev-bin/build.pl b/dev-bin/build.pl index 86183b27..69e8b0d1 100755 --- a/dev-bin/build.pl +++ b/dev-bin/build.pl @@ -141,6 +141,7 @@ sub run_tidyall { $fh->close(); if ( !@errors ) { $rstatus->{'TIDY'} = 'OK'; + $rstatus->{'PC'} = 'TBD'; hitcr("Source OK."); return; } diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index d5f3360b..eb4cd3d9 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -109,7 +109,7 @@ BEGIN { # Release version must be bumped, and it is probably past time for a # release anyway. - $VERSION = '20180220.01'; + $VERSION = '20181116'; } sub streamhandle { @@ -358,7 +358,7 @@ EOM } my $get_hash_ref = sub { - my ($key) = @_; + my ($key) = @_; my $hash_ref = $input_hash{$key}; if ( defined($hash_ref) ) { unless ( ref($hash_ref) eq 'HASH' ) { @@ -1582,7 +1582,7 @@ sub generate_options { $option_category{$opt} = $category_name[$category]; } - $category = 11; # HTML + $category = 11; # HTML $option_category{html} = $category_name[$category]; # routine to install and check options @@ -2751,7 +2751,7 @@ EOM sub find_file_upwards { my ( $search_dir, $search_file ) = @_; - $search_dir =~ s{/+$}{}; + $search_dir =~ s{/+$}{}; $search_file =~ s{^/+}{}; while (1) { diff --git a/lib/Perl/Tidy.pod b/lib/Perl/Tidy.pod index 4daa83f3..b71cef37 100644 --- a/lib/Perl/Tidy.pod +++ b/lib/Perl/Tidy.pod @@ -410,7 +410,7 @@ C in Tidy.pm. =head1 VERSION -This man page documents Perl::Tidy version 20180220.01 +This man page documents Perl::Tidy version 20181116 =head1 LICENSE diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 325fbd79..7bfed3de 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -336,7 +336,7 @@ BEGIN { ); @is_digraph{@q} = (1) x scalar(@q); - @q = qw( ... **= <<= >>= &&= ||= //= <=> <<~ ); + @q = qw( ... **= <<= >>= &&= ||= //= <=> <<~ ); @is_trigraph{@q} = (1) x scalar(@q); @q = qw( @@ -360,22 +360,22 @@ BEGIN { @q = qw(is if unless and or err last next redo return); @is_if_unless_and_or_last_next_redo_return{@q} = (1) x scalar(@q); - @q = qw(last next redo return); + @q = qw(last next redo return); @is_last_next_redo_return{@q} = (1) x scalar(@q); - @q = qw(sort map grep); + @q = qw(sort map grep); @is_sort_map_grep{@q} = (1) x scalar(@q); - @q = qw(sort map grep eval); + @q = qw(sort map grep eval); @is_sort_map_grep_eval{@q} = (1) x scalar(@q); - @q = qw(sort map grep eval do); + @q = qw(sort map grep eval do); @is_sort_map_grep_eval_do{@q} = (1) x scalar(@q); - @q = qw(if unless); + @q = qw(if unless); @is_if_unless{@q} = (1) x scalar(@q); - @q = qw(and or err); + @q = qw(and or err); @is_and_or{@q} = (1) x scalar(@q); # Identify certain operators which often occur in chains. @@ -384,7 +384,7 @@ BEGIN { # Checkbutton => 'Transmission checked', # -variable => \$TRANS # This usually improves appearance so it seems ok. - @q = qw(&& || and or : ? . + - * /); + @q = qw(&& || and or : ? . + - * /); @is_chain_operator{@q} = (1) x scalar(@q); # We can remove semicolons after blocks preceded by these keywords @@ -408,17 +408,17 @@ BEGIN { @ok_to_add_semicolon_for_block_type{@q} = (1) x scalar(@q); # 'L' is token for opening { at hash key - @q = qw< L { ( [ >; + @q = qw< L { ( [ >; @is_opening_type{@q} = (1) x scalar(@q); # 'R' is token for closing } at hash key - @q = qw< R } ) ] >; + @q = qw< R } ) ] >; @is_closing_type{@q} = (1) x scalar(@q); - @q = qw< { ( [ >; + @q = qw< { ( [ >; @is_opening_token{@q} = (1) x scalar(@q); - @q = qw< } ) ] >; + @q = qw< } ) ] >; @is_closing_token{@q} = (1) x scalar(@q); # Patterns for standardizing matches to block types for regular subs and @@ -1391,7 +1391,7 @@ sub set_whitespace_flags { my $ws_in_container = sub { my ($j) = @_; - my $ws = WS_YES; + my $ws = WS_YES; if ( $j + 1 > $jmax ) { return (WS_NO) } # Patch to count '-foo' as single token so that @@ -2162,7 +2162,7 @@ sub respace_tokens { # Insert any essential whitespace between lines # if last line was normal CODE. - # Patch for rt #125012: use K_previous_code rather than '_nonblank' + # Patch for rt #125012: use K_previous_code rather than '_nonblank' # because comments may disappear. my $type_next = $rLL->[$Kfirst]->[_TYPE_]; my $token_next = $rLL->[$Kfirst]->[_TOKEN_]; @@ -2287,7 +2287,7 @@ sub respace_tokens { my $rcopy = copy_token_as_type( $rtoken_vars, 'q', $part1 ); $store_token->($rcopy); - $token = $part2; + $token = $part2; $rtoken_vars->[_TOKEN_] = $token; } @@ -2326,7 +2326,7 @@ sub respace_tokens { $store_token_and_space->( $rcopy, $rwhitespace_flags->[$KK] == WS_YES ); - $token = $part2; + $token = $part2; $rtoken_vars->[_TOKEN_] = $token; # Second part goes without intermediate blank @@ -2538,7 +2538,7 @@ sub respace_tokens { my $rLL = $self->{rLL}; my $Klimit = $self->{Klimit}; - my $CODE_type = $rOpts->{'indent-only'} ? 'IO' : ""; + my $CODE_type = $rOpts->{'indent-only'} ? 'IO' : ""; my $no_internal_newlines = 1 - $rOpts_add_newlines; if ( !$CODE_type && $no_internal_newlines ) { $CODE_type = 'NIN' } @@ -2941,7 +2941,7 @@ sub K_next_nonblank { sub K_previous_code { - # return the index K of the previous nonblank, non-comment token + # return the index K of the previous nonblank, non-comment token # Call with $KK=undef to start search at the top of the array my ( $self, $KK, $rLL ) = @_; @@ -3069,13 +3069,13 @@ sub weld_cuddled_blocks { my $length_to_opening_seqno = sub { my ($seqno) = @_; - my $KK = $K_opening_container->{$seqno}; + my $KK = $K_opening_container->{$seqno}; my $lentot = $KK <= 0 ? 0 : $rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_]; return $lentot; }; my $length_to_closing_seqno = sub { my ($seqno) = @_; - my $KK = $K_closing_container->{$seqno}; + my $KK = $K_closing_container->{$seqno}; my $lentot = $KK <= 0 ? 0 : $rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_]; return $lentot; }; @@ -3084,7 +3084,7 @@ sub weld_cuddled_blocks { # a block is broken if the input line numbers of the braces differ # we can only cuddle between broken blocks - my ($seqno) = @_; + my ($seqno) = @_; my $K_opening = $K_opening_container->{$seqno}; return unless ( defined($K_opening) ); my $K_closing = $K_closing_container->{$seqno}; @@ -3255,14 +3255,14 @@ sub weld_nested_containers { my $length_to_opening_seqno = sub { my ($seqno) = @_; - my $KK = $K_opening_container->{$seqno}; + my $KK = $K_opening_container->{$seqno}; my $lentot = $KK <= 0 ? 0 : $rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_]; return $lentot; }; my $length_to_closing_seqno = sub { my ($seqno) = @_; - my $KK = $K_closing_container->{$seqno}; + my $KK = $K_closing_container->{$seqno}; my $lentot = $KK <= 0 ? 0 : $rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_]; ##my $lentot = $rLL->[$KK]->[_CUMULATIVE_LENGTH_]; return $lentot; @@ -4138,7 +4138,7 @@ sub set_leading_whitespace { ##my $too_close = ($i_test==$max_index_to_go-1); my $test_position = total_line_length( $i_test, $max_index_to_go ); - my $mll = maximum_line_length($i_test); + my $mll = maximum_line_length($i_test); if ( @@ -5544,7 +5544,7 @@ sub make_block_pattern { Warn("unrecognized block type $i after $abbrev, ignoring\n"); } } - my $pattern = '(' . join( '|', @words ) . ')$'; + my $pattern = '(' . join( '|', @words ) . ')$'; my $sub_patterns = ""; if ( $seen{'sub'} ) { $sub_patterns .= '|' . $SUB_PATTERN; @@ -5627,7 +5627,7 @@ sub make_closing_side_comment_prefix { } } $rOpts->{'closing-side-comment-prefix'} = $csc_prefix; - $closing_side_comment_prefix_pattern = $csc_prefix_pattern; + $closing_side_comment_prefix_pattern = $csc_prefix_pattern; return; } @@ -5673,10 +5673,10 @@ EOM BEGIN { my @q; - @q = qw(sort grep map); + @q = qw(sort grep map); @is_sort_grep_map{@q} = (1) x scalar(@q); - @q = qw(for foreach); + @q = qw(for foreach); @is_for_foreach{@q} = (1) x scalar(@q); } @@ -6066,7 +6066,7 @@ EOM # If this becomes too much of a problem, we might give up and just clip # them at zero. ## $levels_to_go[$max_index_to_go] = ( $level > 0 ) ? $level : 0; - $levels_to_go[$max_index_to_go] = $level; + $levels_to_go[$max_index_to_go] = $level; $nesting_depth_to_go[$max_index_to_go] = ( $slevel >= 0 ) ? $slevel : 0; # link the non-blank tokens @@ -6393,9 +6393,9 @@ EOM } } - # Fix for rt #125506 Unexpected string formating - # in which leading space of a terminal quote was removed - $line =~ s/\s+$//; + # Fix for rt #125506 Unexpected string formating + # in which leading space of a terminal quote was removed + $line =~ s/\s+$//; $line =~ s/^\s+// unless ($in_continued_quote); $self->extract_token(0); @@ -8636,7 +8636,7 @@ sub accumulate_block_text { # A label can only be used on the next { if ( $block_type =~ /:$/ ) { $csc_last_label = "" } $csc_block_label{$type_sequence} = $csc_last_label; - $csc_last_label = ""; + $csc_last_label = ""; if ( $accumulating_text_for_block && $levels_to_go[$i] == $leading_block_text_level ) @@ -9419,8 +9419,8 @@ sub send_lines_to_vertical_aligner { my $tok = my $raw_tok = $matching_token_to_go[$i]; - # map similar items - if ($tok eq '!~') {$tok = '=~'} + # map similar items + if ( $tok eq '!~' ) { $tok = '=~' } # make separators in different nesting depths unique # by appending the nesting depth digit. @@ -10481,7 +10481,7 @@ sub set_vertical_tightness_flags { ) { my $valid_flag = 1; - my $spaces = ( $types_to_go[ $ibeg_next - 1 ] eq 'b' ) ? 1 : 0; + my $spaces = ( $types_to_go[ $ibeg_next - 1 ] eq 'b' ) ? 1 : 0; @{$rvertical_tightness_flags} = ( 2, $spaces, $type_sequence_to_go[$ibeg_next], $valid_flag, ); } @@ -10589,7 +10589,7 @@ sub get_seqno { # aligner. Assign qw quotes a value to allow qw opening and closing tokens # to be treated somewhat like opening and closing tokens for stacking # tokens by the vertical aligner. - my ($ii) = @_; + my ($ii) = @_; my $seqno = $type_sequence_to_go[$ii]; if ( $types_to_go[$ii] eq 'q' ) { my $SEQ_QW = -1; @@ -10622,7 +10622,7 @@ sub get_seqno { @is_vertical_alignment_type{@q} = (1) x scalar(@q); # only align these at end of line - @q = qw(&& ||); + @q = qw(&& ||); @is_terminal_alignment_type{@q} = (1) x scalar(@q); # eq and ne were removed from this list to improve alignment chances @@ -10674,7 +10674,7 @@ sub get_seqno { $vert_last_nonblank_block_type = ''; # look at each token in this output line.. - my $count=0; + my $count = 0; foreach my $i ( $ibeg .. $iend ) { my $alignment_type = ''; my $type = $types_to_go[$i]; @@ -10828,9 +10828,9 @@ sub get_seqno { #-------------------------------------------------------- # patch for =~ operator. We only align this if it - # is the first operator in a line, and the line is a simple - # statement. Aligning them within a statement causes - # interferes with other good alignments. + # is the first operator in a line, and the line is a simple + # statement. Aligning them within a statement causes + # interferes with other good alignments. #-------------------------------------------------------- if ( $alignment_type eq '=~' ) { my $terminal_type = $types_to_go[$i_terminal]; @@ -10844,7 +10844,7 @@ sub get_seqno { # then store the value #-------------------------------------------------------- $matching_token_to_go[$i] = $alignment_type; - $count++ if ($alignment_type); + $count++ if ($alignment_type); if ( $type ne 'b' ) { $vert_last_nonblank_type = $type; $vert_last_nonblank_token = $token; @@ -10923,10 +10923,10 @@ sub terminal_type { sub initialize_bond_strength_hashes { my @q; - @q = qw(if unless while until for foreach); + @q = qw(if unless while until for foreach); @is_good_keyword_breakpoint{@q} = (1) x scalar(@q); - @q = qw(lt gt le ge); + @q = qw(lt gt le ge); @is_lt_gt_le_ge{@q} = (1) x scalar(@q); # # The decision about where to break a line depends upon a "bond @@ -11028,7 +11028,7 @@ sub terminal_type { $right_bond_strength{'CORE::'} = NO_BREAK; # breaking AFTER modulus operator is ok: - @q = qw< % >; + @q = qw< % >; @left_bond_strength{@q} = (STRONG) x scalar(@q); @right_bond_strength{@q} = ( 0.1 * NOMINAL + 0.9 * STRONG ) x scalar(@q); @@ -11040,7 +11040,7 @@ sub terminal_type { # Break AFTER weakest math operators + and - # Make them weaker than * but a bit stronger than '.' - @q = qw< + - >; + @q = qw< + - >; @left_bond_strength{@q} = (STRONG) x scalar(@q); @right_bond_strength{@q} = ( 0.91 * NOMINAL + 0.09 * WEAK ) x scalar(@q); @@ -11061,13 +11061,13 @@ sub terminal_type { # make these a little weaker than nominal so that they get # favored for end-of-line characters - @q = qw< != == =~ !~ ~~ !~~ >; + @q = qw< != == =~ !~ ~~ !~~ >; @left_bond_strength{@q} = (STRONG) x scalar(@q); @right_bond_strength{@q} = ( 0.9 * NOMINAL + 0.1 * WEAK ) x scalar(@q); # break AFTER these - @q = qw# < > | & >= <= #; + @q = qw# < > | & >= <= #; @left_bond_strength{@q} = (VERY_STRONG) x scalar(@q); @right_bond_strength{@q} = ( 0.8 * NOMINAL + 0.2 * WEAK ) x scalar(@q); @@ -11429,7 +11429,7 @@ sub terminal_type { # section. if ( !defined($bsr) ) { $bsr = VERY_STRONG } if ( !defined($bsl) ) { $bsl = VERY_STRONG } - my $bond_str = ( $bsr < $bsl ) ? $bsr : $bsl; + my $bond_str = ( $bsr < $bsl ) ? $bsr : $bsl; my $bond_str_1 = $bond_str; #--------------------------------------------------------------- @@ -11693,7 +11693,7 @@ sub terminal_type { elsif ( defined( $bias{$left_key} ) ) { if ( !$want_break_before{$left_key} ) { $bias{$left_key} += $delta_bias; - $bond_str += $bias{$left_key}; + $bond_str += $bias{$left_key}; } } @@ -11913,7 +11913,7 @@ sub pad_array_to_go { \$do_not_break_apart, $must_break_open, ); - $bp_count = $forced_breakpoint_count - $fbc; + $bp_count = $forced_breakpoint_count - $fbc; $do_not_break_apart = 0 if $must_break_open; } } @@ -12951,7 +12951,7 @@ sub pad_array_to_go { # set breaks for any unfinished lists .. for ( my $dd = $current_depth ; $dd >= $minimum_depth ; $dd-- ) { - $interrupted_list[$dd] = 1; + $interrupted_list[$dd] = 1; $has_broken_sublist[$dd] = 1 if ( $dd < $current_depth ); set_comma_breakpoints($dd); set_logical_breakpoints($dd) @@ -13490,7 +13490,7 @@ sub find_token_starting_list { # ) # if $style eq 'all'; - my $i_last_comma = $rcomma_index->[ $comma_count - 1 ]; + my $i_last_comma = $rcomma_index->[ $comma_count - 1 ]; my $long_last_term = excess_line_length( 0, $i_last_comma ) <= 0; my $long_first_term = excess_line_length( $i_first_comma + 1, $max_index_to_go ) <= 0; @@ -14155,19 +14155,19 @@ sub undo_forced_breakpoint_stack { BEGIN { my @q; - @q = qw( && || ); + @q = qw( && || ); @is_amp_amp{@q} = (1) x scalar(@q); - @q = qw( ? : ); + @q = qw( ? : ); @is_ternary{@q} = (1) x scalar(@q); - @q = qw( + - * / ); + @q = qw( + - * / ); @is_math_op{@q} = (1) x scalar(@q); - @q = qw( + - ); + @q = qw( + - ); @is_plus_minus{@q} = (1) x scalar(@q); - @q = qw( * / ); + @q = qw( * / ); @is_mult_div{@q} = (1) x scalar(@q); } @@ -14906,7 +14906,7 @@ sub undo_forced_breakpoint_stack { # and the rest of the loop to do the join if ($skip_Section_3) { $forced_breakpoint_to_go[$iend_1] = 0; - $n_best = $n; + $n_best = $n; last; } @@ -15507,16 +15507,16 @@ sub insert_final_breaks { my $type = $types_to_go[$ii]; # For now, a good break is either a comma or, - # in a long chain, a 'return'. - # Patch for RT #126633: added the $nmax>1 check to avoid - # breaking after a return for a simple ternary. For longer - # chains the break after return allows vertical alignment, so - # it is still done. So perltidy -wba='?' will not break - # immediately after the return in the following statement: - # sub x { - # return 0 ? 'aaaaaaaaaaaaaaaaaaaaa' : - # 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; - # } + # in a long chain, a 'return'. + # Patch for RT #126633: added the $nmax>1 check to avoid + # breaking after a return for a simple ternary. For longer + # chains the break after return allows vertical alignment, so + # it is still done. So perltidy -wba='?' will not break + # immediately after the return in the following statement: + # sub x { + # return 0 ? 'aaaaaaaaaaaaaaaaaaaaa' : + # 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; + # } if ( ( $type eq ',' diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index c5a7fe66..4b04e8c5 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -1019,7 +1019,7 @@ sub guess_old_indentation_level { # what we do here but we'll guess that the old run used 4 spaces per level. my $indent_columns = $tokenizer_self->{_indent_columns}; $indent_columns = 4 if ( !$indent_columns ); - $level = int( $spaces / $indent_columns ); + $level = int( $spaces / $indent_columns ); return ($level); } @@ -1496,11 +1496,11 @@ sub prepare_for_a_new_file { # ------------------------------------------------------------ my %is_for_foreach; - @_ = qw(for foreach); + @_ = qw(for foreach); @is_for_foreach{@_} = (1) x scalar(@_); my %is_my_our; - @_ = qw(my our); + @_ = qw(my our); @is_my_our{@_} = (1) x scalar(@_); # These keywords may introduce blocks after parenthesized expressions, @@ -1788,8 +1788,8 @@ sub prepare_for_a_new_file { '/' => sub { my $is_pattern; - # a pattern cannot follow certain keywords which take optional - # arguments, like 'shift' and 'pop'. See also '?'. + # a pattern cannot follow certain keywords which take optional + # arguments, like 'shift' and 'pop'. See also '?'. if ( $last_nonblank_type eq 'k' && $is_keyword_taking_optional_args{$last_nonblank_token} ) { @@ -2025,8 +2025,8 @@ sub prepare_for_a_new_file { my $is_pattern; # Patch for rt #126965 - # a pattern cannot follow certain keywords which take optional - # arguments, like 'shift' and 'pop'. See also '/'. + # a pattern cannot follow certain keywords which take optional + # arguments, like 'shift' and 'pop'. See also '/'. if ( $last_nonblank_type eq 'k' && $is_keyword_taking_optional_args{$last_nonblank_token} ) { @@ -2409,7 +2409,7 @@ sub prepare_for_a_new_file { @is_zero_continuation_block_type{@_} = (1) x scalar(@_); my %is_not_zero_continuation_block_type; - @_ = qw(sort grep map do eval); + @_ = qw(sort grep map do eval); @is_not_zero_continuation_block_type{@_} = (1) x scalar(@_); my %is_logical_container; @@ -2417,33 +2417,33 @@ sub prepare_for_a_new_file { @is_logical_container{@_} = (1) x scalar(@_); my %is_binary_type; - @_ = qw(|| &&); + @_ = qw(|| &&); @is_binary_type{@_} = (1) x scalar(@_); my %is_binary_keyword; - @_ = qw(and or err eq ne cmp); + @_ = qw(and or err eq ne cmp); @is_binary_keyword{@_} = (1) x scalar(@_); # 'L' is token for opening { at hash key my %is_opening_type; - @_ = qw< L { ( [ >; + @_ = qw< L { ( [ >; @is_opening_type{@_} = (1) x scalar(@_); # 'R' is token for closing } at hash key my %is_closing_type; - @_ = qw< R } ) ] >; + @_ = qw< R } ) ] >; @is_closing_type{@_} = (1) x scalar(@_); my %is_redo_last_next_goto; - @_ = qw(redo last next goto); + @_ = qw(redo last next goto); @is_redo_last_next_goto{@_} = (1) x scalar(@_); my %is_use_require; - @_ = qw(use require); + @_ = qw(use require); @is_use_require{@_} = (1) x scalar(@_); my %is_sub_package; - @_ = qw(sub package); + @_ = qw(sub package); @is_sub_package{@_} = (1) x scalar(@_); # This hash holds the hash key in $tokenizer_self for these keywords: @@ -2585,7 +2585,7 @@ sub prepare_for_a_new_file { # # ----------------------------------------------------------------------- - my $line_of_tokens = shift; + my $line_of_tokens = shift; my ($untrimmed_input_line) = $line_of_tokens->{_line_text}; # patch while coding change is underway @@ -2732,7 +2732,7 @@ sub prepare_for_a_new_file { my $str = $rtokens->[$i]; my $saw_modifier_e; while ( $str =~ /\G$allowed_quote_modifiers/gc ) { - my $pos = pos($str); + my $pos = pos($str); my $char = substr( $str, $pos - 1, 1 ); $saw_modifier_e ||= ( $char eq 'e' ); } @@ -4842,14 +4842,14 @@ sub increase_nesting_depth { if ( $nested_ternary_flag[ $current_depth[$aa] - 1 ] == 0 ) { my $pdepth = $total_depth[$aa][ $current_depth[$aa] - 1 ]; if ( $pdepth == $total_depth - 1 ) { - $indent = 1; + $indent = 1; $nested_ternary_flag[ $current_depth[$aa] - 1 ] = -1; } } } } $nested_statement_type[$aa][ $current_depth[$aa] ] = $statement_type; - $statement_type = ""; + $statement_type = ""; return ( $seqno, $indent ); } @@ -5634,7 +5634,7 @@ sub do_scan_package { $package =~ s/::$//; my $pos = pos($input_line); my $numc = $pos - $pos_beg; - $tok = 'package ' . substr( $input_line, $pos_beg, $numc ); + $tok = 'package ' . substr( $input_line, $pos_beg, $numc ); $type = 'i'; # Now we must convert back from character position @@ -5766,7 +5766,7 @@ sub scan_identifier_do { while ( $i < $max_token_index ) { $i_save = $i unless ( $tok =~ /^\s*$/ ); - $tok = $rtokens->[ ++$i ]; + $tok = $rtokens->[ ++$i ]; if ( ( $tok eq ':' ) && ( $rtokens->[ $i + 1 ] eq ':' ) ) { $tok = '::'; @@ -6248,7 +6248,7 @@ sub scan_identifier_do { $package =~ s/::$//; my $pos = pos($input_line); my $numc = $pos - $pos_beg; - $tok = 'sub ' . substr( $input_line, $pos_beg, $numc ); + $tok = 'sub ' . substr( $input_line, $pos_beg, $numc ); $type = 'i'; } @@ -6568,7 +6568,7 @@ sub find_angle_operator_termination { my $pos = pos($input_line); my $pos_beg = $rtoken_map->[$i]; - my $str = substr( $input_line, $pos_beg, ( $pos - $pos_beg ) ); + my $str = substr( $input_line, $pos_beg, ( $pos - $pos_beg ) ); # Reject if the closing '>' follows a '-' as in: # if ( VERSION < 5.009 && $op-> name eq 'assign' ) { } @@ -6688,7 +6688,7 @@ sub scan_number_do { $pos = pos($input_line); my $numc = $pos - $pos_beg; $number = substr( $input_line, $pos_beg, $numc ); - $type = 'v'; + $type = 'v'; report_v_string($number); } @@ -6701,7 +6701,7 @@ sub scan_number_do { $pos = pos($input_line); my $numc = $pos - $pos_beg; $number = substr( $input_line, $pos_beg, $numc ); - $type = 'n'; + $type = 'n'; } } @@ -6720,7 +6720,7 @@ sub scan_number_do { } my $numc = $pos - $pos_beg; $number = substr( $input_line, $pos_beg, $numc ); - $type = 'n'; + $type = 'n'; } } @@ -7415,11 +7415,11 @@ BEGIN { # these functions have prototypes of the form (&), so when they are # followed by a block, that block MAY BE followed by an operator. # Smartmatch operator ~~ may be followed by anonymous hash or array ref - @q = qw( do eval ); + @q = qw( do eval ); @is_block_operator{@q} = (1) x scalar(@q); # these functions allow an identifier in the indirect object slot - @q = qw( print printf sort exec system say); + @q = qw( print printf sort exec system say); @is_indirect_object_taker{@q} = (1) x scalar(@q); # These tokens may precede a code block @@ -7755,7 +7755,7 @@ BEGIN { delete $really_want_term{'Y'}; # indirect object, too risky to check syntax; # let perl do it - @q = qw(q qq qw qx qr s y tr m); + @q = qw(q qq qw qx qr s y tr m); @is_q_qq_qw_qx_qr_s_y_tr_m{@q} = (1) x scalar(@q); # These keywords are handled specially in the tokenizer code: @@ -7868,7 +7868,7 @@ BEGIN { uc undef ); - @is_keyword_taking_optional_args{@keyword_taking_optional_args} = + @is_keyword_taking_optional_args{@keyword_taking_optional_args} = (1) x scalar(@keyword_taking_optional_args); # These are not used in any way yet diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 4b6f540b..74ca69c4 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -416,7 +416,7 @@ sub valign_input { && $rvertical_tightness_flags->[2] == $cached_seqno ) { $rvertical_tightness_flags->[3] ||= 1; - $cached_line_valid ||= 1; + $cached_line_valid ||= 1; } } @@ -502,7 +502,7 @@ sub valign_input { && $level_jump == 0 ) { $j_terminal_match = fix_terminal_else( $rfields, $rtokens, $rpatterns ); - $jmax = @{$rfields} - 1; + $jmax = @{$rfields} - 1; } # -------------------------------------------------------------------- @@ -848,7 +848,7 @@ sub eliminate_old_fields { $new_fields[$j] = $current_field; $new_matching_patterns[$j] = $current_pattern; - $new_alignments[$j] = $old_line->get_alignment($k); + $new_alignments[$j] = $old_line->get_alignment($k); $maximum_field_index = $j; $old_line->set_alignments(@new_alignments); @@ -1199,7 +1199,7 @@ sub fix_terminal_ternary { unshift( @patterns, @{$rpatterns_old}[ 0 .. $jquestion ] ); # insert appropriate number of empty fields - $jadd = $jquestion + 1; + $jadd = $jquestion + 1; $fields[0] = $pad . $fields[0]; splice( @fields, 0, 0, ('') x $jadd ) if $jadd; } @@ -1586,9 +1586,9 @@ sub fix_terminal_else { NO_MATCH: ##print "no match jmax=$jmax max=$maximum_field_index $group_list_type lines=$maximum_line_index token=$old_rtokens->[0]\n"; - # Make one last effort to retain a match of certain statements - my $match = salvage_equality_matches($new_line, $old_line); - my_flush() unless($match); + # Make one last effort to retain a match of certain statements + my $match = salvage_equality_matches( $new_line, $old_line ); + my_flush() unless ($match); return; } } @@ -1610,7 +1610,7 @@ sub salvage_equality_matches { # $xpownm1 = $class->_pow( $class->_copy($x), $nm1 ); # x(i)^(n-1) # We will only do this if there is one old line (and one new line) - return unless ($maximum_line_index == 0 ); + return unless ( $maximum_line_index == 0 ); return if ($is_matching_terminal_line); # We are only looking for equality type statements @@ -1622,14 +1622,14 @@ sub salvage_equality_matches { # The leading patterns must match my $old_rpatterns = $old_line->get_rpatterns(); - my $rpatterns = $new_line->get_rpatterns(); - return if ( $old_rpatterns->[0] ne $rpatterns->[0] ); + my $rpatterns = $new_line->get_rpatterns(); + return if ( $old_rpatterns->[0] ne $rpatterns->[0] ); # Both should have side comment fields (should always be true) - my $jmax_old = $old_line->get_jmax(); - my $jmax_new = $new_line->get_jmax(); - my $end_tok_old = $old_rtokens->[$jmax_old-1]; - my $end_tok_new = $rtokens->[$jmax_new-1]; + my $jmax_old = $old_line->get_jmax(); + my $jmax_new = $new_line->get_jmax(); + my $end_tok_old = $old_rtokens->[ $jmax_old - 1 ]; + my $end_tok_new = $rtokens->[ $jmax_new - 1 ]; my $have_side_comments = defined($end_tok_old) && $end_tok_old eq '#' @@ -1641,18 +1641,18 @@ sub salvage_equality_matches { # 'unless','||', '&&'. The reason is that (1) this isn't a great match, and # (2) we will prevent possibly better matchs to follow. Here is an # example. The match of the first two lines is rejected, and this allows - # the second and third lines to match. + # the second and third lines to match. # my $type = shift || "o"; # my $fname = ( $type eq 'oo' ? 'orte_city' : 'orte' ); # my $suffix = ( $coord_system eq 'standard' ? '' : '-orig' ); # This logic can cause some unwanted losses of alignments, but it can retain - # long runs of multiple-token alignments, so overall it is worthwhile. - # If we had a peek at the subsequent line we could make a much better + # long runs of multiple-token alignments, so overall it is worthwhile. + # If we had a peek at the subsequent line we could make a much better # decision here, but for now this is not available. - for ( my $j = 1 ; $j < $jmax_new-1 ; $j++ ) { - my $new_tok = $rtokens->[$j]; + for ( my $j = 1 ; $j < $jmax_new - 1 ; $j++ ) { + my $new_tok = $rtokens->[$j]; my $is_good_alignment = ( $new_tok =~ /^(=|\?|if|unless|\|\||\&\&)/ ); - return if ($is_good_alignment); + return if ($is_good_alignment); } my $squeeze_line = sub { @@ -1681,7 +1681,7 @@ sub salvage_equality_matches { $line_obj->{_rtokens} = $rtokens_new; $line_obj->set_jmax($jmax_new); }; - + # Okay, we will force a match at the equals-like token. We will fix both # lines to have just 2 tokens and 3 fields: $squeeze_line->($new_line); @@ -1690,7 +1690,7 @@ sub salvage_equality_matches { # start over with a new group initialize_for_new_group(); add_to_group($old_line); - $current_line = $old_line; + $current_line = $old_line; return 1; } @@ -2056,8 +2056,8 @@ sub decide_if_aligned { # always align lists !$group_list_type - # always align lines with leading equality operators - && !$leading_equals + # always align lines with leading equality operators + && !$leading_equals && ( @@ -2067,7 +2067,7 @@ sub decide_if_aligned { # don't align two lines with big gap || $group_maximum_gap > 12 - # don't align lines with differing number of alignment tokens + # don't align lines with differing number of alignment tokens || ( $previous_maximum_jmax_seen != $previous_minimum_jmax_seen ) ) ); @@ -2537,9 +2537,9 @@ sub valign_output_step_B { # and eliminate multiple colons might appear to be slow, # but it's not an issue because we almost never come # through here. In a typical file we don't. - $seqno_string =~ s/^:+//; + $seqno_string =~ s/^:+//; $last_nonblank_seqno_string =~ s/^:+//; - $seqno_string =~ s/:+/:/g; + $seqno_string =~ s/:+/:/g; $last_nonblank_seqno_string =~ s/:+/:/g; # how many spaces can we outdent? @@ -2707,9 +2707,9 @@ sub valign_output_step_D { # Handle entab option elsif ($rOpts_entab_leading_whitespace) { - # Patch 12-nov-2018 based on report from Glenn. Extra padding was - # not correctly entabbed, nor were side comments: - # Increase leading space count for a padded line to get correct tabbing + # Patch 12-nov-2018 based on report from Glenn. Extra padding was + # not correctly entabbed, nor were side comments: + # Increase leading space count for a padded line to get correct tabbing if ( $line =~ /^(\s+)(.*)$/ ) { my $spaces = length($1); if ( $spaces > $leading_space_count ) { diff --git a/local-docs/ChangeLog.pod b/local-docs/ChangeLog.pod index f6e91e18..636bdc16 100644 --- a/local-docs/ChangeLog.pod +++ b/local-docs/ChangeLog.pod @@ -1,10 +1,7 @@ =head1 Perltidy Change Log -=head2 2018 02 20.01 +=head2 2018 11 16 - - The packaging for this version has changed. The Tidy.pm file has - been split into a smaller Tidy.pm file plus supporting modules in the path - Perl/Tidy/*. - Fixed RT #126965, in which a ternary operator was misparsed if immediately following a function call without arguments, such as: @@ -37,10 +34,6 @@ - Fixed RT #124594, license text desc. changed from 'GPL-2.0+' to 'gpl_2' - - RT #106493; source code repository is https://github.com/perltidy/perltidy - - - Numerous installation test snippets have been added. - - Fixed bug in which a warning about a possible code bug was issued in a script with brace errors. @@ -54,8 +47,11 @@ some lines was was not entabbed. This happened in code which was adjusted for vertical alignment and in hanging side comments. Thanks to Glenn. - - Vertical alignment has been improved in several ways. Thanks especially to - Glenn for sending helpful snippets. + - Fixed RT #127633, undesirable line break after return when -baao flag is set + + - Fixed RT #127035, vertical alignment. Vertical alignment has been improved + in several ways. Thanks especially to Glenn and Michael Wardman for sending + helpful snippets. - In many cases, two lines which were previously left unaligned are now aligned. @@ -90,6 +86,17 @@ is( pop() // 7, 0, 'pop() // ... works' ); is( pop @ARGV // 7, 3, 'pop @array // ... works' ); + - RT #106493; source code repository location has been added to docs; it is + https://github.com/perltidy/perltidy + + - The packaging for this version has changed. The Tidy.pm module is much + smaller. Supporting modules have been split out from it and placed below + it in the path Perl/Tidy/*. + + - A number of new installation test cases have been added. Updates are now + continuously tested at Travis CI against versions back to Perl 5.08. + + =head2 2018 02 20 diff --git a/local-docs/Release-Checklist.md b/local-docs/Release-Checklist.md index 98130f0a..bc63dbc6 100644 --- a/local-docs/Release-Checklist.md +++ b/local-docs/Release-Checklist.md @@ -38,4 +38,4 @@ - Upload Release to CPAN - Update CPAN tickets - Upload release to sourceforge -- Update web site +- Update web sites diff --git a/local-docs/perltidy.md b/local-docs/perltidy.md index d0fae2c2..26b61849 100644 --- a/local-docs/perltidy.md +++ b/local-docs/perltidy.md @@ -3274,16 +3274,16 @@ perlstyle(1), Perl::Tidy(3) # VERSION -This man page documents perltidy version 20180220.01 +This man page documents perltidy version 20181116 # BUG REPORTS -A list of current bugs and issues can be found at the CPAN site - - https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy +A list of current bugs and issues can be found at the CPAN site [https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy](https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy) To report a new bug or problem, use the link on this page. +The source code repository is at [https://github.com/perltidy/perltidy](https://github.com/perltidy/perltidy). + # COPYRIGHT Copyright (c) 2000-2018 by Steve Hancock -- 2.39.5