]> git.donarmstrong.com Git - perltidy.git/commitdiff
minor change in syntax of --use-feature
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 28 Aug 2023 01:24:03 +0000 (18:24 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 28 Aug 2023 01:24:03 +0000 (18:24 -0700)
The default behavior remains the same.  Details in CHANGES

.perlcriticrc
CHANGES.md
bin/perltidy
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index fcbea47de61d69b78b4e057d1b28d74349539638..d6a47abcb3ae713b8915f924e0daefde3b777488 100644 (file)
@@ -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.
index be348a917ec203025cae908f5ba9bb83f35f2905..2ce1bc6b44b44d4a4c2c4e98ce770d05c6d6eb91 100644 (file)
@@ -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.
index eaaa98d3ee74cad397332fda33318e07fb187e7d..4a54bc41c1f935b6be9aef8ab6869ae883fe09be 100755 (executable)
@@ -4936,8 +4936,8 @@ by listing them in the string B<s>.  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<s>.  The current possible settings are:
+This flag tells perltidy to allow or disallow the syntax associated a pragma in
+string B<s>.  The current possible settings are:
 
 =over 4
 
@@ -4948,11 +4948,14 @@ B<class>, B<method>, B<field>, and B<ADJUST> as defined for this feature.
 
 =item *
 
-B<--use-feature=' '>.  This tells perltidy not to treat words B<class>, B<method>, B<field>, B<ADJUST> specially.
+B<--use-feature='noclass'>.  This tells perltidy B<not> to treat words B<class>, B<method>, B<field>, B<ADJUST> 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<Neither of these> (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
 
index 0b1b75511713f926bd2d99e7d4fb5cc8dfc0e0fa..d479bfd21f00e862ecb8d0ced2e4e0301413474f 100644 (file)
@@ -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.
index d29b52b0b939b3160b1488a48880b304aa179d81..27a7b0e6778a3b31b85f6da139b83aef38f44e7a 100644 (file)
@@ -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