]> git.donarmstrong.com Git - perltidy.git/commitdiff
add closing side comments on while loops
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 6 Oct 2024 14:36:45 +0000 (07:36 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 6 Oct 2024 14:36:45 +0000 (07:36 -0700)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/HtmlWriter.pm
lib/Perl/Tidy/Tokenizer.pm
lib/Perl/Tidy/VerticalAligner.pm
perltidyrc

index 2d1d1ad61122654018a1ea00f3dfba02bf97fe89..e9ccc1da1a2546c46bd278ae73a139a656ea73af 100644 (file)
@@ -2379,7 +2379,7 @@ EOM
 
         $logger_object->finish()
           if $logger_object;
-    } ## end of main loop to process all files
+    } ## end while ( @{$rfiles} )
 
     return;
 } ## end sub process_all_files
@@ -3200,7 +3200,7 @@ sub line_diff {
 
             # we could continue to mark all differences, but there is no point
             last;
-        }
+        } ## end while ( $mask =~ /[^\0]/g)
     }
     return ( $diff_marker, $pos1 );
 } ## end sub line_diff
@@ -3293,7 +3293,7 @@ EOM
 $line_diff
 EOM
         return $msg;
-    } ## end while
+    } ## end while (1)
 
     # no line differences found, but one file may have fewer lines
     if ( $counti > $counto ) {
@@ -5212,7 +5212,7 @@ sub find_file_upwards {
         else {
             $search_dir = dirname($search_dir);
         }
-    }
+    } ## end while (1)
 
     # This return is for Perl-Critic.
     # We shouldn't get out of the while loop without a return
@@ -5944,7 +5944,7 @@ sub strip_comments_and_join_quotes {
                     last;
                 }
             }
-        } ## end loop over line characters
+        } ## end while (1)
 
         if ( !$quote_char ) {
             push @{$rline_hash},
@@ -6031,7 +6031,7 @@ EOM
                 last;
             }
         }
-    }
+    } ## end while (1)
     return ( \@body_parts, $msg );
 } ## end sub parse_args
 
index 27dbe9e667566bf825f5f9c9388e1b4320de441d..75e2ac82292e5d46f782fa01de1d971553839cf8 100644 (file)
@@ -1513,7 +1513,7 @@ sub K_next_code {
             return $Knnb;
         }
         $Knnb++;
-    }
+    } ## end while ( $Knnb < $Num )
     return;
 } ## end sub K_next_code
 
@@ -1560,7 +1560,7 @@ sub K_next_nonblank {
         }
         if ( $rLL->[$Knnb]->[_TYPE_] ne 'b' ) { return $Knnb }
         $Knnb++;
-    }
+    } ## end while ( $Knnb < $Num )
     return;
 } ## end sub K_next_nonblank
 
@@ -1598,7 +1598,7 @@ sub K_previous_code {
             return $Kpnb;
         }
         $Kpnb--;
-    }
+    } ## end while ( $Kpnb >= 0 )
     return;
 } ## end sub K_previous_code
 
@@ -3335,7 +3335,7 @@ EOM
         else {
             last;
         }
-    }
+    } ## end while (1)
 
     if ($err_msg) {
         my $msg;
@@ -8016,7 +8016,7 @@ sub follow_if_chain {
 
         # Shouldn't happen unless file has an error
         last;
-    }
+    } ## end while ($seqno)
 
     # check count
     return if ( $elsif_count < $elsif_count_min );
@@ -9634,7 +9634,7 @@ sub expand_quoted_word_list {
             #  @EXPORT = ( @{$EXPORT_TAGS{standard}}, ..
             return;
         }
-    }
+    } ## end while ( ++$Kn <= $Klimit )
     return \@list;
 
 } ## end sub expand_quoted_word_list
@@ -10224,7 +10224,7 @@ sub scan_variable_usage {
             my $word         = $2;
             my $brace        = $3;
             $update_use_count->( $sigil_string, $word, $brace );
-        }
+        } ## end while ( $text =~ ...)
         return;
     }; ## end $scan_quoted_text = sub
 
@@ -10749,7 +10749,7 @@ EOM
                               && Fault("line_type=$ltype should be HERE..\n");
                             return;
                         }
