Truly leverage PHP-CS-Fixer and Twig-CS-Fixer to Fabbot

This commit is contained in:
Hugo Alliaume
2025-12-25 10:21:21 +01:00
parent 6c998390ed
commit 823d5fd6dd
12 changed files with 24 additions and 196 deletions

View File

@@ -1,50 +0,0 @@
name: App Code Quality
on:
push:
paths:
- 'apps/**'
- '.github/workflows/app-code-quality.yaml'
pull_request:
paths:
- 'apps/**'
- '.github/workflows/app-code-quality.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
code-formatting:
name: "Code Formatting (${{ matrix.app }})"
runs-on: ubuntu-latest
strategy:
matrix:
app: ['e2e']
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Install root dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ${{ github.workspace }}
- name: Build root packages
run: php .github/build-packages.php
- name: Install composer packages
uses: ramsey/composer-install@v3
with:
working-directory: apps/${{ matrix.app }}
- name: Ensure PHP code style
run: php vendor/bin/php-cs-fixer fix --diff --dry-run
working-directory: apps/${{ matrix.app }}
- name: Ensure Twig files are nicely formatted
run: php vendor/bin/twig-cs-fixer lint
working-directory: apps/${{ matrix.app }}

View File

@@ -1,50 +0,0 @@
name: Toolkit Kits Linting
on:
push:
paths:
- 'src/Toolkit/**'
- '.github/workflows/toolkit-kits-lint.yaml'
pull_request:
paths:
- 'src/Toolkit/**'
- '.github/workflows/toolkit-kits-lint.yaml'
jobs:
get-matrix:
runs-on: ubuntu-latest
outputs:
kits: ${{ steps.set-kits.outputs.kits }}
steps:
- uses: actions/checkout@v4
- name: Set kits output
id: set-kits
run: |
KITS_JSON=$(find src/Toolkit/kits -mindepth 1 -maxdepth 1 -type d -printf '"%f",' | sed 's/,$//')
echo "kits=[${KITS_JSON}]" >> $GITHUB_OUTPUT
lint:
runs-on: ubuntu-latest
needs: get-matrix
strategy:
fail-fast: false
matrix:
kit: ${{ fromJson(needs.get-matrix.outputs.kits) }}
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- name: Install composer packages
uses: ramsey/composer-install@v3
with:
working-directory: src/Toolkit
- name: Ensure Twig files are nicely formatted
run: php vendor/bin/twig-cs-fixer lint kits/${{ matrix.kit }}
working-directory: src/Toolkit

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ node_modules
.doctor-rst.cache
.php-cs-fixer.cache
.phpunit.result.cache
.twig-cs-fixer.cache
/composer.lock
/vendor

View File

@@ -27,6 +27,15 @@ $fileHeaderParts = [
EOF,
];
$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/src', __DIR__.'/apps'])
->append([__FILE__])
->notPath('#/Fixtures/#')
->notPath('#/assets/#')
->notPath('#/var/#')
// does not work well with `fully_qualified_strict_types` rule
->notPath('LiveComponent/tests/Integration/LiveComponentHydratorTest.php');
return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
@@ -47,13 +56,5 @@ return (new PhpCsFixer\Config())
],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in([__DIR__.'/src'])
->append([__FILE__])
->notPath('#/Fixtures/#')
->notPath('#/var/#')
// does not work well with `fully_qualified_strict_types` rule
->notPath('LiveComponent/tests/Integration/LiveComponentHydratorTest.php')
)
->setFinder($finder)
;

View File

@@ -12,8 +12,15 @@
$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer());
$finder = new TwigCsFixer\File\Finder();
$finder->in([__DIR__.'/src', __DIR__.'/apps']);
$finder->notPath('#/Fixtures/#');
$finder->notPath('#/assets/#');
$finder->notPath('#/var/#');
$config = new TwigCsFixer\Config\Config();
$config->setCacheFile('.twig-cs-fixer.cache');
$config->setRuleset($ruleset);
$config->setFinder($finder);
return $config;

