NAME
TooMuchCode::ProhibitDuplicateLiteral - Don't repeat yourself with identical literals
DESCRIPTION
This policy checks if there are string/number literals with identical value in the same piece of perl code. Usually that's a small signal of repeating and perhaps a small chance of refactoring.
CONFIGURATION
Some strings/numbers may be allowed to have duplicates by listing them in the whitelist
parameter in the configs:
[TooMuchCode:ProhibitDuplicateLiteral]
whitelist = 'present' "forty two" 42
The values is a space-separated list of numbers or quoted string.
The default values in the whitelist are: 0 1
. This two numbers are always part of whitelist and cannot be removed.
Please be aware that, a string literal and its numerical literal counterpart (1
vs "1"
) are considered to be the same. Whitelisting "42"
would also whitelist 42
together.
DEPRECATED CONFIGURATIONS
The whitelist
parameter replace another parameter name whitelist_numbers
, which serves the same purpose but only numbers were supported.
The default value of whitelist_numbers is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9
To opt-out more, add whitelist_numbers
like this in .perlcriticrc
[TooMuchCode::ProhibitDuplicateLiteral]
whitelist_numbers = 42, 10
The numbers given to whitelist_numbers
are appended and there is no way to remove default values.
It is still supported in current release but will be removed in near future. Please check the content of Changes
for the announcement.