-                    }
+                    } ## end while ( ++$ix_HERE <= $ix_max)
 
                     # scan the here-doc text
                     $scan_quoted_text->($here_text);
@@ -13275,7 +13275,7 @@ EOM
                     }
                 }
                 $seqno_parent = $rparent_of_seqno->{$seqno_parent};
-            }
+            } ## end while ( defined($seqno_parent...))
         }
 
         # Handle code blocks ...
@@ -14869,7 +14869,7 @@ sub parent_sub_seqno {
         if ( $self->[_ris_sub_block_]->{$parent_seqno} ) {
             return $parent_seqno;
         }
-    }
+    } ## end while ( $parent_seqno = $self...)
     return;
 } ## end sub parent_sub_seqno
 
@@ -15255,7 +15255,7 @@ sub package_info_maker {
                 }
             }
             last;
-        }
+        } ## end while (@package_stack)
 
         push @package_lookup_list, [ $name, $K_opening ];
         push @package_stack,       $ii_next;
@@ -15789,7 +15789,7 @@ sub count_list_elements {
         else {
             # continue search
         }
-    }
+    } ## end while ( ++$KK < $K_list_end)
 
     # Increase the count by 1 if the list does not have a trailing comma
     if (   defined($KK_this_nb)
@@ -15867,7 +15867,7 @@ sub count_prototype_args {
             $bump_count->();
         }
         else { next }
-    }
+    } ## end while (@chars)
     return ( $count_min, $count_max );
 } ## end sub count_prototype_args
 
@@ -16457,7 +16457,7 @@ sub count_sub_input_args {
                       && Fault("line_type=$ltype should be HERE..\n");
                     return;
                 }
-            }
+            } ## end while ( ++$ix_HERE <= $ix_max)
             if ($here_text) {
                 my $pos;
                 $pos = index( $here_text, '@_' );
@@ -16480,7 +16480,7 @@ sub count_sub_input_args {
         else {
             # continue search
         }
-    }
+    } ## end while ( ++$KK < $K_closing)
 
     #--------------------------------
     # the whole file has been scanned
@@ -18979,7 +18979,7 @@ sub setup_new_weld_measurements {
                 }
             }
             $Knext = $rK_next_seqno_by_K->[$Knext];
-        }
+        } ## end while ( $Knext < $Kouter_opening)
     }
 
     # fix c1468 - do not measure from a leading opening block brace -
@@ -19787,7 +19787,7 @@ EOM
                   $rLL->[$Kouter_closing]->[_CI_LEVEL_];
             }
         }
-    }
+    } ## end while ( @{$rnested_pairs})
 
     return;
 } ## end sub weld_nested_containers
@@ -21232,7 +21232,7 @@ EOM
                 last if ( !defined($parent_seqno) );
                 last if ( $parent_seqno eq SEQ_ROOT );
                 $ris_excluded_lp_container->{$parent_seqno} = 1;
-            }
+            } ## end while (1)
         }
     }
 
@@ -25358,7 +25358,7 @@ Program Bug: undo_forced_breakpoint from $pkg $lno has i=$i but max=$max_index_t
 EOM
                 }
             }
-        }
+        } ## end while ( $forced_breakpoint_undo_count...)
         return;
     } ## end sub undo_forced_breakpoint_stack
 } ## end closure set_forced_breakpoint
@@ -26583,7 +26583,7 @@ EOM
             }
             $i_f = $ri_first->[$line_number];
             $i_l = $ri_last->[$line_number];
-        }
+        } ## end while ( $i_break_left >= ...)
 
         # Do not leave a blank at the end of a line; back up if necessary
         if ( $types_to_go[$i_break_left] eq 'b' ) { $i_break_left-- }
@@ -26660,7 +26660,7 @@ EOM
                 my $tok_i = $tokens_to_go[$ii];
                 return if ( $tok_i eq '?' || $tok_i eq ':' );
             }
-        }
+        } ## end while (1)
 
         # Slow loop checking for certain characters
 
@@ -27055,7 +27055,7 @@ EOM
                     _has_terminal_semicolon => $has_terminal_semicolon,
                 }
             );
