## 2023 09 12.06
- - Added --dump-variables (-dv) option to dump a list of variables with
- certain properties of interest. For example
+ - Added --dump-unusual-variables (-duv) option to dump a list of
+ variables with certain properties of interest. For example
- perltidy -dv somefile.pl >vars.txt
+ perltidy -duv somefile.pl >vars.txt
produces a file with lines which look something like
p: lexical variable with scope in multiple packages
u: unused variable
- - Added a related flag --warn-variables=s (-wv=s) option to warn
- if certain types of variables are found in a script. For example
+ - Added a related flag --warn-variable-types=string (-wvt=string) option
+ to warn if certain types of variables are found in a script. The types
+ may include 'r', 's', and 'p' but not 'u'.
- perltidy -wv=rps somefile.pl
+ perltidy -wvt=rp somefile.pl
- will check for and warn if any of the above types r, s, or p are seen.
+ will check for and warn if any variabls of type 'r', or 'p' are seen.
The manual has further details.
- All parameters taking integer values are now checked for
This will dump a table of comma-separated metrics for subroutines longer than
10 lines to F<blocks.csv>.
- perltidy -dv somefile.pl >vars.txt
+ perltidy -duv somefile.pl >vars.txt
This will dump a list of unused and reused lexical variable names to
F<vars.txt>.
=back
-=item B<Finding unused, reused, and other variables of interest with --dump-variables>
+=item B<Finding unused, reused, and other variables of interest with --dump-unusual-variables>
Lexical variables with certain properties of interest to a programmer can be
-listed with B<--dump-variables> or B<-dv>. This parameter must be on the
-command line, along with a single file name. It causes perltidy to scan the
-file for certain variable types, write any found to the standard output, and
-then immediately exit without doing any formatting. For example
+listed with B<--dump-unusual-variables> or B<-duv>. This parameter must be on
+the command line, along with a single file name. It causes perltidy to scan
+the file for certain variable types, write any found to the standard output,
+and then immediately exit without doing any formatting. For example
- perltidy -dv somefile.pl >vars.txt
+ perltidy -duv somefile.pl >vars.txt
produces a file with lines which look something like
might be defined for possible future program development, clarity or debugging.
But sometimes they can occur due to being orphaned by a coding change, due to a
misspelling, or by having an unintentional preceding C<my>. So it is worth
-checking them, especially for new code.
+reviewing them, especially for new code.
=back
-=item B<Warning about certain variables type with --warn-variables>
+=item B<Warning about certain variable types with --warn-variable-types>
-The flag B<--warn-variables=string>, or B<-wv=string>, can be used to to
+The flag B<--warn-variable-types=string>, or B<-wvt=string>, can be used to to
produce a warning message if certain of the above variable types are
encountered during formatting. The input parameter B<string> is a
a concatenation of the letters associated with the types of variables
-to produce a warning. For example:
+which are to produce a warning. For example:
- perltidy -wv=sp somefile.pl
+ perltidy -wvt=sp somefile.pl
will process F<somefile.pl> normally but issue a warning if either of
the issues 's' or 'p', described above, are encountered.
when perltidy is run on small snippets of code from within an editor.
All possible variable warnings may be requested with B<-wv=rsp> or simply
-B<-wv=1> or B<-wv='*'>. The default is not to do these checks, and it can
-also be indicated with B<-wv=0>.
+B<-wvt=1> or B<-wvt='*'>. The default is not to do these checks, and it can
+also be indicated with B<-wvt=0>.
-A companion flag, B<--want-variables-exclusion-list=string>, or B<-wvxl=string>,
+A companion flag, B<--warn-variable-exclusion-list=string>, or B<-wvxl=string>,
can be used to skip warning checks for a list of variables. For example,
perltidy -wv=1 -wvxl='$self $class' somefile.pl
# line parameters and is expecting formatted output to stdout. Another
# precaution, added elsewhere, is to ignore these in a .perltidyrc
my $num_files = @Arg_files;
- foreach my $opt_name (qw(dump-block-summary dump-variables)) {
+ foreach my $opt_name (qw(dump-block-summary dump-unusual-variables)) {
if ( $rOpts->{$opt_name} && $num_files != 1 ) {
Die(<<EOM);
--$opt_name expects 1 filename in the arg list but saw $num_files filenames
########################################
$category = 9; # Other controls
########################################
- $add_option->( 'warn-missing-else', 'wme', '!' );
- $add_option->( 'add-missing-else', 'ame', '!' );
- $add_option->( 'add-missing-else-comment', 'amec', '=s' );
- $add_option->( 'delete-block-comments', 'dbc', '!' );
- $add_option->( 'delete-closing-side-comments', 'dcsc', '!' );
- $add_option->( 'delete-pod', 'dp', '!' );
- $add_option->( 'delete-side-comments', 'dsc', '!' );
- $add_option->( 'tee-block-comments', 'tbc', '!' );
- $add_option->( 'tee-pod', 'tp', '!' );
- $add_option->( 'tee-side-comments', 'tsc', '!' );
- $add_option->( 'look-for-autoloader', 'lal', '!' );
- $add_option->( 'look-for-hash-bang', 'x', '!' );
- $add_option->( 'look-for-selfloader', 'lsl', '!' );
- $add_option->( 'pass-version-line', 'pvl', '!' );
- $add_option->( 'warn-variables', 'wv', '=s' );
- $add_option->( 'warn-variables-exclusion-list', 'wvxl', '=s' );
+ $add_option->( 'warn-missing-else', 'wme', '!' );
+ $add_option->( 'add-missing-else', 'ame', '!' );
+ $add_option->( 'add-missing-else-comment', 'amec', '=s' );
+ $add_option->( 'delete-block-comments', 'dbc', '!' );
+ $add_option->( 'delete-closing-side-comments', 'dcsc', '!' );
+ $add_option->( 'delete-pod', 'dp', '!' );
+ $add_option->( 'delete-side-comments', 'dsc', '!' );
+ $add_option->( 'tee-block-comments', 'tbc', '!' );
+ $add_option->( 'tee-pod', 'tp', '!' );
+ $add_option->( 'tee-side-comments', 'tsc', '!' );
+ $add_option->( 'look-for-autoloader', 'lal', '!' );
+ $add_option->( 'look-for-hash-bang', 'x', '!' );
+ $add_option->( 'look-for-selfloader', 'lsl', '!' );
+ $add_option->( 'pass-version-line', 'pvl', '!' );
+ $add_option->( 'warn-variable-types', 'wvt', '=s' );
+ $add_option->( 'warn-variable-exclusion-list', 'wvxl', '=s' );
########################################
$category = 13; # Debugging
$add_option->( 'dump-profile', 'dpro', '!' );
$add_option->( 'dump-short-names', 'dsn', '!' );
$add_option->( 'dump-token-types', 'dtt', '!' );
- $add_option->( 'dump-variables', 'dv', '!' );
+ $add_option->( 'dump-unusual-variables', 'duv', '!' );
$add_option->( 'dump-want-left-space', 'dwls', '!' );
$add_option->( 'dump-want-right-space', 'dwrs', '!' );
$add_option->( 'experimental', 'exp', '=s' );
dump-want-left-space
dump-want-right-space
dump-block-summary
- dump-variables
+ dump-unusual-variables
help
stylesheet
version
}
# Dump variable usage info if requested
- if ( $rOpts->{'dump-variables'} ) {
- $self->dump_variables();
+ if ( $rOpts->{'dump-unusual-variables'} ) {
+ $self->dump_unusual_variables();
Exit(0);
}
- # Act on -warn-variables if requesed and if the logger is available
+ # Act on -warn-variable-types if requesed and if the logger is available
# (the logger is deactivated during iterations)
- $self->warn_variables()
- if ( $rOpts->{'warn-variables'}
+ $self->warn_variable_types()
+ if ( $rOpts->{'warn-variable-types'}
&& $self->[_logger_object_] );
$self->examine_vertical_tightness_flags();
return \@sorted;
} ## end sub scan_variable_usage
-sub dump_variables {
+sub dump_unusual_variables {
my ($self) = @_;
- # process a --dump-variables(-dv) command
+ # process a --dump-unusual-variables(-duv) command
my $rlines = $self->scan_variable_usage();
return unless ( @{$rlines} );
print {*STDOUT} $output_string;
return;
-} ## end sub dump_variables
+} ## end sub dump_unusual_variables
-sub warn_variables {
+sub warn_variable_types {
my ($self) = @_;
- # process a --warn-variables command
+ # process a --warn-variable-types command
- my $wv_key = 'warn-variables';
+ my $wv_key = 'warn-variable-types';
my $wv_option = $rOpts->{$wv_key};
# Single letter options:
- # u - declared but unused [NOT AVAILABLE here, use --dump-variables]
+ # u - declared but unused [NOT AVAILABLE, use --dump-unusual-variables]
# r - reused scope
# s - reused sigil
# p - package boundaries crossed by lexical variables
# 1 - all of the above
# * - all of the above
# Example:
- # -wv=sr : do check types 's' and 'r'
+ # -wvt=sr : do check types 's' and 'r'
if ( $wv_option eq '*' || $wv_option eq '1' ) { $wv_option = 'spr' }
# needless warnings when perltidy is run on small blocks from an editor.
if ( $wv_option =~ s/u//g ) {
Warn(<<EOM);
---$wv_key=u is not available; use --dump-variables=u to find unused vars
+--$wv_key=u is not available; use --dump-unusual-variables=u to find unused vars
EOM
}
EOM
# remove any excluded names
- my $wvxl_key = 'warn-variables-exclusion-list';
+ my $wvxl_key = 'warn-variable-exclusion-list';
my $excluded_names = $rOpts->{$wvxl_key};
my %is_excluded_name;
if ($excluded_names) {
$message .= "End scan for --$wv_key=$wv_option:\n";
warning($message);
return;
-} ## end sub warn_variables
+} ## end sub warn_variable_types
sub find_non_indenting_braces {