/ / PerlCritic príznaky ProhibitMagicNumbers porušenie iba 10 krát - perl, perl-krit

Príznaky PerlCritic ProhibitMagicNumbers porušujú iba 10-krát - perl, perl-crit

Spustil som PerlCritic na nasledujúcom kóde:

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;
}
};

Príkaz, ktorý som použil, bol (názov súboru bol test_9.pl)

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

Toto je výsledok, ktorý som dostal po spustení vyššie uvedeného príkazu

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

Ako je vidieť, existuje veľa príkladov pevne zakódovaných hodnôt, ale PerlCritic toto porušenie označuje Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers iba 10 krát. Existuje spôsob, ako urobiť príznak PerlCritic chybu viac ako 10-krát?

odpovede:

1 pre odpoveď č. 1

Nevidím žiadny spôsob, ako zvýšiť počet ProhibitMagicNumbers porušenia pomocou len perlcritic príkazové voľby.

Hľadanie v zdrojovom kóde Perl :: kritikov :: Politické :: ValuesAndExpressions :: ProhibitMagicNumbersVidím, že tento limit je stanovený default_maximum_violations_per_document sub. t/02_policy.t test ukazuje, ako zmeniť limit.

Môžete požiadať o jednoduchší spôsob zmeny hodnoty odoslaním problému správcom kódu.