-        }
+        } ## end while ( my $section = pop...)
 
         return;
     } ## end sub recombine_breakpoints
@@ -27221,7 +27221,7 @@ EOM
                 last;
             }
 
-        } ## end iteration loop
+        } ## end while (1)
 
         if (DEBUG_RECOMBINE) {
             my $ratio = sprintf "%0.3f", $rhash->{_num_compares} / $num_pairs;
@@ -29179,7 +29179,7 @@ sub undo_lp_ci {
         return if ( $lev_start != $levels_to_go[$ibeg] );
         return if ( $ci_start_plus != $ci_levels_to_go[$ibeg] );
         last   if ( $closing_index <= $iend );
-    }
+    } ## end while ( ++$n <= $max_line)
 
     # we can reduce the indentation of all continuation lines
     my $continuation_line_count = $n - $line_open;
@@ -29414,7 +29414,7 @@ sub break_long_lines {
         if ( ( $i_begin <= $imax ) && ( $types_to_go[$i_begin] eq 'b' ) ) {
             $i_begin++;
         }
-    }
+    } ## end while ( $i_begin <= $imax)
 
     #-------------------------------------------------
     # END of main loop to set continuation breakpoints
@@ -29938,7 +29938,7 @@ sub break_lines_inner_loop {
             };
             last;
         }
-    }
+    } ## end while ( ++$i_test <= $imax)
 
     #-----------------------------------------------------
     # End INNER_LOOP over the indexes in the _to_go arrays
@@ -33211,7 +33211,7 @@ sub compactify_table {
         {
             $number_of_fields = $min_fields;
             $min_fields -= $odd_or_even;
-        }
+        } ## end while ( $min_fields >= $odd_or_even...)
     }
     return $number_of_fields;
 } ## end sub compactify_table
@@ -34072,7 +34072,7 @@ EOM
                 $current_ci_level = $ci_lev;
                 last;
             }
-        }
+        } ## end while (1)
         return;
     } ## end sub lp_decreasing_depth
 
@@ -34477,7 +34477,7 @@ program bug with -lp: want to delete $deleted_spaces from item $i, but old=$old_
 EOM
                     }
                 }
-            }
+            } ## end while ( ++$i <= $max_lp_object_list)
             $lp_position_predictor -= $deleted_spaces;
             $spaces_needed         -= $deleted_spaces;
             last if ( $spaces_needed <= 0 );
@@ -35079,7 +35079,7 @@ EOM
                         last;
                     }
                     $KP = $rK_next_seqno_by_K->[$KP];
-                }
+                } ## end while ( defined($KP) && $KP...)
             }
             $rvao_args->{is_terminal_ternary} = $is_terminal_ternary;
         }
@@ -37885,7 +37885,7 @@ sub make_paren_name {
                     $indentation = $reduced_spaces_to_go[$i_ind];
                     $lev         = $levels_to_go[$i_ind];
                 }
-            }
+            } ## end while ( $i_ind < $i_terminal)
         }
 
         #--------------------------------------------------------------
index 6c779bedc6ed98b865dc0f7f1924fecacd1fe30e..8d5509ab94fa4605268f89d2e6a69a1f351ee226 100644 (file)
@@ -942,14 +942,14 @@ sub pod_to_html {
                     $html_print->('<pre>');
                     $html_print->( ${$rpre_string} );
                     $html_print->('</pre>');
-                }
+                } ## end while ( @{$rpre_string_stack...})
             }
             $html_print->($line);
         }
         else {
             $html_print->($line);
         }
-    }
+    } ## end while ( defined( my $line...))
 
     $success_flag = 1;
     if ( !$saw_body ) {
index 48292366f7e194facb4e8d5a4b68a543fbdd1056..5ee462fbf736cd7833867b9e74c104b94ba89b9a 100644 (file)
@@ -1777,7 +1777,7 @@ sub find_starting_indentation_level {
 
             $starting_level = $self->guess_old_indentation_level($line);
             last;
-        }
+        } ## end while ( defined( $line = ...))
         $msg = "Line $i implies starting-indentation-level = $starting_level\n";
         $self->write_logfile_entry("$msg");
     }
