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

feat: [OP-237] Update Eckinox CS #3

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ root = true
[*]
charset = utf-8
end_of_line = LF
indent_size = 2
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml,php,html,twig,js,mjs,cjs,ts,css,json}]
indent_size = 4

[*.{yml,yaml}]
[*.{yml,yaml,php,twig,js}]
indent_style = space
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"env": {
"browser": true,
"es2021": true
"es2022": true
},
"globals": {
},
"extends": [
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": [
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
Expand All @@ -21,8 +27,9 @@ jobs:
- name: Install PHP dependencies (composer install)
uses: php-actions/composer@v6
with:
php_version: 8.0
php_version: "8.1"
php_extensions: xsl intl
memory_limit: -1
- name: Remove auth.json file
run: rm -f $GITHUB_WORKSPACE/auth.json
- name: Restore configs overwritten by the eckinox/eckinox-cs install
Expand All @@ -39,5 +46,3 @@ jobs:
run: DEV/cs/phpstan.sh
- name: PHP MD
run: DEV/cs/phpmd.sh
- name: CSS stylelint
run: DEV/cs/stylelint.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/vendor/
node_modules
.php-cs-fixer.cache
.DS_Store
composer.lock
18 changes: 17 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@
->exclude('var')
->exclude('vendor')
->exclude('node_modules')
->notName('Configuration.php')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PhpCsFixer' => true,
'@Symfony' => true,
'@PER-CS' => true,
'@DoctrineAnnotation' => true,
'php_unit_test_class_requires_covers' => false,
'php_unit_internal_class' => false,
'heredoc_to_nowdoc' => false,
'string_implicit_backslashes' => false,
'explicit_indirect_variable' => false,
'explicit_string_variable' => false,
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'doctrine_annotation_array_assignment' => false,
'yoda_style' => ['equal' => false, 'identical' => false],
'increment_style' => ['style' => 'post'],
'concat_space' => false,
'single_quote' => false,
'method_argument_space' => ['on_multiline' => 'ignore'],
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
])
->setIndent("\t")
->setFinder($finder);
114 changes: 51 additions & 63 deletions .phpmd.xml
Original file line number Diff line number Diff line change
@@ -1,72 +1,60 @@
<?xml version="1.0"?>
<ruleset name="Eckinox PHPMD"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Eckinox PHPMD"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Eckinox's PHPMD Ruleset
</description>
<description>
Eckinox's PHPMD Ruleset
</description>

<!-- Import entire rulesets -->
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/unusedcode.xml" />
<!-- Import entire rulesets -->
<rule ref="rulesets/controversial.xml"/>

<!-- Import codesize ruleset with common configs for Symfony entities -->
<rule ref="rulesets/codesize.xml">
<exclude name="TooManyMethods" />
<exclude name="TooManyPublicMethods" />
</rule>
<rule ref="rulesets/codesize.xml/TooManyMethods">
<properties>
<property name="ignorepattern" value="(^(set|get|add|remove))i" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="ignorepattern" value="(^(set|get|add|remove))i" />
</properties>
</rule>
<rule ref="rulesets/unusedcode.xml">
<exclude name="UnusedFormalParameter"/>
</rule>

<!-- Import cleancode ruleset with a few allowances -->
<rule ref="rulesets/cleancode.xml">
<exclude name="IfStatementAssignment" />
<exclude name="BooleanArgumentFlag" />
<exclude name="ElseExpression" />
<exclude name="StaticAccess" />
</rule>
<!-- Import codesize ruleset with common configs for Symfony entities -->
<rule ref="rulesets/codesize.xml">
<exclude name="CyclomaticComplexity"/>
<exclude name="NPathComplexity"/>
<exclude name="ExcessiveParameterList"/>
<exclude name="ExcessivePublicCount"/>
<exclude name="TooManyFields"/>
<exclude name="TooManyMethods"/>
<exclude name="TooManyPublicMethods"/>
<exclude name="ExcessiveClassComplexity"/>
<exclude name="ExcessiveMethodLength"/>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="200"/>
</properties>
</rule>

<!-- Import design ruleset with higher CouplingBetweenObjects limit -->
<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects" />
</rule>
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<property name="maximum" value="20" />
</properties>
</rule>
<!-- Import cleancode ruleset with a few allowances -->
<rule ref="rulesets/cleancode.xml">
<exclude name="IfStatementAssignment"/>
<exclude name="BooleanArgumentFlag"/>
<exclude name="ElseExpression"/>
<exclude name="StaticAccess"/>
<exclude name="MissingImport"/>
</rule>

<!-- Import naming ruleset with common configs for Symfony -->
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
<exclude name="ShortMethodName"/>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="id,i,em" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="30" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="exceptions" value="up,down" />
</properties>
</rule>
<!-- Import design ruleset with higher CouplingBetweenObjects limit -->
<rule ref="rulesets/design.xml">
<exclude name="NumberOfChildren"/>
<exclude name="CouplingBetweenObjects"/>
</rule>

<!-- Import naming ruleset with common configs for Symfony -->
<rule ref="rulesets/naming.xml">
<exclude name="LongClassName"/>
<exclude name="ShortVariable"/>
<exclude name="LongVariable"/>
<exclude name="ShortMethodName"/>
</rule>
</ruleset>
3 changes: 2 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"number-leading-zero": "never",
"no-descending-specificity": null,
"rule-empty-line-before": null,
"font-family-no-missing-generic-family-keyword": null
"font-family-no-missing-generic-family-keyword": null,
"max-line-length": 350
}
}

