Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(twig): leverage twig-cs-fixer #60761

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

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions .github/workflows/twig-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Twig CS Fixer

on:
push:
paths:
- '**.twig'
pull_request:
paths:
- '**.twig'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
twig-cs-fixer:
name: Twig CS Fixer
runs-on: ubuntu-24.04

env:
php-version: '8.4'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php-version }}
ini-values: "memory_limit=-1"
coverage: none

- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
Comment on lines +33 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
- name: Checkout
uses: actions/checkout@v4

Please note that in this case a PR branch is required, not a target branch.


- name: Install dependencies
run: |
COMPOSER_HOME="$(composer config home)"
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
export COMPOSER_ROOT_VERSION=$(grep ' VERSION = ' src/Symfony/Component/HttpKernel/Kernel.php | grep -P -o '[0-9]+\.[0-9]+').x-dev
composer require --dev vincentlanglet/twig-cs-fixer:^3.8.1

- name: Run Twig CS Fixer Lint
run: vendor/bin/twig-cs-fixer lint --config=.twig-cs-fixer.dist.php --report=github
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ composer.lock
phpunit.xml
.php-cs-fixer.cache
.php-cs-fixer.php
.twig-cs-fixer.cache
.twig-cs-fixer.php
.phpunit.result.cache
composer.phar
package.tar
Expand Down
28 changes: 28 additions & 0 deletions .twig-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer());

$finder = new TwigCsFixer\File\Finder();
$finder->in('src/Symfony/Bridge/');
$finder->in('src/Symfony/Bundle/');
$finder->in('src/Symfony/Component/');
$finder->exclude('Fixtures');

$config = new TwigCsFixer\Config\Config();
$config->setCacheFile('.twig-cs-fixer.cache');
$config->setRuleset($ruleset);
$config->setFinder($finder);
// RFC: should we allow?
// $config->allowNonFixableRules();

return $config;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% extends "@email/zurb_2/notification/body.html.twig" %}
{% extends '@email/zurb_2/notification/body.html.twig' %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% extends "@email/zurb_2/notification/body.txt.twig" %}
{% extends '@email/zurb_2/notification/body.txt.twig' %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<head>
<style>
{% block style %}
{{ source("@email/zurb_2/main.css") }}
{{ source("@email/zurb_2/notification/local.css") }}
{{ source('@email/zurb_2/main.css') }}
{{ source('@email/zurb_2/notification/local.css') }}
{% endblock %}
</style>
</head>
<body>
<spacer size="32"></spacer>
<wrapper class="body">
<container class="body_{{ ("urgent" == importance ? "alert" : ("high" == importance ? "warning" : "default")) }}">
<container class="body_{{ ('urgent' == importance ? 'alert' : ('high' == importance ? 'warning' : 'default')) }}">
<spacer size="16"></spacer>
<row>
<columns large="12" small="12">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use "bootstrap_3_layout.html.twig" %}
{% use 'bootstrap_3_layout.html.twig' %}

