]> git.donarmstrong.com Git - perltidy.git/commitdiff
check all eval return values
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 18 Jun 2022 15:37:18 +0000 (08:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 18 Jun 2022 15:37:18 +0000 (08:37 -0700)
.perlcriticrc
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/LineSource.pm
lib/Perl/Tidy/Logger.pm
lib/Perl/Tidy/Tokenizer.pm

index 98ae2e0acbfc8e49573aa310a36e03f5e6bcadce..a68dc59a563c343ca051e1fe5156b018fdcc99a5 100644 (file)
@@ -11,8 +11,10 @@ verbose = %f: [%p] %m at line %l, column %c.\n
 # Example command to run a single policy on single module:
 # perlcritic --single-policy Subroutines::ProhibitSubroutinePrototypes Module.pm
 
-# Below is a list of policies that customize perlcritic to the needs of
-# Perl::Tidy.
+# Below is a list of policies that are skipped or customized to the needs of
+# Perl::Tidy.  After experimenting with ## no critic comments, I decided that
+# they cause more trouble than the value they provide, so policies are either
+# 'on' or 'off'.
 
 #--------------------------------------------------------------
 # Following is a list of policies to be skipped for severity=4:
@@ -27,7 +29,7 @@ verbose = %f: [%p] %m at line %l, column %c.\n
 
 # There is a stringy eval in Formatter.pm and Tokenizer.pm which is essential
 # for checking user input. So we have to skip this.
-[-BuiltinFunctions::ProhibitStringyEval] 
+[-BuiltinFunctions::ProhibitStringyEval]
 
 # Tidy.pm exports 'perltidy'. Changing this could break existing scripts.
 [-Modules::ProhibitAutomaticExportation]
@@ -82,9 +84,6 @@ max_nests=11
 # Agree - these are in process of being converted to if's
 [-ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
 
-# Agree - checks are in process of being checked
-[-ErrorHandling::RequireCheckingReturnValueOfEval] 
-
 # This is a good general policy but not always the best for efficiency
 [-Subroutines::ProhibitManyArgs]
 
index 3fb419ff02e513f16bd7391e656b6cc7d755c4f3..d70b4ec559aef004f558114f211dddc6477fee9b 100644 (file)
@@ -4533,8 +4533,8 @@ sub bad_pattern {
     # but it should be safe because the pattern has been constructed
     # by this program.
     my ($pattern) = @_;
-    eval "'##'=~/$pattern/";
-    return $EVAL_ERROR;
+    my $ok = eval "'##'=~/$pattern/";
+    return !defined($ok) || $EVAL_ERROR;
 }
 
 {    ## begin closure prepare_cuddled_block_types
index 9c56ea7c4410785083ae2d192d6ae5cdcd288f5c..288beb58bcace60c89a1b10dd657e07bef91f660 100644 (file)
@@ -8,8 +8,11 @@
 package Perl::Tidy::LineSource;
 use strict;
 use warnings;
+use English qw( -no_match_vars );
 our $VERSION = '20220613';
 
+use constant DEVEL_MODE => 0;
+
 sub AUTOLOAD {
 
     # Catch any undefined sub calls so that we are sure to get
@@ -86,7 +89,10 @@ sub close_input_file {
     # Only close physical files, not STDIN and other objects
     my $filename = $self->{_filename};
     if ( $filename ne '-' && !ref $filename ) {
-        eval { $self->{_fh}->close() };
+        my $ok = eval { $self->{_fh}->close(); 1 };
+        if ( !$ok && DEVEL_MODE ) {
+            Fault("Could not close file handle(): $EVAL_ERROR\n");
+        }
     }
     return;
 }
index b005abd9f414171d681b00b3dceb0ad6c06d8c95..93e54b3d9dbd6b76888eaa79fb9f2c93a5551c3e 100644 (file)
@@ -10,6 +10,7 @@ use warnings;
 our $VERSION = '20220613';
 use English qw( -no_match_vars );
 
+use constant DEVEL_MODE   => 0;
 use constant EMPTY_STRING => q{};
 use constant SPACE        => q{ };
 
@@ -496,11 +497,13 @@ sub finish {
             my $routput_array = $self->{_output_array};
             foreach my $line ( @{$routput_array} ) { $fh->print($line) }
             if ( $log_file ne '-' && !ref $log_file ) {
-                eval { $fh->close() };
+                my $ok = eval { $fh->close(); 1 };
+                if ( !$ok && DEVEL_MODE ) {
+                    Fault("Could not close file handle(): $EVAL_ERROR\n");
+                }
             }
         }
     }
     return;
 }
 1;
-
index ba87a97a681143af2a7d82ae622441ec57b4292c..894bb70ae22f950ff79f86eb5cb8e26188f3a4c0 100644 (file)
@@ -281,8 +281,8 @@ sub bad_pattern {
     # but it should be safe because the pattern has been constructed
     # by this program.
     my ($pattern) = @_;
-    eval "'##'=~/$pattern/";
-    return $EVAL_ERROR;
+    my $ok = eval "'##'=~/$pattern/";
+    return !defined($ok) || $EVAL_ERROR;
 }
 
 sub make_code_skipping_pattern {