From 6131d47ea5780f5ccc0b3c4a2be231492594c44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Fri, 26 Apr 2024 18:35:49 +0200 Subject: [PATCH] [Site] Configure Twig-CS-Fixer --- .github/workflows/ux.symfony.com.yaml | 74 ++++++--- .php-cs-fixer.dist.php | 5 +- ux.symfony.com/.gitignore | 4 + ux.symfony.com/.php-cs-fixer.dist.php | 44 ++++++ ux.symfony.com/.twig-cs-fixer.dist.php | 6 + ux.symfony.com/composer.json | 1 + ux.symfony.com/composer.lock | 140 +++++++++++++++++- .../Controller/UxPackage/SwupController.php | 4 +- ux.symfony.com/symfony.lock | 9 ++ ux.symfony.com/templates/changelog.html.twig | 2 +- .../templates/components/Browser.html.twig | 1 - .../components/ChangelogItem.html.twig | 2 +- .../templates/components/DocsLink.html.twig | 2 +- .../components/Icon/IconGrid.html.twig | 1 - .../components/Icon/IconModal.html.twig | 8 +- .../components/ProductGrid.html.twig | 2 +- .../components/ThemeSwitcher.html.twig | 4 +- .../components/LiveMemory/Board.html.twig | 2 +- .../components/LiveMemory/Card.html.twig | 4 +- .../components/LiveMemory/Metrics.html.twig | 2 +- .../components/LiveMemory/ScoreRow.html.twig | 2 +- .../components/LiveMemory/Tableau.html.twig | 2 +- .../LiveMemory/ThemeSwitch.html.twig | 4 +- .../components/LiveMemory/Timer.html.twig | 2 +- .../demos/live_memory/index.html.twig | 4 +- .../templates/icons/index.html.twig | 5 +- .../templates/liveDemoBase.html.twig | 3 +- ux.symfony.com/templates/main/demos.html.twig | 4 +- .../templates/main/homepage.html.twig | 2 +- .../templates/main/packages.html.twig | 4 +- 30 files changed, 289 insertions(+), 60 deletions(-) create mode 100644 ux.symfony.com/.php-cs-fixer.dist.php create mode 100644 ux.symfony.com/.twig-cs-fixer.dist.php diff --git a/.github/workflows/ux.symfony.com.yaml b/.github/workflows/ux.symfony.com.yaml index 30bbb0f9ea3..48ec0b31ba4 100644 --- a/.github/workflows/ux.symfony.com.yaml +++ b/.github/workflows/ux.symfony.com.yaml @@ -9,30 +9,62 @@ on: - 'ux.symfony.com/**' jobs: - tests: + + cs-php: runs-on: ubuntu-latest defaults: - run: - shell: bash - working-directory: ux.symfony.com - + run: + shell: bash + working-directory: ux.symfony.com steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + tools: php-cs-fixer + - name: Install dependencies + uses: ramsey/composer-install@v3 + with: + working-directory: ux.symfony.com + - name: php-cs-fixer + run: php-cs-fixer check --diff - - uses: shivammathur/setup-php@v2 - with: - php-version: 8.3 - - - name: Install dependencies - uses: ramsey/composer-install@v3 - with: + cs-twig: + runs-on: ubuntu-latest + defaults: + run: + shell: bash working-directory: ux.symfony.com + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: Install dependencies + uses: ramsey/composer-install@v3 + with: + working-directory: ux.symfony.com + - name: twig-cs-fixer + run: vendor/bin/twig-cs-fixer lint templates --report=github - - name: Importmap dependencies - run: php bin/console importmap:install - - - name: Build Sass assets - run: php bin/console sass:build - - - name: Tests - run: vendor/bin/phpunit + tests: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + working-directory: ux.symfony.com + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + - name: Install dependencies + uses: ramsey/composer-install@v3 + with: + working-directory: ux.symfony.com + - name: Importmap dependencies + run: php bin/console importmap:install + - name: Build Sass assets + run: php bin/console sass:build + - name: Tests + run: vendor/bin/phpunit diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 33c5085c1ef..fbf4badadde 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -33,10 +33,9 @@ ->setRiskyAllowed(true) ->setFinder( PhpCsFixer\Finder::create() - ->in([__DIR__.'/src', __DIR__.'/ux.symfony.com/src', __DIR__.'/ux.symfony.com/tests']) + ->in([__DIR__.'/src']) ->append([__FILE__]) ->notPath('#/Fixtures/#') - ->notPath('#/app/var/#') - ->notPath('#/var/cache/#') + ->notPath('#/var/#') ) ; diff --git a/ux.symfony.com/.gitignore b/ux.symfony.com/.gitignore index 2e2c322f6c4..f3ace40024f 100644 --- a/ux.symfony.com/.gitignore +++ b/ux.symfony.com/.gitignore @@ -16,3 +16,7 @@ /public/assets/ /assets/vendor/ ###< symfony/asset-mapper ### + +###> vincentlanglet/twig-cs-fixer ### +/.twig-cs-fixer.cache +###< vincentlanglet/twig-cs-fixer ### diff --git a/ux.symfony.com/.php-cs-fixer.dist.php b/ux.symfony.com/.php-cs-fixer.dist.php new file mode 100644 index 00000000000..06c7f89bdc3 --- /dev/null +++ b/ux.symfony.com/.php-cs-fixer.dist.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +if (!file_exists(__DIR__.'/src')) { + exit(0); +} + +$fileHeaderComment = <<<'EOF' +This file is part of the Symfony package. + +(c) Fabien Potencier + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PHPUnit75Migration:risky' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + 'header_comment' => ['header' => $fileHeaderComment], + 'nullable_type_declaration' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']], + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->append([__FILE__]) + ) + ->setCacheFile('.php-cs-fixer.cache') +; diff --git a/ux.symfony.com/.twig-cs-fixer.dist.php b/ux.symfony.com/.twig-cs-fixer.dist.php new file mode 100644 index 00000000000..042d4137b00 --- /dev/null +++ b/ux.symfony.com/.twig-cs-fixer.dist.php @@ -0,0 +1,6 @@ +setCacheFile(null); + +return $config; diff --git a/ux.symfony.com/composer.json b/ux.symfony.com/composer.json index 8c5f5bd774d..592939539e5 100644 --- a/ux.symfony.com/composer.json +++ b/ux.symfony.com/composer.json @@ -127,6 +127,7 @@ "symfony/phpunit-bridge": "7.0.*", "symfony/stopwatch": "7.0.*", "symfony/web-profiler-bundle": "7.0.*", + "vincentlanglet/twig-cs-fixer": "^2.8", "zenstruck/browser": "^1.4", "zenstruck/foundry": "^1.33" } diff --git a/ux.symfony.com/composer.lock b/ux.symfony.com/composer.lock index 26da232a8fd..f05ffea4813 100644 --- a/ux.symfony.com/composer.lock +++ b/ux.symfony.com/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e3bf9a90112df53b2a003340258431b5", + "content-hash": "4d99693ebbe6bef767a820491dc32ccf", "packages": [ { "name": "composer/semver", @@ -11704,6 +11704,144 @@ ], "time": "2024-03-03T12:36:25+00:00" }, + { + "name": "vincentlanglet/twig-cs-fixer", + "version": "2.8.1", + "source": { + "type": "git", + "url": "https://github.com/VincentLanglet/Twig-CS-Fixer.git", + "reference": "8b843a17bdfd4c6ea77a01a5fea0720d037826c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/VincentLanglet/Twig-CS-Fixer/zipball/8b843a17bdfd4c6ea77a01a5fea0720d037826c9", + "reference": "8b843a17bdfd4c6ea77a01a5fea0720d037826c9", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.0.0", + "ext-ctype": "*", + "ext-json": "*", + "php": ">=8.0", + "symfony/console": "^5.4.9 || ^6.0 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/string": "^5.4 || ^6.0 || ^7.0", + "twig/twig": "^2.14.0 || ^3.0.5", + "webmozart/assert": "^1.10" + }, + "require-dev": { + "dereuromark/composer-prefer-lowest": "^0.1.10", + "ergebnis/composer-normalize": "^2.29", + "friendsofphp/php-cs-fixer": "^3.13.0", + "icanhazstring/composer-unused": "^0.8.5", + "infection/infection": "^0.26.16 || ^0.27.0", + "maglnet/composer-require-checker": "^3.8 || ^4.3", + "phpstan/phpstan": "^1.9.1", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpstan/phpstan-symfony": "^1.2.16", + "phpstan/phpstan-webmozart-assert": "^1.2.2", + "phpunit/phpunit": "^9.5.26 || ^10.0.9", + "psalm/plugin-phpunit": "^0.18.4", + "psalm/plugin-symfony": "^5.0.0", + "rector/rector": "^1.0.0", + "symfony/process": "^5.4 || ^6.0 || ^7.0", + "symfony/twig-bridge": "^5.4 || ^6.0 || ^7.0", + "symfony/ux-twig-component": "^2.2.0", + "twig/cache-extra": "^3.2", + "vimeo/psalm": "^5.2.0" + }, + "bin": [ + "bin/twig-cs-fixer" + ], + "type": "coding-standard", + "autoload": { + "psr-4": { + "TwigCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Vincent Langlet" + } + ], + "description": "A tool to automatically fix Twig code style", + "homepage": "https://github.com/VincentLanglet/Twig-CS-Fixer", + "support": { + "issues": "https://github.com/VincentLanglet/Twig-CS-Fixer/issues", + "source": "https://github.com/VincentLanglet/Twig-CS-Fixer/tree/2.8.1" + }, + "funding": [ + { + "url": "https://github.com/VincentLanglet", + "type": "github" + } + ], + "time": "2024-04-26T08:59:11+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" + }, { "name": "zenstruck/assert", "version": "v1.5.0", diff --git a/ux.symfony.com/src/Controller/UxPackage/SwupController.php b/ux.symfony.com/src/Controller/UxPackage/SwupController.php index 93b283d562b..2938e49e4ee 100644 --- a/ux.symfony.com/src/Controller/UxPackage/SwupController.php +++ b/ux.symfony.com/src/Controller/UxPackage/SwupController.php @@ -26,11 +26,11 @@ public function __invoke(UxPackageRepository $packageRepository, int $page = 1): $package = $packageRepository->find('swup'); $packages = $packageRepository->findAll(); - $pages = ceil(count($packages) / self::PER_PAGE); + $pages = ceil(\count($packages) / self::PER_PAGE); if ($page < 1 || $page > $pages) { throw $this->createNotFoundException('Page not found'); } - $results = array_slice($packages, ($page - 1) * self::PER_PAGE, self::PER_PAGE); + $results = \array_slice($packages, ($page - 1) * self::PER_PAGE, self::PER_PAGE); return $this->render('ux_packages/swup.html.twig', [ 'package' => $package, diff --git a/ux.symfony.com/symfony.lock b/ux.symfony.com/symfony.lock index 837d59b26e1..6b7bcfa94ce 100644 --- a/ux.symfony.com/symfony.lock +++ b/ux.symfony.com/symfony.lock @@ -657,6 +657,15 @@ "twig/twig": { "version": "v3.3.10" }, + "vincentlanglet/twig-cs-fixer": { + "version": "2.8", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "0.6", + "ref": "e4da12a48e8138479bd24a675321bcfd84950266" + } + }, "zenstruck/assert": { "version": "v1.0.1" }, diff --git a/ux.symfony.com/templates/changelog.html.twig b/ux.symfony.com/templates/changelog.html.twig index d405c1fb75f..252265d0dd5 100644 --- a/ux.symfony.com/templates/changelog.html.twig +++ b/ux.symfony.com/templates/changelog.html.twig @@ -2,7 +2,7 @@ {% set meta = { title: 'Changelog', - title_suffix: " - Symfony UX", + title_suffix: ' - Symfony UX', description: 'Symfony UX changelog - New features, bug fixes, performances and security improvements about Symfony Live Components, Twig Components, Autocomplete, Icons...', canonical: url('app_changelog'), } %} diff --git a/ux.symfony.com/templates/components/Browser.html.twig b/ux.symfony.com/templates/components/Browser.html.twig index 8f219b3f73d..a18aa38fe50 100644 --- a/ux.symfony.com/templates/components/Browser.html.twig +++ b/ux.symfony.com/templates/components/Browser.html.twig @@ -42,4 +42,3 @@ - diff --git a/ux.symfony.com/templates/components/ChangelogItem.html.twig b/ux.symfony.com/templates/components/ChangelogItem.html.twig index 5368e9b4941..1fff78b9c6d 100644 --- a/ux.symfony.com/templates/components/ChangelogItem.html.twig +++ b/ux.symfony.com/templates/components/ChangelogItem.html.twig @@ -1,4 +1,4 @@ -
+
{{ title }} {% if icon|default %} - {% elseif isExternal %} + {% elseif isExternal %} {% endif %}