9
apps/e2e/.gitignore vendored
View File

@@ -14,12 +14,3 @@ composer.lock
/public/assets/
/assets/vendor/
###< symfony/asset-mapper ###
###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
###> vincentlanglet/twig-cs-fixer ###
/.twig-cs-fixer.cache
###< vincentlanglet/twig-cs-fixer ###

View File

@@ -1,49 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$fileHeaderParts = [
<<<'EOF'
This file is part of the Symfony package.
(c) Fabien Potencier <fabien@symfony.com>
EOF,
<<<'EOF'
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF,
];
return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'header_comment' => [
'header' => implode('', $fileHeaderParts),
'validator' => implode('', [
'/',
preg_quote($fileHeaderParts[0], '/'),
'(?P<EXTRA>.*)??',
preg_quote($fileHeaderParts[1], '/'),
'/s',
]),
],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in([__DIR__.'/src'])
->append([__FILE__])
->notPath('#/var/#')
)
;

View File

@@ -70,12 +70,10 @@
"twig/twig": "^3.21.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92",
"symfony/debug-bundle": "6.4.*|7.3.*",
"symfony/maker-bundle": "^1.64",
"symfony/stopwatch": "6.4.*|7.3.*",
"symfony/web-profiler-bundle": "6.4.*|7.3.*",
"vincentlanglet/twig-cs-fixer": "^3.11",
"zenstruck/foundry": "^2.8"
},
"config": {

View File

@@ -35,18 +35,6 @@
"migrations/.gitignore"
]
},
"friendsofphp/php-cs-fixer": {
"version": "3.92",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "be2103eb4a20942e28a6dd87736669b757132435"
},
"files": [
".php-cs-fixer.dist.php"
]
},
"symfony/asset-mapper": {
"version": "7.3",
"recipe": {
@@ -465,15 +453,6 @@
"twig/extra-bundle": {
"version": "v3.21.0"
},
"vincentlanglet/twig-cs-fixer": {
"version": "3.11",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "3.0",
"ref": "d42582ae1bce86fd43491d6264c738b0867f8ffe"
}
},
"zenstruck/foundry": {
"version": "2.8",
"recipe": {

View File

@@ -9,6 +9,7 @@
"php": ">=8.1",
"symfony/filesystem": "^6.4|^7.0",
"symfony/finder": "^6.4|^7.0",
"php-cs-fixer/shim": "^3.62"
"php-cs-fixer/shim": "^3.62",
"vincentlanglet/twig-cs-fixer": "^3.11"
}
}

View File

@@ -47,7 +47,6 @@
"symfony/http-client": "^6.4|^7.0|^8.0",
"symfony/stopwatch": "^6.4|^7.0|^8.0",
"symfony/phpunit-bridge": "^7.2|^8.0",
"vincentlanglet/twig-cs-fixer": "^3.9",
"spatie/phpunit-snapshot-assertions": "^4.2.17|^5.2.3",
"phpunit/phpunit": "^9.6.22",
"symfony/ux-icons": "^2.18",

View File

@@ -160,16 +160,16 @@
{% else %}
<section class="twig-component-metrics metrics">
<div class="metric-group">
{{ _self.metric(collector.componentCount, "Twig Components") }}
{{ _self.metric(collector.componentCount, 'Twig Components') }}
</div>
<div class="metric-divider"></div>
<div class="metric-group">
{{ _self.metric(collector.renderCount, "Render Count") }}
{{ _self.metric(collector.renderTime|round, "Render Time", "ms") }}
{{ _self.metric(collector.renderCount, 'Render Count') }}
{{ _self.metric(collector.renderTime|round, 'Render Time', 'ms') }}
</div>
<div class="metric-divider"></div>
<div class="metric-group">
{{ _self.metric((collector.peakMemoryUsage / 1024 / 1024)|number_format(1), "Memory Usage", "MiB") }}
{{ _self.metric((collector.peakMemoryUsage / 1024 / 1024)|number_format(1), 'Memory Usage', 'MiB') }}
</div>
</section>
<section class="twig-component-components">