mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-29 20:20:57 -05:00
Support for testing PHPCS and Psalm
This commit is contained in:
parent
7abb1db30b
commit
a4fec5d53b
9 changed files with 83 additions and 9 deletions
1
.automation/test/local-storage.json
Normal file
1
.automation/test/local-storage.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"anonymousUserId":"8f97180e-e0e9-4d33-a52d-f45c9fec4000"}
|
15
.automation/test/php/php_bad_2.php
Executable file
15
.automation/test/php/php_bad_2.php
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string>
|
||||||
|
*/
|
||||||
|
function takesAnInt(int $i) {
|
||||||
|
return [$i, "hello"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ["some text", 5];
|
||||||
|
takesAnInt($data[0]);
|
||||||
|
|
||||||
|
$condition = rand(0, 5);
|
||||||
|
iff ($condition) {
|
||||||
|
} elseif ($condition) {}
|
25
.automation/test/php/php_good_2.php
Executable file
25
.automation/test/php/php_good_2.php
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string>
|
||||||
|
*/
|
||||||
|
function helloName(string $name): array
|
||||||
|
{
|
||||||
|
return ["hello", $name];
|
||||||
|
}
|
||||||
|
|
||||||
|
function helloSuperLinter(): void
|
||||||
|
{
|
||||||
|
$hello = helloName("Super-Linter");
|
||||||
|
echo implode(" ", $hello) . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function helloOrWorld(): void
|
||||||
|
{
|
||||||
|
$random = rand(0, 10);
|
||||||
|
if ($random >= 5) {
|
||||||
|
echo "Hello";
|
||||||
|
} else {
|
||||||
|
echo "World";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
TAP version 13
|
|
||||||
1..2
|
|
||||||
not ok 1 - php_bad_1.php
|
|
||||||
---
|
|
||||||
message: PHP Parse error syntax error, unexpected 'pe98y' (T_STRING) in /tmp/lint/.automation/test/php/php_bad_1.php on line 3\nErrors parsing /tmp/lint/.automation/test/php/php_bad_1.php\n
|
|
||||||
...
|
|
||||||
ok 2 - php_good_1.php
|
|
12
.automation/test/php/reports/expected-PHP_BUILTIN.tap
Executable file
12
.automation/test/php/reports/expected-PHP_BUILTIN.tap
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
TAP version 13
|
||||||
|
1..4
|
||||||
|
not ok 1 - php_bad_1.php
|
||||||
|
---
|
||||||
|
message: PHP Parse error syntax error, unexpected 'pe98y' (T_STRING) in /tmp/lint/.automation/test/php/php_bad_1.php on line 3\nErrors parsing /tmp/lint/.automation/test/php/php_bad_1.php\n
|
||||||
|
...
|
||||||
|
not ok 2 - php_bad_2.php
|
||||||
|
---
|
||||||
|
message: PHP Parse error syntax error, unexpected '}' in /tmp/lint/.automation/test/php/php_bad_2.php on line 15\nErrors parsing /tmp/lint/.automation/test/php/php_bad_2.php\n
|
||||||
|
...
|
||||||
|
ok 3 - php_good_1.php
|
||||||
|
ok 4 - php_good_2.php
|
12
.automation/test/php/reports/expected-PHP_PHPCS.tap
Executable file
12
.automation/test/php/reports/expected-PHP_PHPCS.tap
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
TAP version 13
|
||||||
|
1..4
|
||||||
|
not ok 1 - php_bad_1.php
|
||||||
|
---
|
||||||
|
message: \nFILE /tmp/lint/.automation/test/php/php_bad_1.php\n----------------------------------------------------------------------\nFOUND 7 ERRORS AFFECTING 1 LINE\n----------------------------------------------------------------------\n 3 | ERROR | [x] Expected at least 1 space before "-"; 0 found\n 3 | ERROR | [x] Expected at least 1 space after "-"; 0 found\n 3 | ERROR | [x] Expected at least 1 space before "="; 0 found\n 3 | ERROR | [x] Expected at least 1 space after "="; 0 found\n 3 | ERROR | [x] Expected at least 1 space before "-"; 0 found\n 3 | ERROR | [x] Expected at least 1 space before "-"; 0 found\n 3 | ERROR | [x] Expected at least 1 space after "-"; 0 found\n----------------------------------------------------------------------\nPHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY\n----------------------------------------------------------------------\n\n
|
||||||
|
...
|
||||||
|
not ok 2 - php_bad_2.php
|
||||||
|
---
|
||||||
|
message: \nFILE /tmp/lint/.automation/test/php/php_bad_2.php\n----------------------------------------------------------------------\nFOUND 4 ERRORS AND 1 WARNING AFFECTING 4 LINES\n----------------------------------------------------------------------\n 1 | WARNING | [ ] A file should declare new symbols (classes,\n | | functions, constants, etc.) and cause no other\n | | side effects, or it should execute logic with\n | | side effects, but should not do both. The first\n | | symbol is defined on line 6 and the first side\n | | effect is on line 10.\n 6 | ERROR | [x] Opening brace should be on a new line\n 14 | ERROR | [x] Space before opening parenthesis of function call\n | | prohibited\n 15 | ERROR | [x] Newline required after opening brace\n 15 | ERROR | [x] Closing brace must be on a line by itself\n----------------------------------------------------------------------\nPHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY\n----------------------------------------------------------------------\n\n
|
||||||
|
...
|
||||||
|
ok 3 - php_good_1.php
|
||||||
|
ok 4 - php_good_2.php
|
12
.automation/test/php/reports/expected-PHP_PSALM.tap
Executable file
12
.automation/test/php/reports/expected-PHP_PSALM.tap
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
TAP version 13
|
||||||
|
1..4
|
||||||
|
not ok 1 - php_bad_1.php
|
||||||
|
---
|
||||||
|
message: Scanning files...\nAnalyzing files...\n\nE\n\nERROR ParseError - php/php_bad_1.php 3 2 - Syntax error, unexpected T_STRING on line 3 (see https //psalm.dev/173)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 2 - Const pe98y is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 8 - Const r is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 10 - Const n0u823n is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR ParseError - php/php_bad_1.php 3 17 - Syntax error, unexpected '=' on line 3 (see https //psalm.dev/173)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 18 - Const r is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR ParseError - php/php_bad_1.php 3 21 - Invalid numeric literal on line 3 (see https //psalm.dev/173)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 24 - Const u3 is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 28 - Const r08u2q098ry is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR ParseError - php/php_bad_1.php 3 40 - Syntax error, unexpected T_LNUMBER on line 3 (see https //psalm.dev/173)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 42 - Const nq2yr09n2yr9 is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 55 - Const y2n is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR ParseError - php/php_bad_1.php 3 61 - Syntax error, unexpected T_STRING on line 3 (see https //psalm.dev/173)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 61 - Const yr is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\nERROR UndefinedConstant - php/php_bad_1.php 3 68 - Const yr3 is not defined (see https //psalm.dev/020)\n2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29\n\n\n------------------------------\n15 errors found\n------------------------------\n\n
|
||||||
|
...
|
||||||
|
not ok 2 - php_bad_2.php
|
||||||
|
---
|
||||||
|
message: Scanning files...\nAnalyzing files...\n\nE\n\nERROR InvalidReturnType - php/php_bad_2.php 4 12 - The declared return type 'array<array-key, string>' for takesAnInt is incorrect, got 'array{int, string(hello)}' (see https //psalm.dev/011)\n * @return array<string>\n\n\nERROR InvalidReturnStatement - php/php_bad_2.php 7 12 - The inferred type 'array{int, string(hello)}' does not match the declared return type 'array<array-key, string>' for takesAnInt (see https //psalm.dev/128)\n return [$i, "hello"];\n\n\nERROR InvalidScalarArgument - php/php_bad_2.php 11 12 - Argument 1 of takesAnInt expects int, string(some text) provided (see https //psalm.dev/012)\ntakesAnInt($data[0]);\n\n\nERROR ParseError - php/php_bad_2.php 15 1 - Syntax error, unexpected '}' on line 15 (see https //psalm.dev/173)\n} elseif ($condition) {}\n\n\n------------------------------\n4 errors found\n------------------------------\nPsalm can automatically fix 1 of these issues.\nRun Psalm again with \n[30;48;5;195m--alter --issues=InvalidReturnType --dry-run\nto see what it can fix.\n------------------------------\n\n
|
||||||
|
...
|
||||||
|
ok 3 - php_good_1.php
|
||||||
|
ok 4 - php_good_2.php
|
|
@ -239,7 +239,9 @@ function BuildFileList() {
|
||||||
################################
|
################################
|
||||||
# Append the file to the array #
|
# Append the file to the array #
|
||||||
################################
|
################################
|
||||||
FILE_ARRAY_PHP+=("${FILE}")
|
FILE_ARRAY_PHP_BUILTIN+=("${FILE}")
|
||||||
|
FILE_ARRAY_PHP_PHPCS+=("${FILE}")
|
||||||
|
FILE_ARRAY_PHP_PSALM+=("${FILE}")
|
||||||
##########################################################
|
##########################################################
|
||||||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||||
##########################################################
|
##########################################################
|
||||||
|
|
|
@ -597,7 +597,9 @@ function RunTestCases() {
|
||||||
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin"
|
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin"
|
||||||
TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown"
|
TestCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "markdown"
|
||||||
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl"
|
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "perl"
|
||||||
TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "php"
|
TestCodebase "PHP_BUILTIN" "php" "php -l" ".*\.\(php\)\$" "php"
|
||||||
|
TestCodebase "PHP_PHPCS" "phpcs" "phpcs --standard=${PHP_PHPCS_LINTER_RULES}" ".*\.\(php\)\$" "php"
|
||||||
|
TestCodebase "PHP_PSALM" "psalm" "psalm --config=${PHP_PSALM_LINTER_RULES}" ".*\.\(php\)\$" "php"
|
||||||
TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi"
|
TestCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi"
|
||||||
TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell"
|
TestCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "powershell"
|
||||||
TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf"
|
TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "protobuf"
|
||||||
|
|
Loading…
Reference in a new issue