From 6ea7f6bd9f086a0ad605c04daa952cc2f3c99f37 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 27 Aug 2023 18:24:03 -0700 Subject: [PATCH] minor change in syntax of --use-feature The default behavior remains the same. Details in CHANGES --- .perlcriticrc | 26 ++++++++++++++++---------- CHANGES.md | 10 ++++++++++ bin/perltidy | 11 +++++++---- lib/Perl/Tidy/Formatter.pm | 15 ++++----------- lib/Perl/Tidy/Tokenizer.pm | 8 ++++---- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/.perlcriticrc b/.perlcriticrc index fcbea47d..d6a47abc 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -9,9 +9,14 @@ # Example command to run a single policy on single module: # perlcritic --single-policy Subroutines::ProhibitSubroutinePrototypes Module.pm -# This file lists the policies which must be turned off for Perl::Tidy. Many -# of the policies are excellent starting points for new code, but important -# exceptions often exist which make it impossible to use them as rigid rules. +# This file lists the policies which must be adjusted or deactivated for +# Perl::Tidy. Many of the policies are excellent starting points for new code, +# but important exceptions often exist which make it impossible to use them as +# rigid rules. + +# I have found the '## no critic' method for locally deactivating specific +# policies with comments to be too troublesome to use. So unfortunately +# policies are either on or off. # severity = 1 gives the most strict checking. severity = 1 @@ -50,12 +55,12 @@ short_subroutine_statements = 2 # my editor uses color to make it clear if interpolation is in effect. [-ValuesAndExpressions::RequireQuotedHeredocTerminator] -# Perlcritic doesn't know that ARGV in Perl::Tidy actually is localized. -# Localization of @ARGV could be avoided by calling GetOptionsFromArray -# instead of GetOptions, but that is not available before perl 5.10, and -# we want to continue supporting Perl 5.8. So we have to skip this for now. -# When the time comes to make perl 5.10 the earliest version supported, -# this restriction can be deleted +# Perlcritic doesn't seem to know that @ARGV in Perl::Tidy actually **is** +# localized. Localization of @ARGV could be avoided by calling +# GetOptionsFromArray instead of GetOptions, but that is not available before +# perl 5.10, and we want to continue supporting Perl 5.8. So we have to skip +# this for now. When the time comes to make perl 5.10 the earliest version +# supported, this restriction can be deleted [-Variables::RequireLocalizedPunctuationVars] # sub 'backup_method_copy' in Perl::Tidy.pm has about 25 lines between open @@ -84,7 +89,8 @@ max_mccabe=180 [ControlStructures::ProhibitDeepNests] max_nests=9 -# This would be nice, but there are many cases where this is really impossible. +# This would be nice, but in reality there are many cases where these cannot be +# avoided. [-ControlStructures::ProhibitCascadingIfElse] # This is a reasonable starting point but does not work well as a rigid rule. diff --git a/CHANGES.md b/CHANGES.md index be348a91..2ce1bc6b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,16 @@ ## 2023 07 01.03 + - The syntax of the parameter --use-feature=class, or -uf=class, which + new in the previous release, has been changed slightly for clarity. + The default behavior, which occurs if this flag is not entered, is + to automatically try to handle both old and new uses of the keywords + 'class', 'method', 'field', and 'ADJUST'. + To force these keywords to only follow the -use feature 'class' syntax, + enter --use-feature=class. + To force perltidy to ignore the -use feature 'class' syntax, enter + --use-feature=noclass. + - Issue git #122. Added parameter -lrt=n1:n2, or --line-range-tidy=n1:n2 to limit tidy operations to a limited line range. Line numbers start with 1. The man pages have details. diff --git a/bin/perltidy b/bin/perltidy index eaaa98d3..4a54bc41 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -4936,8 +4936,8 @@ by listing them in the string B. To remove all of the default operators use =item B<-uf=s>, B<--use-feature=s> -This flag tells perltidy to allow the syntax associated a pragma in string -B. The current possible settings are: +This flag tells perltidy to allow or disallow the syntax associated a pragma in +string B. The current possible settings are: =over 4 @@ -4948,11 +4948,14 @@ B, B, B, and B as defined for this feature. =item * -B<--use-feature=' '>. This tells perltidy not to treat words B, B, B, B specially. +B<--use-feature='noclass'>. This tells perltidy B to treat words B, B, B, B specially. =item * -B<--use-feature> not defined B<[DEFAULT]>. In this case perltidy will try to handle both the newer --use-feature 'class' syntax as well as some older overlapping uses, in particular for the keyword 'method'. +B (B<--use-feature> not defined). This is the DEFAULT and +recommended setting. In this case perltidy will try to automatically handle +both the newer --use-feature 'class' syntax as well as some conflicting +uses of some of these special words by exisiting modules. =back diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0b1b7551..d479bfd2 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -5359,20 +5359,13 @@ sub make_sub_matching_pattern { push @words, 'sub'; } - # Also include 'method' if necessary for '--use-feature=class': - # - if user does NOT set 'use-feature', assume 'use-feature=class': - if ( !defined( $rOpts->{'use-feature'} ) ) { + # add 'method' unless use-feature='noclass' is set. + if ( !defined( $rOpts->{'use-feature'} ) + || $rOpts->{'use-feature'} !~ /\bnoclass\b/ ) + { push @words, 'method'; } - # - if user sets 'use-feature', then only add 'method' if - # use-feature=class is set. - else { - if ( $rOpts->{'use-feature'} =~ /\bclass\b/ ) { - push @words, 'method'; - } - } - # Note (see also RT #133130): These patterns are used by # sub make_block_pattern, which is used for making most patterns. # So this sub needs to be called before other pattern-making routines. diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index d29b52b0..27a7b0e6 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -363,12 +363,12 @@ sub check_options { my $use_feature_class = 1; if ( $rOpts->{'use-feature'} ) { - if ( $rOpts->{'use-feature'} =~ /\bclass\b/ ) { - $guess_if_method = 0; - } - else { + if ( $rOpts->{'use-feature'} =~ /\bnoclass\b/ ) { $use_feature_class = 0; } + elsif ( $rOpts->{'use-feature'} =~ /\bclass\b/ ) { + $guess_if_method = 0; + } } # These are the main updates for this option. There are additional -- 2.39.5