Skip to content

Commit

Permalink
linter: copy rules (#1177)
Browse files Browse the repository at this point in the history
Co-authored-by: Makhnev Petr <51853996+i582@users.noreply.github.com>
  • Loading branch information
Danil42Russia and i582 authored Jun 22, 2022
1 parent 4f34e25 commit f482dfd
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 1 deletion.
59 changes: 58 additions & 1 deletion docs/checkers_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

| Total checks | Checks enabled by default | Disabled checks by default | Autofixable checks |
| ------------ | ------------------------- | -------------------------- | ------------------ |
| 99 | 82 | 17 | 12 |
| 102 | 85 | 17 | 12 |

## Table of contents
- Enabled by default
Expand Down Expand Up @@ -89,6 +89,9 @@
- [`undefinedVariable` checker](#undefinedvariable-checker)
- [`unimplemented` checker](#unimplemented-checker)
- [`unused` checker](#unused-checker)
- [`useEval` checker](#useeval-checker)
- [`useExitOrDie` checker](#useexitordie-checker)
- [`useSleep` checker](#usesleep-checker)
- [`varShadow` checker](#varshadow-checker)
- Disabled by default
- [`argsReverse` checker](#argsreverse-checker)
Expand Down Expand Up @@ -1759,6 +1762,60 @@ return [$result, $err];
<p><br></p>


### `useEval` checker

#### Description

Report using `eval` function.

#### Non-compliant code:
```php
eval("2 + 2");
```

#### Compliant code:
```php
// no eval
```
<p><br></p>


### `useExitOrDie` checker

#### Description

Report using `exit` or `die` functions.

#### Non-compliant code:
```php
exit(1);
```

#### Compliant code:
```php
// no exit
```
<p><br></p>


### `useSleep` checker

#### Description

Report using `sleep` function.

#### Non-compliant code:
```php
sleep(10);
```

#### Compliant code:
```php
// no sleep
```
<p><br></p>


### `varShadow` checker

#### Description
Expand Down
41 changes: 41 additions & 0 deletions src/cmd/embeddedrules/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,44 @@ function concatenationPrecedence() {
$_ . $_ >> $_;
}
}

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

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

/**
* @comment Report using `eval` function.
* @before eval("2 + 2");
* @after // no eval
*/
function useEval() {
/**
* @warning Don't use the 'eval' function
*/
eval($_);
}

/**
* @comment Report using `sleep` function.
* @before sleep(10);
* @after // no sleep
*/
function useSleep() {
/**
* @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 useEval: 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 useSleep: Don't use the 'sleep' function at testdata/phprocksyd/Phprocksyd.php:8
sleep(10);
^^^^^^^^^
WARNING useSleep: 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 useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:75
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:82
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:87
exit(0);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:93
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:98
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:118
exit(1);
^^^^^^^
WARNING useExitOrDie: 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 useExitOrDie: 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 useExitOrDie: 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 useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:557
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:590
exit(0);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:619
exit(1);
^^^^^^^
WARNING useExitOrDie: Don't use the 'exit' function at testdata/phprocksyd/Phprocksyd.php:685
exit(0);
^^^^^^^
WARNING useExitOrDie: 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 useExitOrDie: 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
7 changes: 7 additions & 0 deletions src/tests/inline/testdata/embeddedrules/useEval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

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

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

function useExitOrDie() {
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`
}
5 changes: 5 additions & 0 deletions src/tests/inline/testdata/embeddedrules/useSleep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

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

0 comments on commit f482dfd

Please sign in to comment.