diff --git a/ux.symfony.com/templates/components/Icon/IconGrid.html.twig b/ux.symfony.com/templates/components/Icon/IconGrid.html.twig index 11e4bdd39ef..9e41cc5361a 100644 --- a/ux.symfony.com/templates/components/Icon/IconGrid.html.twig +++ b/ux.symfony.com/templates/components/Icon/IconGrid.html.twig @@ -17,4 +17,3 @@ {% endfor %}
- diff --git a/ux.symfony.com/templates/components/Icon/IconModal.html.twig b/ux.symfony.com/templates/components/Icon/IconModal.html.twig index b8542831980..30dfe1dc6db 100644 --- a/ux.symfony.com/templates/components/Icon/IconModal.html.twig +++ b/ux.symfony.com/templates/components/Icon/IconModal.html.twig @@ -1,7 +1,7 @@ @@ -105,7 +105,7 @@ 'GitHub': iconSet.github ? { title: iconSet.github.name, href: iconSet.github.url, - } : null, + } : null, 'Licence': iconSet.license ? { title: iconSet.license.title, href: iconSet.license.url|default, diff --git a/ux.symfony.com/templates/components/ProductGrid.html.twig b/ux.symfony.com/templates/components/ProductGrid.html.twig index c9c5892186d..5d35dfe8eeb 100644 --- a/ux.symfony.com/templates/components/ProductGrid.html.twig +++ b/ux.symfony.com/templates/components/ProductGrid.html.twig @@ -4,7 +4,7 @@
{% if page > 1 %} - {# 🦊 #} + {# 🦊 #} {# Adding a fake "previous page" div is enough to trick the system #} {# It must have the same ID than the original page #}
diff --git a/ux.symfony.com/templates/components/ThemeSwitcher.html.twig b/ux.symfony.com/templates/components/ThemeSwitcher.html.twig index 6b9a4c7f190..deb5491e99b 100644 --- a/ux.symfony.com/templates/components/ThemeSwitcher.html.twig +++ b/ux.symfony.com/templates/components/ThemeSwitcher.html.twig @@ -1,6 +1,6 @@ {% endfor %}
diff --git a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Card.html.twig b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Card.html.twig index 018732c62d2..4c87e409ce9 100644 --- a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Card.html.twig +++ b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Card.html.twig @@ -6,7 +6,7 @@ 'LiveMemory-Card--paired': paired, 'LiveMemory-Card--matched': matched, }, class|default) }}" - style="--card-delta:{{ (key* 17) % 10 }};" + style="--card-delta:{{ (key * 17) % 10 }};" > {# We keep the back / button to flip until the card is matched #} @@ -18,7 +18,7 @@ data-live-action-param="flip" data-live-key-param="{{ key }}" > -{# data-live-item-name-param="CustomItem"#} +{# data-live-item-name-param="CustomItem" #} LiveMemory Card Back - {{ back|upper }} {% else %} {% set value = game.timeLimit - (game.isEnded ? min(game.timeLimit, game.time) : 0) %} - {% set value = (value > 99 ? '%03d' : '%02d')|format(value) %} + {% set value = (value > 99 ? '%03d' : '%02d')|format(value) %} {% endif %} diff --git a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ScoreRow.html.twig b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ScoreRow.html.twig index ef72810be6d..0f339a77136 100644 --- a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ScoreRow.html.twig +++ b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ScoreRow.html.twig @@ -1,4 +1,4 @@ -
+
{{ label }} {{ this.getDots() }} diff --git a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Tableau.html.twig b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Tableau.html.twig index e4df3ef7456..d83674a6dd0 100644 --- a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Tableau.html.twig +++ b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/Tableau.html.twig @@ -22,7 +22,7 @@ {% if card.matched and card.selected %}
{% for i in 0..9 %} - + {% endfor %}
{% endif %} diff --git a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ThemeSwitch.html.twig b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ThemeSwitch.html.twig index 8e9ce92c287..69e472e0b72 100644 --- a/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ThemeSwitch.html.twig +++ b/ux.symfony.com/templates/demos/live_memory/components/LiveMemory/ThemeSwitch.html.twig @@ -1,7 +1,7 @@