Skip to content

Commit e5654f3

Browse files
committed
minor #1793 [Site] Configure Twig-CS-Fixer (smnandre)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Site] Configure Twig-CS-Fixer (and apply rules) Fully isolate website GA workflows from the components Fix #1166 Commits ------- 6131d47 [Site] Configure Twig-CS-Fixer
2 parents 4ae4987 + 6131d47 commit e5654f3

30 files changed

+289
-60
lines changed

.github/workflows/ux.symfony.com.yaml

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,62 @@ on:
99
- 'ux.symfony.com/**'
1010

1111
jobs:
12-
tests:
12+
13+
cs-php:
1314
runs-on: ubuntu-latest
1415
defaults:
15-
run:
16-
shell: bash
17-
working-directory: ux.symfony.com
18-
16+
run:
17+
shell: bash
18+
working-directory: ux.symfony.com
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v4
21+
- uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: '8.3'
24+
tools: php-cs-fixer
25+
- name: Install dependencies
26+
uses: ramsey/composer-install@v3
27+
with:
28+
working-directory: ux.symfony.com
29+
- name: php-cs-fixer
30+
run: php-cs-fixer check --diff
2131

22-
- uses: shivammathur/setup-php@v2
23-
with:
24-
php-version: 8.3
25-
26-
- name: Install dependencies
27-
uses: ramsey/composer-install@v3
28-
with:
32+
cs-twig:
33+
runs-on: ubuntu-latest
34+
defaults:
35+
run:
36+
shell: bash
2937
working-directory: ux.symfony.com
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: shivammathur/setup-php@v2
41+
with:
42+
php-version: '8.3'
43+
- name: Install dependencies
44+
uses: ramsey/composer-install@v3
45+
with:
46+
working-directory: ux.symfony.com
47+
- name: twig-cs-fixer
48+
run: vendor/bin/twig-cs-fixer lint templates --report=github
3049

31-
- name: Importmap dependencies
32-
run: php bin/console importmap:install
33-
34-
- name: Build Sass assets
35-
run: php bin/console sass:build
36-
37-
- name: Tests
38-
run: vendor/bin/phpunit
50+
tests:
51+
runs-on: ubuntu-latest
52+
defaults:
53+
run:
54+
shell: bash
55+
working-directory: ux.symfony.com
56+
steps:
57+
- uses: actions/checkout@v4
58+
- uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: '8.3'
61+
- name: Install dependencies
62+
uses: ramsey/composer-install@v3
63+
with:
64+
working-directory: ux.symfony.com
65+
- name: Importmap dependencies
66+
run: php bin/console importmap:install
67+
- name: Build Sass assets
68+
run: php bin/console sass:build
69+
- name: Tests
70+
run: vendor/bin/phpunit

.php-cs-fixer.dist.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@
3333
->setRiskyAllowed(true)
3434
->setFinder(
3535
PhpCsFixer\Finder::create()
36-
->in([__DIR__.'/src', __DIR__.'/ux.symfony.com/src', __DIR__.'/ux.symfony.com/tests'])
36+
->in([__DIR__.'/src'])
3737
->append([__FILE__])
3838
->notPath('#/Fixtures/#')
39-
->notPath('#/app/var/#')
40-
->notPath('#/var/cache/#')
39+
->notPath('#/var/#')
4140
)
4241
;

ux.symfony.com/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
/public/assets/
1717
/assets/vendor/
1818
###< symfony/asset-mapper ###
19+
20+
###> vincentlanglet/twig-cs-fixer ###
21+
/.twig-cs-fixer.cache
22+
###< vincentlanglet/twig-cs-fixer ###

