Просмотр исходного кода

scripts: Do not use negative expression in unless and until conditions

These are double negations which are hard to grasp at a first glance.

Fixes ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions.
Guillem Jover лет назад: 13
Родитель
Сommit
840d3d8836

+ 1 - 1
scripts/Dpkg/Compression.pm

@@ -201,7 +201,7 @@ sub compression_get_default_level {
 sub compression_set_default_level {
     my ($level) = @_;
     error(_g('%s is not a compression level'), $level)
-            unless !defined($level) or compression_is_valid_level($level);
+        if defined($level) and not compression_is_valid_level($level);
     $default_compression_level = $level;
 }
 

+ 2 - 1
scripts/Dpkg/Source/Archive.pm

@@ -79,7 +79,8 @@ sub add_directory {
     if (*$self->{chdir}) {
         $testfile = File::Spec->catdir(*$self->{chdir}, $file);
     }
-    internerr('add_directory() only handles directories') unless not -l $testfile and -d _;
+    internerr('add_directory() only handles directories')
+        if -l $testfile or not -d _;
     $self->_add_entry($file);
 }
 

+ 1 - 1
scripts/dpkg-buildpackage.pl

@@ -399,7 +399,7 @@ unless (build_binaryonly) {
     chdir($dir) or syserr("chdir $dir");
 }
 
-unless ($buildtarget eq 'build' or scalar(@debian_rules) > 1) {
+if ($buildtarget ne 'build' and scalar(@debian_rules) == 1) {
     # Verify that build-{arch,indep} are supported. If not, fallback to build.
     # This is a temporary measure to not break too many packages on a flag day.
     my $pid = spawn(exec => [ 'make', '-f', @debian_rules, '-qn', $buildtarget ],

+ 3 - 3
scripts/dpkg-genchanges.pl

@@ -245,13 +245,13 @@ if (not is_sourceonly) {
 			$1, $.);
 	    $f2sec{$1}= $5;
 	    $f2pri{$1}= $6;
-	    push(@archvalues,$4) unless !$4 || $archadded{$4}++;
+	    push(@archvalues, $4) if $4 and not $archadded{$4}++;
 	    push(@fileslistfiles,$1);
 	} elsif (m/^([-+.0-9a-z]+_[^_]+_([-\w]+)\.[a-z0-9.]+) (\S+) (\S+)$/) {
 	    # A non-deb package
 	    $f2sec{$1}= $3;
 	    $f2pri{$1}= $4;
-	    push(@archvalues,$2) unless !$2 || $archadded{$2}++;
+	    push(@archvalues, $2) if $2 and not $archadded{$2}++;
 	    push(@fileslistfiles,$1);
 	} elsif (m/^([-+.,_0-9a-zA-Z]+) (\S+) (\S+)$/) {
 	    defined($f2sec{$1}) &&
@@ -324,7 +324,7 @@ foreach my $pkg ($control->get_packages()) {
 	    } elsif (!debarch_eq('all', $v)) {
 		$v = '';
 	    }
-	    push(@archvalues,$v) unless !$v || $archadded{$v}++;
+	    push(@archvalues, $v) if $v and not $archadded{$v}++;
         } elsif (m/^Description$/) {
             # Description in changes is computed, do not copy this field
 	} else {

+ 1 - 0
test/100_critic.t

@@ -50,6 +50,7 @@ my @policies = qw(
     CodeLayout::RequireConsistentNewlines
     ControlStructures::ProhibitCStyleForLoops
     ControlStructures::ProhibitLabelsWithSpecialBlockNames
+    ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions
     ControlStructures::ProhibitUntilBlocks
     Documentation::RequirePackageMatchesPodName
     InputOutput::ProhibitBarewordFileHandles