Skip to content

[Site] Configure Twig-CS-Fixer #1793

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

Merged
merged 1 commit into from
Apr 26, 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
74 changes: 53 additions & 21 deletions .github/workflows/ux.symfony.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/#')
)
;
4 changes: 4 additions & 0 deletions ux.symfony.com/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
/public/assets/
/assets/vendor/
###< symfony/asset-mapper ###

###> vincentlanglet/twig-cs-fixer ###
/.twig-cs-fixer.cache
###< vincentlanglet/twig-cs-fixer ###
44 changes: 44 additions & 0 deletions ux.symfony.com/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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.
*/

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

$fileHeaderComment = <<<'EOF'
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.
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')
;
6 changes: 6 additions & 0 deletions ux.symfony.com/.twig-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$config = new TwigCsFixer\Config\Config();
$config->setCacheFile(null);

return $config;
1 change: 1 addition & 0 deletions ux.symfony.com/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
140 changes: 139 additions & 1 deletion ux.symfony.com/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ux.symfony.com/src/Controller/UxPackage/SwupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions ux.symfony.com/symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion ux.symfony.com/templates/changelog.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
} %}
Expand Down
1 change: 0 additions & 1 deletion ux.symfony.com/templates/components/Browser.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@
</div>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<article {{ attributes.defaults({class: "ChangelogItem"}) }} id="{{ item.version }}">
<article {{ attributes.defaults({class: 'ChangelogItem'}) }} id="{{ item.version }}">

<div class="ChangelogItem__Anchor">
<a class="ChangelogItem__Version" href="https://github.com/symfony/ux/releases/tag/{{ item.version }}"
Expand Down
2 changes: 1 addition & 1 deletion ux.symfony.com/templates/components/DocsLink.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
>{{ title }}</a>
{% if icon|default %}
<twig:Icon name="{{ icon }}" class="DocsLink_arrow"/>
{% elseif isExternal %}
{% elseif isExternal %}
<twig:Icon name="arrow-right" style="transform: rotate(-45deg);" class="DocsLink_arrow"/>
{% endif %}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
{% endfor %}

</div>

Loading