ux.symfony.com/.php-cs-fixer.dist.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
if (!file_exists(__DIR__.'/src')) {
13+
exit(0);
14+
}
15+
16+
$fileHeaderComment = <<<'EOF'
17+
This file is part of the Symfony package.
18+
19+
(c) Fabien Potencier <[email protected]>
20+
21+
For the full copyright and license information, please view the LICENSE
22+
file that was distributed with this source code.
23+
EOF;
24+
25+
return (new PhpCsFixer\Config())
26+
->setRules([
27+
'@PHPUnit75Migration:risky' => true,
28+
'@Symfony' => true,
29+
'@Symfony:risky' => true,
30+
'header_comment' => ['header' => $fileHeaderComment],
31+
'nullable_type_declaration' => true,
32+
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
33+
])
34+
->setRiskyAllowed(true)
35+
->setFinder(
36+
PhpCsFixer\Finder::create()
37+
->in([
38+
__DIR__.'/src',
39+
__DIR__.'/tests',
40+
])
41+
->append([__FILE__])
42+
)
43+
->setCacheFile('.php-cs-fixer.cache')
44+
;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$config = new TwigCsFixer\Config\Config();
4+
$config->setCacheFile(null);
5+
6+
return $config;

ux.symfony.com/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"symfony/phpunit-bridge": "7.0.*",
128128
"symfony/stopwatch": "7.0.*",
129129
"symfony/web-profiler-bundle": "7.0.*",
130+
"vincentlanglet/twig-cs-fixer": "^2.8",
130131
"zenstruck/browser": "^1.4",
131132
"zenstruck/foundry": "^1.33"
132133
}

ux.symfony.com/composer.lock

Lines changed: 139 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ux.symfony.com/src/Controller/UxPackage/SwupController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function __invoke(UxPackageRepository $packageRepository, int $page = 1):
2626
$package = $packageRepository->find('swup');
2727

2828
$packages = $packageRepository->findAll();
29-
$pages = ceil(count($packages) / self::PER_PAGE);
29+
$pages = ceil(\count($packages) / self::PER_PAGE);
3030
if ($page < 1 || $page > $pages) {
3131
throw $this->createNotFoundException('Page not found');
3232
}
33-
$results = array_slice($packages, ($page - 1) * self::PER_PAGE, self::PER_PAGE);
33+
$results = \array_slice($packages, ($page - 1) * self::PER_PAGE, self::PER_PAGE);
3434

3535
return $this->render('ux_packages/swup.html.twig', [
3636
'package' => $package,

ux.symfony.com/symfony.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@
657657
"twig/twig": {
658658
"version": "v3.3.10"
659659
},
660+
"vincentlanglet/twig-cs-fixer": {
661+
"version": "2.8",
662+
"recipe": {
663+
"repo": "github.com/symfony/recipes-contrib",
664+
"branch": "main",
665+
"version": "0.6",
666+
"ref": "e4da12a48e8138479bd24a675321bcfd84950266"
667+
}
668+
},
660669
"zenstruck/assert": {
661670
"version": "v1.0.1"
662671
},

ux.symfony.com/templates/changelog.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% set meta = {
44
title: 'Changelog',
5-
title_suffix: " - Symfony UX",
5+
title_suffix: ' - Symfony UX',
66
description: 'Symfony UX changelog - New features, bug fixes, performances and security improvements about Symfony Live Components, Twig Components, Autocomplete, Icons...',
77
canonical: url('app_changelog'),
88
} %}

ux.symfony.com/templates/components/Browser.html.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@
4242
</div>
4343
</div>
4444
</div>
45-

ux.symfony.com/templates/components/ChangelogItem.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article {{ attributes.defaults({class: "ChangelogItem"}) }} id="{{ item.version }}">
1+
<article {{ attributes.defaults({class: 'ChangelogItem'}) }} id="{{ item.version }}">
22

33
<div class="ChangelogItem__Anchor">
44
<a class="ChangelogItem__Version" href="https://github.com/symfony/ux/releases/tag/{{ item.version }}"

ux.symfony.com/templates/components/DocsLink.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
>{{ title }}</a>
77
{% if icon|default %}
88
<twig:Icon name="{{ icon }}" class="DocsLink_arrow"/>
9-
{% elseif isExternal %}
9+
{% elseif isExternal %}
1010
<twig:Icon name="arrow-right" style="transform: rotate(-45deg);" class="DocsLink_arrow"/>
1111
{% endif %}
1212
</p>

ux.symfony.com/templates/components/Icon/IconGrid.html.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@
1717
{% endfor %}
1818

1919
</div>
20-

0 commit comments

Comments
 (0)