Basic support for PHPCS and Psalm

This commit is contained in:
Filip Š 2020-07-26 21:01:29 +02:00
parent c9eae4876c
commit 49243625fe
3 changed files with 64 additions and 11 deletions

View file

@ -65,8 +65,18 @@ RUN apk add --update --no-cache \
openjdk8-jre \
perl \
php7 \
php7-phar \
php7-json \
php7-simplexml \
php7-xmlwriter \
php7-mbstring \
php7-tokenizer \
php7-ctype \
php7-curl \
php7-dom \
py3-setuptools \
ruby ruby-dev ruby-bundler ruby-rdoc
ruby ruby-dev ruby-bundler ruby-rdoc \
gnupg
########################################
# Copy dependencies files to container #
@ -96,6 +106,19 @@ ENV PATH="/node_modules/.bin:${PATH}"
##############################
RUN bundle install
##############################
# Install Phive dependencies #
##############################
RUN wget -O phive.phar https://phar.io/releases/phive.phar \
&& wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc \
&& gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79 \
&& gpg --verify phive.phar.asc phive.phar \
&& chmod +x phive.phar \
&& mv phive.phar /usr/local/bin/phive \
&& rm phive.phar.asc \
&& phive install --trust-gpg-keys 31C7E470E2138192,8A03EA3B385DBAA1
# Trusted GPG keys for PHP linters: phpcs, psalm
#########################################
# Install Powershell + PSScriptAnalyzer #
#########################################

6
dependencies/phive.xml vendored Executable file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<!-- When adding new linter, do not forget to add its GPG key ID to Dockerfile -->
<phar name="phpcs" version="^3.5" installed="3.5.5" location="/usr/local/bin/phpcs" copy="true"/>
<phar name="psalm" version="^3.12" installed="3.12.2" location="/usr/local/bin/psalm" copy="true"/>
</phive>

View file

@ -107,7 +107,7 @@ LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'clj-kondo'
LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT'
'CSS' 'DART' 'DOCKER' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVASCRIPT_ES'
'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'MARKDOWN' 'OPENAPI'
'PERL' 'PHP' 'POWERSHELL' 'PROTOBUF' 'PYTHON'
'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON'
'RAKU' 'RUBY' 'STATES' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES'
'TYPESCRIPT_STANDARD' 'XML' 'YML')
@ -154,7 +154,9 @@ VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to vali
VALIDATE_MARKDOWN="${VALIDATE_MD:-}" # Boolean to validate language
VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language
VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language
VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language
VALIDATE_PHP_BUILTIN="${VALIDATE_PHP_BUILTIN}" # Boolean to validate language
VALIDATE_PHP_PHPCS="${VALIDATE_PHP_PHPCS}" # Boolean to validate language
VALIDATE_PHP_PSALM="${VALIDATE_PHP_PSALM}" # Boolean to validate language
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language
VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language
VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language
@ -230,7 +232,9 @@ FILE_ARRAY_KOTLIN=() # Array of files to check
FILE_ARRAY_MARKDOWN=() # Array of files to check
FILE_ARRAY_OPENAPI=() # Array of files to check
FILE_ARRAY_PERL=() # Array of files to check
FILE_ARRAY_PHP=() # Array of files to check
FILE_ARRAY_PHP_BUILTIN=() # Array of files to check
FILE_ARRAY_PHP_PHPCS=() # Array of files to check
FILE_ARRAY_PHP_PSALM=() # Array of files to check
FILE_ARRAY_POWERSHELL=() # Array of files to check
FILE_ARRAY_PROTOBUF=() # Array of files to check
FILE_ARRAY_PYTHON=() # Array of files to check
@ -289,8 +293,12 @@ ERRORS_FOUND_OPENAPI=0 # Count of errors found
export ERRORS_FOUND_OPENAPI # Workaround SC2034
ERRORS_FOUND_PERL=0 # Count of errors found
export ERRORS_FOUND_PERL # Workaround SC2034
ERRORS_FOUND_PHP=0 # Count of errors found
export ERRORS_FOUND_PHP # Workaround SC2034
ERRORS_FOUND_PHP_BUILTIN=0 # Count of errors found
export ERRORS_FOUND_PHP_BUILTIN # Workaround SC2034
ERRORS_FOUND_PHP_PHPCS=0 # Count of errors found
export ERRORS_FOUND_PHP_PHPCS # Workaround SC2034
ERRORS_FOUND_PHP_PSALM=0 # Count of errors found
export ERRORS_FOUND_PHP_PSALM # Workaround SC2034
ERRORS_FOUND_POWERSHELL=0 # Count of errors found
export ERRORS_FOUND_POWERSHELL # Workaround SC2034
ERRORS_FOUND_PROTOBUF=0 # Count of errors found
@ -1453,12 +1461,28 @@ fi
################
# PHP LINTING #
################
if [ "${VALIDATE_PHP}" == "true" ]; then
#######################
# Lint the PHP files #
#######################
if [ "${VALIDATE_PHP_BUILTIN}" == "true" ]; then
################################################
# Lint the PHP files using built-in PHP linter #
################################################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}"
LintCodebase "PHP_BUILTIN" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_BUILTIN[@]}"
fi
if [ "${VALIDATE_PHP_PHPCS}" == "true" ]; then
############################################
# Lint the PHP files using PHP CodeSniffer #
############################################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PHP_PHPCS" "phpcs" "phpcs" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PHPCS[@]}"
fi
if [ "${VALIDATE_PHP_PSALM}" == "true" ]; then
##################################
# Lint the PHP files using Psalm #
##################################
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
LintCodebase "PHP_PSALM" "psalm" "psalm" ".*\.\(php\)\$" "${FILE_ARRAY_PHP_PSALM[@]}"
fi
######################