@@ -7526,7 +7526,7 @@ sub peek_ahead_for_n_nonblank_pre_tokens {
         ( $rpre_tokens, $rmap, $rpre_types ) =
           pre_tokenize( $line, $max_pretokens );
         last;
-    }
+    } ## end while ( defined( $line = ...))
     return ( $rpre_tokens, $rpre_types );
 } ## end sub peek_ahead_for_n_nonblank_pre_tokens
 
@@ -7552,7 +7552,7 @@ sub peek_ahead_for_nonblank_token {
             $rtokens->[ ++$j ] = $tok;
         }
         last;
-    }
+    } ## end while ( defined( $line = ...))
     return;
 } ## end sub peek_ahead_for_nonblank_token
 
@@ -7837,7 +7837,7 @@ sub guess_if_here_doc {
             last;
         }
         last if ( $k >= $HERE_DOC_WINDOW );
-    }
+    } ## end while ( defined( $line = ...))
 
     if ( !$here_doc_expected ) {
 
@@ -9152,7 +9152,7 @@ EOM
             # implies that scanning has finished
             last if ( $i <= $i_start_loop );
 
-        } ## end of main loop
+        } ## end while ( $i < $max_token_index...)
 
         #-------------
         # Check result
@@ -10257,7 +10257,7 @@ sub inverse_pretoken_map {
             $i--;
             last;
         }
-    }
+    } ## end while ( ++$i <= $max_token_index)
     return ( $i, $error );
 } ## end sub inverse_pretoken_map
 
@@ -10600,7 +10600,7 @@ sub follow_quoted_string {
             else {
                 $allow_quote_comments = 1;
             }
-        }
+        } ## end while ( $i < $max_token_index)
     }
 
     # There are two different loops which search for the ending quote
@@ -10665,7 +10665,7 @@ sub follow_quoted_string {
                     $quoted_string .= substr( $tok, $old_pos );
                 }
             }
-        }
+        } ## end while ( $i <= $max_token_index)
     }
 
     #-----------------------------------------------------------------------
@@ -10698,7 +10698,7 @@ sub follow_quoted_string {
                 ## nothing special
             }
             $quoted_string .= $tok;
-        }
+        } ## end while ( $i < $max_token_index)
     }
     if ( $i > $max_token_index ) { $i = $max_token_index }
     return (
@@ -10882,7 +10882,7 @@ sub pre_tokenize {
         else {
             return ( \@tokens, \@token_map, \@type );
         }
-    }
+    } ## end while ( $max_tokens_wanted...)
 
     return ( \@tokens, \@token_map, \@type );
 } ## end sub pre_tokenize
index 4bc78755d802468a9646df73fd1ffb6e7b5c6697..71aa1aa76385b7444d86531b6c63dd350a0c1449 100644 (file)
@@ -3704,7 +3704,7 @@ sub get_line_token_info {
             {
                 $imax = $ii;
                 $ii--;
-            }
+            } ## end while ( $ii >= 0 && fat_comma_to_comma...)
         }
 
         # make a first pass to find level range
index 93fa710515bff152766fe6d1a0249d89c096cb9a..eee5625676d02f48b17ac464086eb34e75f676a6 100644 (file)
 # user-defined subs must have args in parens
 --want-call-parens='&'
 
-# add closing side comments for subs
+# Add closing side comments for subs, asubs, and while blocks
+# while blocks are marked because they can be tricky to get right.
+# The default interval (-csci=6) is used but a value of 10 might 
+# be a little better. But changing -csci would change a lot of lines.
 --closing-side-comments
---closing-side-comment-list='sub asub'
+--closing-side-comment-list='sub asub while'
 
 # remove non-bare trailing commas
 # add trailing commas to key=>value hash lists
@@ -43,6 +46,6 @@
 --add-interbracket-arrows
 --interbracket-arrow-style=']->{ }->['
 
-# use 'perltidy -dmcp filename' to find mixed call paren usage
-# prefer call parens for these keywords:
+# Use 'perltidy -dmcp filename' to find mixed call paren usage.
+# Prefer call parens for these keywords:
 --want-call-parens='open unlink substr defined ref scalar int'