PerlCritic只标记10次ProhibitMagicNumbers违规



我在以下代码上运行PerlCritic:

my @map;
$map{3}=3;
$map{2}=2;
$map{1}=1;
$map{6}=6;
$map{4}=4;
$map{12}=13;
$map{5}=5;
$map{11}=11;
$map{7}=7;
$map{23}=23;
$map{15}=15;
$map{47}=49;
$map{10}=10;
$map{31}=32;
$map{95}=104;
$map{21}=22;
$map{63}=69;
$map{190}=222;
$map{14}=14;
$map{42}=46;
$map{127}=147;
$map{381}=473;
$map{9}=9;
$map{28}=30;
$map{84}=98;
$map{254}=314;
$map{762}=1009;
$map{18}=19;
$map{56}=63;
$map{169}=207;
$map{508}=668;
$map{1525}=2150;
$map{37}=41;
$map{113}=134;
for (my $var = 0; $var < 10; $var++) {
    my $input = <>;
    if($input eq """")
    {
        goto getout;
    }
    chomp($input);
    print coinSub($input);
    print ""n"";
};
getout:;
sub coinSub{
    my $coin = shift;
    if($map{$coin} eq """")
    {
        my $coinA = int($coin / 2);
        my $coinB = int($coin / 3);
        my $coinC = int($coin / 4);
        if($coinA < 2 or $coinB < 2 or $coinB < 2)
        {
            goto subEnd;
        }
        $coinA = coinSub($coinA);
        $coinB = coinSub($coinB);
        $coinC = coinSub($coinC);
subEnd:;
        my $exchangeAmt = $coinA + $coinB + $coinC;
        $map{$coin} = max($exchangeAmt,$coin);
        return max($exchangeAmt,$coin);
    }
    else
    {
        return $map{$coin};
    }
};
sub max{
    my $no1 = shift;
    my $no2 = shift;
    if($no1 > $no2)
    {
        return $no1;
    }
    else
    {
        return $no2;
    }
};

我使用的命令是(文件名为test_9.pl)

perlcritic --brutal --theme core --verbose "%f, %P, %m, %ln" test_9.pl

这是我运行上面命令后得到的结果

test_9.pl, Perl::Critic::Policy::CodeLayout::RequireTidyCode, perltidy had errors!!, 1
test_9.pl, Perl::Critic::Policy::Modules::RequireExplicitPackage, Code not contained in explicit package, 1
test_9.pl, Perl::Critic::Policy::Modules::RequireVersionVar, No package-scoped "$VERSION" variable found, 1
test_9.pl, Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict, Code before strictures are enabled, 1
test_9.pl, Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings, Code before warnings are enabled, 1
test_9.pl, Perl::Critic::Policy::Variables::ProhibitUnusedVariables, "@map" is declared but not used, 1
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 3 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 2
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 3 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 2
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 6 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 5
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 6 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 5
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 4 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 6
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 4 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 6
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 12 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 7
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 13 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 7
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 5 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 8
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers, 5 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead, 8
test_9.pl, Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops, C-style "for" loop used, 37
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 39
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 39
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 39
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 39
test_9.pl, Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins, Builtin function called with parentheses, 43
test_9.pl, Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls, Return value of flagged function ignored - print, 44
test_9.pl, Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls, Return value of flagged function ignored - print, 45
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 45
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 45
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 45
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 45
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Label "getout" is not all upper case, 47
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Subroutine "coinSub" is not all lower case or all upper case, 48
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 50
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 50
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes, Quotes used with a string containing no non-whitespace characters, 50
test_9.pl, Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals, Useless interpolation of literal string, 50
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Local lexical variable "$coinA" is not all lower case or all upper case, 52
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Local lexical variable "$coinB" is not all lower case or all upper case, 53
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Local lexical variable "$coinC" is not all lower case or all upper case, 54
test_9.pl, Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace, Found "t" at the end of the line, 62
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Label "subEnd" is not all upper case, 63
test_9.pl, Perl::Critic::Policy::NamingConventions::Capitalization, Local lexical variable "$exchangeAmt" is not all lower case or all upper case, 64
test_9.pl, Perl::Critic::Policy::Modules::RequireEndWithOne, Module does not end with "1;", 73

可以看到,有许多硬编码值的实例,但是PerlCritic只标记了违反Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers 10次。是否有一种方法可以使PerlCritic标记错误超过10次?

我无法看到仅使用perlcritic命令选项来增加ProhibitMagicNumbers违规的数量。

然而,通过源代码搜索Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers,我可以看到这个限制是由default_maximum_violations_per_document子设置的。t/02_policy.t测试显示了如何更改限制。

您可以通过向代码维护者提交issue来请求一种更简单的方法来更改该值。

相关内容

  • 没有找到相关文章

最新更新