summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gustafsson2021-08-31 09:07:04 +0000
committerDaniel Gustafsson2021-08-31 09:07:04 +0000
commitbb466c6b0992a1a21c03239a7b0a87ebadd3bee1 (patch)
treeca337e27f75307637ab18311e0c733e03f517587
parentf2bbadce6b5052337a11a33ea6bd8d8aebe2610a (diff)
Prohibit map and grep in void context
map and grep are not intended to be used as mutators, iterating with side-effects should be done with for or foreach loops. This fixes the one occurrence of the pattern, and bumps the perlcritic policy to severity 5 for the map and grep policies. Author: Dagfinn Ilmari MannsÃ¥ker <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Andrew Dunstan <[email protected]> Reviewed-by: Julien Rouhaud <[email protected]> Discussion: https://postgr.es/m/[email protected]
-rwxr-xr-xcontrib/intarray/bench/create_test.pl2
-rw-r--r--src/tools/perlcheck/perlcriticrc7
2 files changed, 8 insertions, 1 deletions
diff --git a/contrib/intarray/bench/create_test.pl b/contrib/intarray/bench/create_test.pl
index 993a4572f41..ae8d72bab03 100755
--- a/contrib/intarray/bench/create_test.pl
+++ b/contrib/intarray/bench/create_test.pl
@@ -51,7 +51,7 @@ foreach my $i (1 .. 200000)
else
{
print $msg "$i\t{" . join(',', @sect) . "}\n";
- map { print $map "$i\t$_\n" } @sect;
+ print $map "$i\t$_\n" foreach @sect;
}
}
close $map;
diff --git a/src/tools/perlcheck/perlcriticrc b/src/tools/perlcheck/perlcriticrc
index e230111b232..9267fb43b27 100644
--- a/src/tools/perlcheck/perlcriticrc
+++ b/src/tools/perlcheck/perlcriticrc
@@ -22,3 +22,10 @@ verbose = %f: %m at line %l, column %c. %e. ([%p] Severity: %s)\n
# insist on use of the warnings pragma
[TestingAndDebugging::RequireUseWarnings]
severity = 5
+
+# forbid grep and map in void context
+[BuiltinFunctions::ProhibitVoidGrep]
+severity = 5
+
+[BuiltinFunctions::ProhibitVoidMap]
+severity = 5