11 changes: 11 additions & 0 deletions .twig-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer());
$ruleset->removeRule(TwigCsFixer\Rules\Whitespace\BlankEOFRule::class);

$config = new TwigCsFixer\Config\Config();
$config->allowNonFixableRules();
$config->setRuleset($ruleset);

return $config;
1 change: 1 addition & 0 deletions DEV/cs/eslint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint:js
14 changes: 13 additions & 1 deletion DEV/cs/phpstan.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
addedFiles=$(git diff --diff-filter=d --cached --name-only ":!tests")
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../.."

# If this is not a Symfony project, auto-remove the Symfony-specific configuration
if [ ! -d "${BASEDIR}/var/cache" ] && grep -q "var/cache/" "${BASEDIR}/phpstan.neon"; then
sed -i -e 's/var\/cache\/dev\/App_KernelDevDebugContainer.xml//g' "${BASEDIR}/phpstan.neon"
fi

# Ignore test directory if it exists
if [ -d "${BASEDIR}/tests" ]; then
addedFiles=$(git diff --diff-filter=d --cached --name-only ":!tests")
else
addedFiles=$(git diff --diff-filter=d --cached --name-only "${BASEDIR}")
fi

if [ -z "$addedFiles" ];
then
Expand Down
10 changes: 10 additions & 0 deletions DEV/cs/twigcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../.."

if [ -d "${BASEDIR}/templates" ]; then
# Lint templates before validating them if possible
if [ -f "${BASEDIR}/bin/console" ]; then
bin/console lint:twig templates
fi

vendor/bin/twig-cs-fixer lint templates
fi
4 changes: 2 additions & 2 deletions DEV/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../.."

# Define CI scripts to run
CI_SCRIPTS=("php-cs-fixer.sh" "phpstan.sh" "phpmd.sh" "stylelint.sh")
CI_SCRIPT_NAMES=("PHP-CS-Fixer" "PHPStan" "PHPMD" "CSS stylelint")
CI_SCRIPTS=("php-cs-fixer.sh" "phpstan.sh" "phpmd.sh" "twigcs.sh" "eslint.sh" "stylelint.sh")
CI_SCRIPT_NAMES=("PHP-CS-Fixer" "PHPStan" "PHPMD" "Twigcs" "ESLint" "CSS stylelint")
scriptCount=${#CI_SCRIPTS[@]}
addedFiles=$(git diff --diff-filter=d --cached --name-only)

Expand Down
81 changes: 81 additions & 0 deletions DEV/hooks/pre-commit-with-bypass
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
#
# Pre Commit with option to continue when test failed
#
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty


BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../.."

# Define CI scripts to run
CI_SCRIPTS=("php-cs-fixer.sh" "phpstan.sh" "phpmd.sh" "twigcs.sh" "eslint.sh" "stylelint.sh")
CI_SCRIPT_NAMES=("PHP-CS-Fixer" "PHPStan" "PHPMD" "Twigcs" "ESLint" "CSS stylelint")
scriptCount=${#CI_SCRIPTS[@]}
addedFiles=$(git diff --diff-filter=d --cached --name-only)

# Utility functions
verbose()
{
msg=${1}
type=${2:-""}
addTrailingNewline=${3:-0}

if [ "${type}" = "error" ]; then
msg="\033[1m\e[41m${msg}\e[0m"
elif [ "${type}" = "success" ]; then
msg="\033[1m\e[42m${msg}\e[0m"
elif [ "${type}" = "info" ]; then
msg="\e[44m${msg}\e[0m"
fi

endNewline=""
if [ ${addTrailingNewline} -eq 1 ]; then
endNewline="\n"
fi

if [ "${type}" = "error" ]; then
>&2 printf "${msg}${endNewline}"
else
printf "${msg}${endNewline}"
fi
}

# Run PHP-CS-Fixer with automatic fixes
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -q

# If there were any added files, re-add them after the automatic fixes
if [ -n "$addedFiles" ]
then
git add $addedFiles
fi

# Loop through scripts and execute them
# If no error is thrown, mute all outputs.
# Otherwise, stop execution and output the error(s).
for ((i=0; i < ${scriptCount}; i++)); do
filename=${CI_SCRIPTS[$i]}
label=${CI_SCRIPT_NAMES[$i]}

verbose "Running ${label}..." "info"
output=$(${BASEDIR}/DEV/cs/${filename} 2>&1)

if [ $? -ne 0 ]; then
printf " ❌\n"
verbose "Failed CI test ${label} (DEV/cs/${filename}). View output below." "error" 1
printf "%s\n\n" "${output}"
verbose "Do you want to continue [Y/n]" "info" 1
read yn
echo $yn | grep ^[Yy]$
if [ $? -eq 1 ]; then
exit 1
fi
else
echo " ✅"
fi
done

# All systems go: tests ran without errors!
verbose "Tests passed with flying colors: all systems go!\e[0m 🚀" "success" 1
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
"description": "A Symfony bundle to generate PDFs from Twig templates.",
"type": "symfony-bundle",
"require": {
"php": "^8.0",
"twig/twig": "*",
"php": ">=8.1.10",
"eckinox/php-puppeteer": "^1.0",
"symfony/http-foundation": "^4.0|^5.0|^6.0",
"symfony/http-kernel": "^4.0|^5.0|^6.0",
"symfony/string": "^5.4|^6.0.9",
"symfony/translation-contracts": "^2.0|^3.0"
"symfony/http-foundation": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/string": "^5.4|^6.0",
"twig/twig": "^3.8"
},
"require-dev": {
"eckinox/eckinox-cs": ">=1.2.1"
"eckinox/eckinox-cs": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading
Loading