mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-25 10:10:56 -05:00
Add PHP linting foundation
This commit is contained in:
parent
1e08ff6363
commit
f7ca82806f
7 changed files with 96 additions and 2 deletions
13
.automation/test/php/README.md
Normal file
13
.automation/test/php/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# PHP Test Cases
|
||||||
|
This folder holds the test cases for **PHP**.
|
||||||
|
|
||||||
|
## Additional Docs
|
||||||
|
No Additional information is needed for this test case.
|
||||||
|
|
||||||
|
## Good Test Cases
|
||||||
|
The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted.
|
||||||
|
- **Note:** They are linted utilizing the default linter rules.
|
||||||
|
|
||||||
|
## Bad Test Cases
|
||||||
|
The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted.
|
||||||
|
- **Note:** They are linted utilizing the default linter rules.
|
5
.automation/test/php/php_bad_1.php
Normal file
5
.automation/test/php/php_bad_1.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
2pe98y r-n0u823n=r 092u3- r08u2q098ry 09nq2yr09n2yr9 y2n-93yr 298yr3 29
|
||||||
|
|
||||||
|
exit(1);
|
5
.automation/test/php/php_good_1.php
Normal file
5
.automation/test/php/php_good_1.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo "Hello World!", PHP_EOL;
|
||||||
|
|
||||||
|
exit (0);
|
|
@ -27,7 +27,8 @@ RUN apk add --no-cache \
|
||||||
libxml2-utils perl \
|
libxml2-utils perl \
|
||||||
ruby ruby-dev ruby-bundler ruby-rdoc make \
|
ruby ruby-dev ruby-bundler ruby-rdoc make \
|
||||||
py3-setuptools ansible-lint \
|
py3-setuptools ansible-lint \
|
||||||
go
|
go \
|
||||||
|
php7
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Run Pip3 Installs #
|
# Run Pip3 Installs #
|
||||||
|
@ -111,6 +112,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
||||||
VALIDATE_MD=${VALIDATE_MD} \
|
VALIDATE_MD=${VALIDATE_MD} \
|
||||||
VALIDATE_BASH=${VALIDATE_BASH} \
|
VALIDATE_BASH=${VALIDATE_BASH} \
|
||||||
VALIDATE_PERL=${VALIDATE_PERL} \
|
VALIDATE_PERL=${VALIDATE_PERL} \
|
||||||
|
VALIDATE_PHP=${VALIDATE_PHP} \
|
||||||
VALIDATE_PYTHON=${VALIDATE_PYTHON} \
|
VALIDATE_PYTHON=${VALIDATE_PYTHON} \
|
||||||
VALIDATE_RUBY=${VALIDATE_RUBY} \
|
VALIDATE_RUBY=${VALIDATE_RUBY} \
|
||||||
VALIDATE_COFFEE=${VALIDATE_COFFEE} \
|
VALIDATE_COFFEE=${VALIDATE_COFFEE} \
|
||||||
|
|
|
@ -26,6 +26,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
||||||
| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) |
|
| **JSON** | [jsonlint](https://github.com/zaach/jsonlint) |
|
||||||
| **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) |
|
| **Markdown** | [markdownlint](https://github.com/igorshubovych/markdownlint-cli#readme) |
|
||||||
| **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) |
|
| **Perl** | [perl](https://pkgs.alpinelinux.org/package/edge/main/x86/perl) |
|
||||||
|
| **PHP** | [PHP](https://www.php.net/) |
|
||||||
| **Python3** | [pylint](https://www.pylint.org/) |
|
| **Python3** | [pylint](https://www.pylint.org/) |
|
||||||
| **Ruby** | [Rubocop](https://github.com/rubocop-hq/rubocop) |
|
| **Ruby** | [Rubocop](https://github.com/rubocop-hq/rubocop) |
|
||||||
| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) |
|
| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) |
|
||||||
|
@ -119,6 +120,7 @@ and won't run anything unexpected.
|
||||||
| **VALIDATE_MD** | `true` | Flag to enable or disable the linting process of the language. |
|
| **VALIDATE_MD** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
| **VALIDATE_BASH** | `true` | Flag to enable or disable the linting process of the language. |
|
| **VALIDATE_BASH** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
| **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the language. |
|
| **VALIDATE_PERL** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
|
| **VALIDATE_PHP** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the language. |
|
| **VALIDATE_PYTHON** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
| **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the language. |
|
| **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the language. |
|
||||||
| **VALIDATE_COFFEE** | `true` | Flag to enable or disable the linting process of the language . |
|
| **VALIDATE_COFFEE** | `true` | Flag to enable or disable the linting process of the language . |
|
||||||
|
|
|
@ -11,6 +11,7 @@ Below is examples and documentation for each language and the various methods to
|
||||||
- [JSON](#json)
|
- [JSON](#json)
|
||||||
- [Markdown](#markdown)
|
- [Markdown](#markdown)
|
||||||
- [Perl](#perl)
|
- [Perl](#perl)
|
||||||
|
- [PHP](#php)
|
||||||
- [XML](#xml)
|
- [XML](#xml)
|
||||||
- [Coffeescript](#coffeescript)
|
- [Coffeescript](#coffeescript)
|
||||||
- [Javascript Eslint](#javascript-eslint)
|
- [Javascript Eslint](#javascript-eslint)
|
||||||
|
@ -301,6 +302,23 @@ Here is more data
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
## PHP
|
||||||
|
- [PHP](https://www.php.net/)
|
||||||
|
|
||||||
|
### PHP Config file
|
||||||
|
- There is no top level *configuration file* available at this time
|
||||||
|
|
||||||
|
### PHP disable single line
|
||||||
|
- There is currently **No** way to disable rules inline of the file(s)
|
||||||
|
|
||||||
|
### PHP disable code block
|
||||||
|
- There is currently **No** way to disable rules inline of the file(s)
|
||||||
|
|
||||||
|
### PHP disable entire file
|
||||||
|
- There is currently **No** way to disable rules inline of the file(s)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
## XML
|
## XML
|
||||||
- [XML](http://xmlsoft.org/)
|
- [XML](http://xmlsoft.org/)
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
||||||
#############################
|
#############################
|
||||||
# Language array for prints #
|
# Language array for prints #
|
||||||
#############################
|
#############################
|
||||||
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON'
|
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON'
|
||||||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
||||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM')
|
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM')
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate lang
|
||||||
VALIDATE_MD="${VALIDATE_MD}" # Boolean to validate language
|
VALIDATE_MD="${VALIDATE_MD}" # Boolean to validate language
|
||||||
VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language
|
VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language
|
||||||
VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language
|
VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language
|
||||||
|
VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language
|
||||||
VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language
|
VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language
|
||||||
VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language
|
VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language
|
||||||
VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language
|
VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language
|
||||||
|
@ -118,6 +119,7 @@ FILE_ARRAY_XML=() # Array of files to check
|
||||||
FILE_ARRAY_MD=() # Array of files to check
|
FILE_ARRAY_MD=() # Array of files to check
|
||||||
FILE_ARRAY_BASH=() # Array of files to check
|
FILE_ARRAY_BASH=() # Array of files to check
|
||||||
FILE_ARRAY_PERL=() # Array of files to check
|
FILE_ARRAY_PERL=() # Array of files to check
|
||||||
|
FILE_ARRAY_PHP=() # Array of files to check
|
||||||
FILE_ARRAY_RUBY=() # Array of files to check
|
FILE_ARRAY_RUBY=() # Array of files to check
|
||||||
FILE_ARRAY_PYTHON=() # Array of files to check
|
FILE_ARRAY_PYTHON=() # Array of files to check
|
||||||
FILE_ARRAY_COFFEESCRIPT=() # Array of files to check
|
FILE_ARRAY_COFFEESCRIPT=() # Array of files to check
|
||||||
|
@ -138,6 +140,7 @@ ERRORS_FOUND_XML=0 # Count of errors found
|
||||||
ERRORS_FOUND_MARKDOWN=0 # Count of errors found
|
ERRORS_FOUND_MARKDOWN=0 # Count of errors found
|
||||||
ERRORS_FOUND_BASH=0 # Count of errors found
|
ERRORS_FOUND_BASH=0 # Count of errors found
|
||||||
ERRORS_FOUND_PERL=0 # Count of errors found
|
ERRORS_FOUND_PERL=0 # Count of errors found
|
||||||
|
ERRORS_FOUND_PHP=0 # Count of errors found
|
||||||
ERRORS_FOUND_RUBY=0 # Count of errors found
|
ERRORS_FOUND_RUBY=0 # Count of errors found
|
||||||
ERRORS_FOUND_PYTHON=0 # Count of errors found
|
ERRORS_FOUND_PYTHON=0 # Count of errors found
|
||||||
ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found
|
ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found
|
||||||
|
@ -714,6 +717,7 @@ GetValidationInfo()
|
||||||
VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}')
|
VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}')
|
||||||
VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}')
|
VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}')
|
||||||
VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}')
|
VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}')
|
||||||
|
VALIDATE_PHP=$(echo "$VALIDATE_PHP" | awk '{print tolower($0)}')
|
||||||
VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}')
|
VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}')
|
||||||
VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}')
|
VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}')
|
||||||
VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}')
|
VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}')
|
||||||
|
@ -736,6 +740,7 @@ GetValidationInfo()
|
||||||
-n "$VALIDATE_MD" || \
|
-n "$VALIDATE_MD" || \
|
||||||
-n "$VALIDATE_BASH" || \
|
-n "$VALIDATE_BASH" || \
|
||||||
-n "$VALIDATE_PERL" || \
|
-n "$VALIDATE_PERL" || \
|
||||||
|
-n "$VALIDATE_PHP" || \
|
||||||
-n "$VALIDATE_PYTHON" || \
|
-n "$VALIDATE_PYTHON" || \
|
||||||
-n "$VALIDATE_RUBY" || \
|
-n "$VALIDATE_RUBY" || \
|
||||||
-n "$VALIDATE_COFFEE" || \
|
-n "$VALIDATE_COFFEE" || \
|
||||||
|
@ -834,6 +839,20 @@ GetValidationInfo()
|
||||||
VALIDATE_PERL="true"
|
VALIDATE_PERL="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# Validate if we should check PHP #
|
||||||
|
####################################
|
||||||
|
if [[ "$ANY_SET" == "true" ]]; then
|
||||||
|
# Some linter flags were set - only run those set to true
|
||||||
|
if [[ -z "$VALIDATE_PHP" ]]; then
|
||||||
|
# PHP flag was not set - default to false
|
||||||
|
VALIDATE_PHP="false"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No linter flags were set - default all to true
|
||||||
|
VALIDATE_PHP="true"
|
||||||
|
fi
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
# Validate if we should check PYTHON #
|
# Validate if we should check PYTHON #
|
||||||
######################################
|
######################################
|
||||||
|
@ -1021,6 +1040,11 @@ GetValidationInfo()
|
||||||
else
|
else
|
||||||
PRINT_ARRAY+=("- Excluding [PERL] files in code base...")
|
PRINT_ARRAY+=("- Excluding [PERL] files in code base...")
|
||||||
fi
|
fi
|
||||||
|
if [[ "$VALIDATE_PHP" == "true" ]]; then
|
||||||
|
PRINT_ARRAY+=("- Validating [PHP] files in code base...")
|
||||||
|
else
|
||||||
|
PRINT_ARRAY+=("- Excluding [PHP] files in code base...")
|
||||||
|
fi
|
||||||
if [[ "$VALIDATE_PYTHON" == "true" ]]; then
|
if [[ "$VALIDATE_PYTHON" == "true" ]]; then
|
||||||
PRINT_ARRAY+=("- Validating [PYTHON] files in code base...")
|
PRINT_ARRAY+=("- Validating [PYTHON] files in code base...")
|
||||||
else
|
else
|
||||||
|
@ -1298,6 +1322,18 @@ BuildFileList()
|
||||||
##########################################################
|
##########################################################
|
||||||
READ_ONLY_CHANGE_FLAG=1
|
READ_ONLY_CHANGE_FLAG=1
|
||||||
######################
|
######################
|
||||||
|
# Get the PHP files #
|
||||||
|
######################
|
||||||
|
elif [ "$FILE_TYPE" == "php" ]; then
|
||||||
|
################################
|
||||||
|
# Append the file to the array #
|
||||||
|
################################
|
||||||
|
FILE_ARRAY_PHP+=("$FILE")
|
||||||
|
##########################################################
|
||||||
|
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||||
|
##########################################################
|
||||||
|
READ_ONLY_CHANGE_FLAG=1
|
||||||
|
######################
|
||||||
# Get the RUBY files #
|
# Get the RUBY files #
|
||||||
######################
|
######################
|
||||||
elif [ "$FILE_TYPE" == "rb" ]; then
|
elif [ "$FILE_TYPE" == "rb" ]; then
|
||||||
|
@ -1878,6 +1914,7 @@ Footer()
|
||||||
[ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \
|
[ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_BASH" -ne 0 ] || \
|
[ "$ERRORS_FOUND_BASH" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_PERL" -ne 0 ] || \
|
[ "$ERRORS_FOUND_PERL" -ne 0 ] || \
|
||||||
|
[ "$ERRORS_FOUND_PHP" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \
|
[ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \
|
[ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \
|
||||||
[ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \
|
[ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \
|
||||||
|
@ -1935,6 +1972,7 @@ RunTestCases()
|
||||||
TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$"
|
TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$"
|
||||||
TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$"
|
TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$"
|
||||||
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$"
|
TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$"
|
||||||
|
TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$"
|
||||||
TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$"
|
TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$"
|
||||||
TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$"
|
TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$"
|
||||||
TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$"
|
TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$"
|
||||||
|
@ -2108,6 +2146,17 @@ if [ "$VALIDATE_PERL" == "true" ]; then
|
||||||
LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}"
|
LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
################
|
||||||
|
# PHP LINTING #
|
||||||
|
################
|
||||||
|
if [ "$VALIDATE_PHP" == "true" ]; then
|
||||||
|
#######################
|
||||||
|
# Lint the PHP files #
|
||||||
|
#######################
|
||||||
|
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||||
|
LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
################
|
################
|
||||||
# RUBY LINTING #
|
# RUBY LINTING #
|
||||||
################
|
################
|
||||||
|
|
Loading…
Reference in a new issue