Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 72823
Status: open
Priority: 0/
Queue: Perl-Critic

Owner: Nobody in particular
Requestors: EDAVIS [...]

Bug Information
Severity: Normal
Broken in: 1.116
Fixed in: (no value)

Subject: ProhibitMagicNumbers does not recognize octal in allowed_values
Download (untitled) / with headers
text/plain 812b
Create test program 'testprog' with content $x = 020; Checking this with % perlcritic --single-policy ValuesAndExpressions::ProhibitMagicNumbers testprog gives a warning that 020 is not an allowed literal value. Fine so far. But create a configuration file 'rc' with content [ValuesAndExpressions::ProhibitMagicNumbers] allowed_values = 020 and recheck with % perlcritic -t rc --single-policy ValuesAndExpressions::ProhibitMagicNumbers testprog The same warning appears. On the other hand, '20' instead of '020' behaves correctly in that adding it to allowed_values stops the warning. I suggest that to add support for octal (and hexadecimal), each base should be treated separately. So adding '020' to allowed_values would not mean that '16' is allowed, nor the other way. (And similar for '0x10'.)
Download (untitled) / with headers
text/plain 641b
Heh, and I see that if you try to work around this and add the decimal value to the allowed_values list, the policy falls back to its second line of defence, 'Octal literals are not allowed'. Perhaps that should be moved into a separate policy? Whether to allow octal (or hexadecimal) literals at all is one thing; whether literals in general should be 'constant' or 'Readonly' is another thing. If you feel that the same policy should enforce both rules, then I suggest that 'Octal literals are not allowed' should appear as the normal message when you use an octal number in code, rather than 'is not one of the allowed literal values'.
Download (untitled) / with headers
text/plain 137b
...and if the user tries to put octal notation into the allowed_values list, that should be an error when parsing the configuration file.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to