2016-10-03 8 views
1

私は、次のコードにPerlCriticを走った:私は、使用するコマンドだったPerlCriticフラグProhibitMagicNumbers違反10回のみ

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, %l\n" 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回以上のエラーを発生させる方法はありますか?

答えて

1

perlcriticコマンドオプションを使用して、ProhibitMagicNumbers違反の回数を増やす方法はありません。

しかし、Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbersのソースコードを検索すると、この制限はdefault_maximum_violations_per_documentサブで設定されていることがわかります。 t/02_policy.tテストでは、制限を変更する方法が示されています。

コード管理者に問題を提出することで、値を変更する簡単な方法をリクエストできます。

+0

コマンドラインツールを使用するときに制限を変更する方法はないと思います。それは...ですか? –

関連する問題