From 6deb2044e9db18f1ab4e24fbd3578f550849337d Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 13 Dec 2023 08:34:17 -0800 Subject: [PATCH] change dv to duv, wv to wvt=s The old names were a little confusing because they were very similar but one took an arg and the other did not. dump-variables -> dump-unusual-variables (dv->duv) warn-variables=s -> warn-variable-types (wv->wvt) --- CHANGES.md | 15 ++++++++------- bin/perltidy | 30 +++++++++++++++--------------- lib/Perl/Tidy.pm | 38 +++++++++++++++++++------------------- lib/Perl/Tidy/Formatter.pm | 32 ++++++++++++++++---------------- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8375c847..7c0803c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,10 +2,10 @@ ## 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 @@ -26,12 +26,13 @@ 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 diff --git a/bin/perltidy b/bin/perltidy index 89603dd6..3710b495 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -125,7 +125,7 @@ the start of every line. This will dump a table of comma-separated metrics for subroutines longer than 10 lines to F. - 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. @@ -5508,15 +5508,15 @@ This selects every if-chain which contains 2 or more B blocks: =back -=item B +=item B 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 @@ -5564,19 +5564,19 @@ provided by another routine or data structure but which are not needed, or they 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. So it is worth -checking them, especially for new code. +reviewing them, especially for new code. =back -=item B +=item B -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 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 normally but issue a warning if either of the issues 's' or 'p', described above, are encountered. @@ -5586,10 +5586,10 @@ A limitation is that warnings may not be requested for unused variables, type 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 diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 793856a5..435fa21f 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -915,7 +915,7 @@ EOM # 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(<( '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 @@ -3667,7 +3667,7 @@ sub generate_options { $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' ); @@ -4551,7 +4551,7 @@ EOM dump-want-left-space dump-want-right-space dump-block-summary - dump-variables + dump-unusual-variables help stylesheet version diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 4a39bb88..5c69031c 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6413,15 +6413,15 @@ EOM } # 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(); @@ -9401,10 +9401,10 @@ EOM 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} ); @@ -9426,18 +9426,18 @@ EOM 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 @@ -9445,7 +9445,7 @@ sub warn_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' } @@ -9453,7 +9453,7 @@ sub warn_variables { # needless warnings when perltidy is run on small blocks from an editor. if ( $wv_option =~ s/u//g ) { Warn(<{$wvxl_key}; my %is_excluded_name; if ($excluded_names) { @@ -9493,7 +9493,7 @@ EOM $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 { -- 2.39.5