is not specified, and when 'asub' is requested with -cscl=asub.
Use -cscxl=asub to prevent this.
+ - Include check for unused constants in --dump-unusual-variables and
+ --warn-variable-types (new issue type 'c').
+
- Include signature variables in --dump-unusual-variables and
--warn-variable-types; see git #158.
where 's' is a control string. These are explained in the manual.
- Updates for issue git #151:
- (1) --warn-variable-types=u is now okay if it is on the command line
- with a named file.
+ (1) --warn-variable-types=u is now okay if a named file is processed.
(2) --warn-variable-exclusion-list=s now allows leading and/or
trailing * on variable names to allow a wildcard match. For example
-wvxl='*_unused' is okay and would match $var1_unused and $var2_unused.
the issues B<s> or B<r>, described above, are encountered.
The B<u> and B<c> options (unused variables and constants) have a limitation:
-they are not allowed in a F<.perltidyrc> configuration file. But they can be
-used on the command line provided that perltidy is operating on a named file.
+they will be silently turned off if perltidy is not operating on a named file.
This rule is necessary to avoid warnings when perltidy is run on small snippets
-of code from within an editor.
+of code from within an editor which passes data through the standard input. If
+this precaution is not sufficient to prevent incorrect warnings from within an
+editor which uses temporary files, a solution might be to remove the B<-wvt>
+parameter from a F<.perltidyrc> file and only use it on the command line.
A companion flag, B<--warn-variable-exclusion-list=string>, or B<-wvxl=string>,
can be used to skip warning checks for a list of variable names. A leading
}
# Special check for -wvt
- elsif ( ( $opt eq 'u' || $opt eq 'c' )
+ # Deactivated for now to allow -wvt in perltidyrc files. This can
+ # eventually be removed if allowing this does not cause problems.
+ elsif (0
+ && ( $opt eq 'u' || $opt eq 'c' )
&& $long_name eq 'warn-variable-types' )
{
if ( !$wvt_in_args ) {
# $wvt_in_args = true if the -wvt parameter was on the command line
# $num_files = number of files on the command line
- my @all_opts = qw(r s p);
- if ( $wvt_in_args && $num_files ) { push @all_opts, 'u', 'c' }
+ my @all_opts = qw(r s p u c);
$rwarn_variable_types =
initialize_warn_hash( 'warn-variable-types', 0, \@all_opts,
$wvt_in_args );
+ # Turn off types 'u' and 'c' if we are not operating on a named file
+ # or are under editor line range control
+ if ( $rOpts->{'line-range-tidy'} || !$num_files ) {
+ $rwarn_variable_types->{u} = 0;
+ $rwarn_variable_types->{c} = 0;
+ }
+
+ # Set 'u' and 'c' conditional on starting indentation = 0 if just 1 file
+ # and -wvt is not on cmd line. The reason is that if -wvt is in the
+ # perltidyrc file, and we are operating on just one file, it could be
+ # a temporary file created by an editor. Requiring a starting level
+ # of zero is a defensive strategy for minimizing the chance of
+ # incorrect warnings when formatting a short snippet.
+ else {
+ if ( !$wvt_in_args && $num_files <= 1 ) {
+ $rwarn_variable_types->{require_sil_zero} = 1;
+ }
+ }
+
$ris_warn_variable_excluded_name =
make_excluded_name_hash('warn-variable-exclusion-list');
return;
my $wv_option = $rOpts->{$wv_key};
return unless ( %{$rwarn_variable_types} );
+ # Make a copy of the control hash
+ my $rwarn_variable_types_copy = {};
+ foreach my $key ( keys %{$rwarn_variable_types} ) {
+ next if ( length($key) > 1 );
+ $rwarn_variable_types_copy->{$key} = $rwarn_variable_types->{$key};
+ }
+
+ # If requested, we must turn off 'u' and 'c' if starting level is not zero
+ if ( $rwarn_variable_types->{require_sil_zero} ) {
+ my $rLL = $self->[_rLL_];
+ my $sil = $rLL->[0]->[_LEVEL_];
+ if ($sil) {
+ $rwarn_variable_types_copy->{u} = 0;
+ $rwarn_variable_types_copy->{c} = 0;
+ }
+ }
+
my ( $rwarnings, $issue_type_string ) =
- $self->scan_variable_usage($rwarn_variable_types);
+ $self->scan_variable_usage($rwarn_variable_types_copy);
return unless ( $rwarnings && @{$rwarnings} );
$rwarnings =