Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter: copy rules #1177

Merged
merged 11 commits into from
Jun 22, 2022
35 changes: 35 additions & 0 deletions src/cmd/embeddedrules/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,38 @@ function concatenationPrecedence() {
$_ . $_ >> $_;
}
}

/**
* @comment Report using `exit` or 'die' functions.
*/
function usageExitOrDie() {
/**
* @warning Don't use the 'exit' function
*/
exit($_);

/**
* @warning Don't use the 'die' function
*/
die($_);
}

/**
* @comment Report using `eval' function.
i582 marked this conversation as resolved.
Show resolved Hide resolved
*/
function useEvalCheck() {
/**
* @warning Don't use the 'eval' function
*/
eval($_);
}

/**
* @comment Report using `sleep' function.
*/
function useSleepCheck() {
/**
* @warning Don't use the 'sleep' function
*/
sleep($_);
}
3 changes: 3 additions & 0 deletions src/tests/golden/testdata/mustache/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ MAYBE ternarySimplify: Could rewrite as `$this->fileMode ?? (0666 & ~umask())`
WARNING errorSilence: Don't use @, silencing errors is bad practice at testdata/mustache/src/Mustache/Cache/FilesystemCache.php:143
@chmod($fileName, $mode);
^^^^^^^^^^^^^^^^^^^^^^^^
WARNING useEvalCheck: Don't use the 'eval' function at testdata/mustache/src/Mustache/Cache/NoopCache.php:45
eval('?>' . $value);
^^^^^^^^^^^^^^^^^^^
MAYBE ternarySimplify: Could rewrite as `$node[Mustache_Tokenizer::FILTERS] ?? array()` at testdata/mustache/src/Mustache/Compiler.php:99
isset($node[Mustache_Tokenizer::FILTERS]) ? $node[Mustache_Tokenizer::FILTERS] : array(),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
48 changes: 48 additions & 0 deletions src/tests/golden/testdata/phprocksyd/golden.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
WARNING useSleepCheck: Don't use the 'sleep' function at testdata/phprocksyd/Phprocksyd.php:8
sleep(10);
^^^^^^^^^
WARNING useSleepCheck: Don't use the 'sleep' function at testdata/phprocksyd/Phprocksyd.php:18
sleep(100);
^^^^^^^^^^
MAYBE deprecated: Call to deprecated function dl (since: 5.3) at testdata/phprocksyd/Phprocksyd.php:73
if (!extension_loaded($ext) && !dl($ext . '.so')) {
^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:75
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:82
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:87
exit(0);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:93
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:98
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:118
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:129
exit(1);
^^^^^^^
ERROR constCase: Constant 'NULL' should be used in lower case as 'null' at testdata/phprocksyd/Phprocksyd.php:321
$n = stream_select($read, $write, $except, NULL);
^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:325
exit(1);
^^^^^^^
WARNING invalidDocblock: Malformed @param $stream_id tag (maybe type is missing?) at testdata/phprocksyd/Phprocksyd.php:364
* @param $stream_id
^^^^^^^^^^
Expand Down Expand Up @@ -31,9 +61,27 @@ WARNING invalidDocblock: Malformed @param $stream_id tag (maybe type is missing?
WARNING invalidDocblock: Malformed @param $req tag (maybe type is missing?) at testdata/phprocksyd/Phprocksyd.php:444
* @param $req
^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:481
exit(0);
^^^^^^^
ERROR undefinedMethod: Call to undefined method {mixed}->run() at testdata/phprocksyd/Phprocksyd.php:479
$instance->run($req['params']);
^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:557
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:590
exit(0);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:619
exit(1);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:685
exit(0);
^^^^^^^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Simple.php:38
exit(1);
^^^^^^^
ERROR constCase: Constant 'NULL' should be used in lower case as 'null' at testdata/phprocksyd/Simple.php:158
$n = stream_select($read, $write, $except, NULL);
^^^^
3 changes: 3 additions & 0 deletions src/tests/golden/testdata/qrcode/golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ MAYBE callSimplify: Could simplify to $group[1] at testdata/qrcode/qrcode.php:
WARNING switchDefault: Add 'default' branch to avoid unexpected unhandled condition values at testdata/qrcode/qrcode.php:697
switch ($mask) {
^
WARNING usageExitOrDie: Don't use the 'exit' function at testdata/qrcode/qrcode.php:33
exit(0);
^^^^^^^
ERROR classMembersOrder: Property $qr_capacity must go before methods in the class QRCode at testdata/qrcode/qrcode.php:890
private $qr_capacity = [
^^
Expand Down
9 changes: 9 additions & 0 deletions src/tests/inline/testdata/embeddedrules/usageExitOrDie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

function usageExitOrDie() {
exit; // want `Don't use the 'exit' function`
exit(1); // want `Don't use the 'exit' function`

die; // want `Don't use the 'die' function`
die("die"); // want `Don't use the 'die' function`
}
7 changes: 7 additions & 0 deletions src/tests/inline/testdata/embeddedrules/useEvalCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

function useEvalCheck() {
$hello = "Hello NoVerify!";

eval("echo \"$hello\";"); // want `Don't use the 'eval' function`
}
5 changes: 5 additions & 0 deletions src/tests/inline/testdata/embeddedrules/useSleepCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

function useSleepCheck() {
sleep(5); // want `Don't use the 'sleep' function`
}