{% block form_start -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
Expand All @@ -25,7 +25,7 @@ col-sm-2
{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ ((not compound or force_error|default(false)) and not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use "bootstrap_base_layout.html.twig" %}
{% use 'bootstrap_base_layout.html.twig' %}

{# Widgets #}

Expand Down Expand Up @@ -35,21 +35,21 @@
{% block checkbox_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{% if 'checkbox-inline' in parent_label_class %}
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
{% else -%}
<div class="checkbox">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- endif -%}
{%- endblock checkbox_widget %}

{% block radio_widget -%}
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
{%- if 'radio-inline' in parent_label_class -%}
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
{%- else -%}
<div class="radio">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- endif -%}
{%- endblock radio_widget %}
Expand All @@ -73,13 +73,13 @@
{% endblock %}

{% block checkbox_label -%}
{%- set label_attr = label_attr|merge({'for': id}) -%}
{%- set label_attr = label_attr|merge({for: id}) -%}

{{- block('checkbox_radio_label') -}}
{%- endblock checkbox_label %}

{% block radio_label -%}
{%- set label_attr = label_attr|merge({'for': id}) -%}
{%- set label_attr = label_attr|merge({for: id}) -%}

{{- block('checkbox_radio_label') -}}
{%- endblock radio_label %}
Expand All @@ -104,7 +104,7 @@
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
<label{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
{#- if statement must be kept on the same line, to force the space between widget and label -#}
{{- widget|raw }} {% if label is not same as(false) -%}
{%- if translation_domain is same as(false) -%}
Expand All @@ -130,7 +130,7 @@
{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group' ~ ((not compound or force_error|default(false)) and not valid ? ' has-error'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) }} {# -#}
Expand Down Expand Up @@ -201,7 +201,7 @@
{% block form_help -%}
{%- if help is not empty -%}
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block')|trim}) -%}
<span id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
<span id="{{ id }}_help"{% with {attr: help_attr} %}{{ block('attributes') }}{% endwith %}>
{%- if translation_domain is same as(false) -%}
{%- if help_html is same as(false) -%}
{{- help -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use "bootstrap_4_layout.html.twig" %}
{% use 'bootstrap_4_layout.html.twig' %}

{# Labels #}

Expand Down Expand Up @@ -26,7 +26,7 @@ col-sm-2
{%- else -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group row' ~ ((not compound or force_error|default(false)) and not valid ? ' is-invalid'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
Expand All @@ -41,7 +41,7 @@ col-sm-2
{% block fieldset_form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<fieldset{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use "bootstrap_base_layout.html.twig" %}
{% use 'bootstrap_base_layout.html.twig' %}

{# Widgets #}

Expand Down Expand Up @@ -123,10 +123,10 @@
{%- set type = type|default('file') -%}
{%- set input_lang = 'en' -%}
{% if app is defined and app.request is defined %}{%- set input_lang = app.request.locale -%}{%- endif -%}
{%- set attr = {lang: input_lang} | merge(attr) -%}
{%- set attr = {lang: input_lang}|merge(attr) -%}
{{- block('form_widget_simple') -}}
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim })|filter((value, key) => key != 'id') -%}
<label for="{{ form.vars.id }}" {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-file-label')|trim})|filter((value, key) => key != 'id') -%}
<label for="{{ form.vars.id }}" {% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
{%- if attr.placeholder is defined and attr.placeholder is not none -%}
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
{%- endif -%}
Expand Down Expand Up @@ -173,17 +173,17 @@
{%- if 'checkbox-custom' in parent_label_class -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- elseif 'switch-custom' in parent_label_class -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
<div class="custom-control custom-switch{{ 'switch-inline' in parent_label_class ? ' custom-control-inline' }}">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- else -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
<div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- endif -%}
{%- endblock checkbox_widget %}
Expand All @@ -193,12 +193,12 @@
{%- if 'radio-custom' in parent_label_class -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
<div class="custom-control custom-radio{{ 'radio-inline' in parent_label_class ? ' custom-control-inline' }}">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- else -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
<div class="form-check{{ 'radio-inline' in parent_label_class ? ' form-check-inline' }}">
{{- form_label(form, null, { widget: parent() }) -}}
{{- form_label(form, null, {widget: parent()}) -}}
</div>
{%- endif -%}
{%- endblock radio_widget %}
Expand Down Expand Up @@ -233,7 +233,7 @@
{% if required -%}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>
<{{ element|default('label') }}{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
{{- block('form_label_content') -}}
{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
{%- else -%}
Expand All @@ -256,7 +256,7 @@
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
{%- endif %}
{%- if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{% set label_attr = label_attr|merge({for: id}) %}
{%- endif -%}
{%- if required -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
Expand All @@ -267,7 +267,7 @@
{% endif %}

{{ widget|raw }}
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
<label{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
{%- if label is not same as(false) -%}
{{- block('form_label_content') -}}
{%- endif -%}
Expand All @@ -284,7 +284,7 @@
{%- endif -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}
Expand Down Expand Up @@ -312,7 +312,7 @@
{% block form_help -%}
{%- if help is not empty -%}
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-muted')|trim}) -%}
<small id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
<small id="{{ id }}_help"{% with {attr: help_attr} %}{{ block('attributes') }}{% endwith %}>
{{- block('form_help_content') -}}
</small>
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use "bootstrap_5_layout.html.twig" %}
{% use 'bootstrap_5_layout.html.twig' %}

{# Labels #}

Expand Down Expand Up @@ -29,7 +29,7 @@
{%- else -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
{%- set row_class = row_class|default(row_attr.class|default('mb-3')) -%}
{%- set is_form_floating = is_form_floating|default('form-floating' in row_class) -%}
Expand Down Expand Up @@ -73,7 +73,7 @@
{% block fieldset_form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
{%- endif -%}
<fieldset{% with {attr: row_attr|merge({class: row_attr.class|default('mb-3')|trim})} %}{{ block('attributes') }}{% endwith %}>
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
Expand Down
Loading
Loading