Prohibit map and grep in void context
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 31 Aug 2021 09:07:04 +0000 (11:07 +0200)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 31 Aug 2021 09:07:04 +0000 (11:07 +0200)
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 <ilmari@ilmari.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://postgr.es/m/87fsvzhhc4.fsf@wibble.ilmari.org

contrib/intarray/bench/create_test.pl
src/tools/perlcheck/perlcriticrc

index 993a4572f416700b22673d310fe63bf4e801e9fa..ae8d72bab03d535d95d156009a83d58facfdc13f 100755 (executable)
@@ -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;
index e230111b232bf6d9ac59fa39df124858bbfd1449..9267fb43b27f3ba3039f20717b30ed77d1ef6945 100644 (file)
@@ -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