Skip to content

Commit cb8d864

Browse files
committed
minor #60761 Introduce twig-cs-fixer (94noni)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- Introduce `twig-cs-fixer` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no (improve Twig file coding standard consistency) | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony#54799 | License | MIT --- ## This PR adds config file for the tool `twig-cs-fixer` ([via](https://github.com/VincentLanglet/Twig-CS-Fixer)) As per the original issue, this tool is, in my opinion, relevant here to standardize symfony source Twig file, It follows Twig recommandation, and it's since the issue creation mentioned in the official Twig doc. How to use: - install `twig-cs-fixer` via https://github.com/VincentLanglet/Twig-CS-Fixer - run `{twig-cs-fixer} --config=.twig-cs-fixer.dist.php lint --fix` split in 2 commits; first being the real code, second being the tool run on codebase ## TODOs: - decide if its wanted/needed or not - act default rule set for this PR - define CI --- Friendly ping `@VincentLanglet` `@smnandre` as issue commenters Commits ------- fa3cc0e0ef1 Introduce `twig-cs-fixer`
2 parents 126e912 + f866899 commit cb8d864

15 files changed

+88
-88
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{% extends "@email/zurb_2/notification/body.html.twig" %}
1+
{% extends '@email/zurb_2/notification/body.html.twig' %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{% extends "@email/zurb_2/notification/body.txt.twig" %}
1+
{% extends '@email/zurb_2/notification/body.txt.twig' %}

Resources/views/Email/zurb_2/notification/body.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<head>
44
<style>
55
{% block style %}
6-
{{ source("@email/zurb_2/main.css") }}
7-
{{ source("@email/zurb_2/notification/local.css") }}
6+
{{ source('@email/zurb_2/main.css') }}
7+
{{ source('@email/zurb_2/notification/local.css') }}
88
{% endblock %}
99
</style>
1010
</head>
1111
<body>
1212
<spacer size="32"></spacer>
1313
<wrapper class="body">
14-
<container class="body_{{ ("urgent" == importance ? "alert" : ("high" == importance ? "warning" : "default")) }}">
14+
<container class="body_{{ ('urgent' == importance ? 'alert' : ('high' == importance ? 'warning' : 'default')) }}">
1515
<spacer size="16"></spacer>
1616
<row>
1717
<columns large="12" small="12">

Resources/views/Form/bootstrap_3_horizontal_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_3_layout.html.twig" %}
1+
{% use 'bootstrap_3_layout.html.twig' %}
22

33
{% block form_start -%}
44
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
@@ -25,7 +25,7 @@ col-sm-2
2525
{% block form_row -%}
2626
{%- set widget_attr = {} -%}
2727
{%- if help -%}
28-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
28+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
2929
{%- endif -%}
3030
<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 %}>
3131
{{- form_label(form) -}}

Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_base_layout.html.twig" %}
1+
{% use 'bootstrap_base_layout.html.twig' %}
22

33
{# Widgets #}
44

@@ -35,21 +35,21 @@
3535
{% block checkbox_widget -%}
3636
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
3737
{% if 'checkbox-inline' in parent_label_class %}
38-
{{- form_label(form, null, { widget: parent() }) -}}
38+
{{- form_label(form, null, {widget: parent()}) -}}
3939
{% else -%}
4040
<div class="checkbox">
41-
{{- form_label(form, null, { widget: parent() }) -}}
41+
{{- form_label(form, null, {widget: parent()}) -}}
4242
</div>
4343
{%- endif -%}
4444
{%- endblock checkbox_widget %}
4545

4646
{% block radio_widget -%}
4747
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
4848
{%- if 'radio-inline' in parent_label_class -%}
49-
{{- form_label(form, null, { widget: parent() }) -}}
49+
{{- form_label(form, null, {widget: parent()}) -}}
5050
{%- else -%}
5151
<div class="radio">
52-
{{- form_label(form, null, { widget: parent() }) -}}
52+
{{- form_label(form, null, {widget: parent()}) -}}
5353
</div>
5454
{%- endif -%}
5555
{%- endblock radio_widget %}
@@ -73,13 +73,13 @@
7373
{% endblock %}
7474

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

7878
{{- block('checkbox_radio_label') -}}
7979
{%- endblock checkbox_label %}
8080

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

8484
{{- block('checkbox_radio_label') -}}
8585
{%- endblock radio_label %}
@@ -104,7 +104,7 @@
104104
{% set label = name|humanize %}
105105
{%- endif -%}
106106
{%- endif -%}
107-
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
107+
<label{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
108108
{#- if statement must be kept on the same line, to force the space between widget and label -#}
109109
{{- widget|raw }} {% if label is not same as(false) -%}
110110
{%- if translation_domain is same as(false) -%}
@@ -130,7 +130,7 @@
130130
{% block form_row -%}
131131
{%- set widget_attr = {} -%}
132132
{%- if help -%}
133-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
133+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
134134
{%- endif -%}
135135
<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 %}>
136136
{{- form_label(form) }} {# -#}
@@ -201,7 +201,7 @@
201201
{% block form_help -%}
202202
{%- if help -%}
203203
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block')|trim}) -%}
204-
<span id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
204+
<span id="{{ id }}_help"{% with {attr: help_attr} %}{{ block('attributes') }}{% endwith %}>
205205
{%- if translation_domain is same as(false) -%}
206206
{%- if help_html is same as(false) -%}
207207
{{- help -}}

Resources/views/Form/bootstrap_4_horizontal_layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_4_layout.html.twig" %}
1+
{% use 'bootstrap_4_layout.html.twig' %}
22

33
{# Labels #}
44

@@ -26,7 +26,7 @@ col-sm-2
2626
{%- else -%}
2727
{%- set widget_attr = {} -%}
2828
{%- if help -%}
29-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
29+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
3030
{%- endif -%}
3131
<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 %}>
3232
{{- form_label(form) -}}
@@ -41,7 +41,7 @@ col-sm-2
4141
{% block fieldset_form_row -%}
4242
{%- set widget_attr = {} -%}
4343
{%- if help -%}
44-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
44+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
4545
{%- endif -%}
4646
<fieldset{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
4747
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_base_layout.html.twig" %}
1+
{% use 'bootstrap_base_layout.html.twig' %}
22

33
{# Widgets #}
44

@@ -123,10 +123,10 @@
123123
{%- set type = type|default('file') -%}
124124
{%- set input_lang = 'en' -%}
125125
{% if app is defined and app.request is defined %}{%- set input_lang = app.request.locale -%}{%- endif -%}
126-
{%- set attr = {lang: input_lang} | merge(attr) -%}
126+
{%- set attr = {lang: input_lang}|merge(attr) -%}
127127
{{- block('form_widget_simple') -}}
128-
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim })|filter((value, key) => key != 'id') -%}
129-
<label for="{{ form.vars.id }}" {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
128+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-file-label')|trim})|filter((value, key) => key != 'id') -%}
129+
<label for="{{ form.vars.id }}" {% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
130130
{%- if attr.placeholder is defined and attr.placeholder is not none -%}
131131
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
132132
{%- endif -%}
@@ -173,17 +173,17 @@
173173
{%- if 'checkbox-custom' in parent_label_class -%}
174174
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
175175
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
176-
{{- form_label(form, null, { widget: parent() }) -}}
176+
{{- form_label(form, null, {widget: parent()}) -}}
177177
</div>
178178
{%- elseif 'switch-custom' in parent_label_class -%}
179179
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
180180
<div class="custom-control custom-switch{{ 'switch-inline' in parent_label_class ? ' custom-control-inline' }}">
181-
{{- form_label(form, null, { widget: parent() }) -}}
181+
{{- form_label(form, null, {widget: parent()}) -}}
182182
</div>
183183
{%- else -%}
184184
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
185185
<div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}">
186-
{{- form_label(form, null, { widget: parent() }) -}}
186+
{{- form_label(form, null, {widget: parent()}) -}}
187187
</div>
188188
{%- endif -%}
189189
{%- endblock checkbox_widget %}
@@ -193,12 +193,12 @@
193193
{%- if 'radio-custom' in parent_label_class -%}
194194
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
195195
<div class="custom-control custom-radio{{ 'radio-inline' in parent_label_class ? ' custom-control-inline' }}">
196-
{{- form_label(form, null, { widget: parent() }) -}}
196+
{{- form_label(form, null, {widget: parent()}) -}}
197197
</div>
198198
{%- else -%}
199199
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
200200
<div class="form-check{{ 'radio-inline' in parent_label_class ? ' form-check-inline' }}">
201-
{{- form_label(form, null, { widget: parent() }) -}}
201+
{{- form_label(form, null, {widget: parent()}) -}}
202202
</div>
203203
{%- endif -%}
204204
{%- endblock radio_widget %}
@@ -233,7 +233,7 @@
233233
{% if required -%}
234234
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
235235
{%- endif -%}
236-
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>
236+
<{{ element|default('label') }}{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
237237
{{- block('form_label_content') -}}
238238
{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
239239
{%- else -%}
@@ -256,7 +256,7 @@
256256
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
257257
{%- endif %}
258258
{%- if not compound -%}
259-
{% set label_attr = label_attr|merge({'for': id}) %}
259+
{% set label_attr = label_attr|merge({for: id}) %}
260260
{%- endif -%}
261261
{%- if required -%}
262262
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
@@ -267,7 +267,7 @@
267267
{% endif %}
268268

269269
{{ widget|raw }}
270-
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
270+
<label{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
271271
{%- if label is not same as(false) -%}
272272
{{- block('form_label_content') -}}
273273
{%- endif -%}
@@ -284,7 +284,7 @@
284284
{%- endif -%}
285285
{%- set widget_attr = {} -%}
286286
{%- if help -%}
287-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
287+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
288288
{%- endif -%}
289289
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
290290
{{- form_label(form) -}}
@@ -312,7 +312,7 @@
312312
{% block form_help -%}
313313
{%- if help -%}
314314
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-muted')|trim}) -%}
315-
<small id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
315+
<small id="{{ id }}_help"{% with {attr: help_attr} %}{{ block('attributes') }}{% endwith %}>
316316
{{- block('form_help_content') -}}
317317
</small>
318318
{%- endif -%}

Resources/views/Form/bootstrap_5_horizontal_layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_5_layout.html.twig" %}
1+
{% use 'bootstrap_5_layout.html.twig' %}
22

33
{# Labels #}
44

@@ -29,7 +29,7 @@
2929
{%- else -%}
3030
{%- set widget_attr = {} -%}
3131
{%- if help -%}
32-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
32+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
3333
{%- endif -%}
3434
{%- set row_class = row_class|default(row_attr.class|default('mb-3')) -%}
3535
{%- set is_form_floating = is_form_floating|default('form-floating' in row_class) -%}
@@ -73,7 +73,7 @@
7373
{% block fieldset_form_row -%}
7474
{%- set widget_attr = {} -%}
7575
{%- if help -%}
76-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
76+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
7777
{%- endif -%}
7878
<fieldset{% with {attr: row_attr|merge({class: row_attr.class|default('mb-3')|trim})} %}{{ block('attributes') }}{% endwith %}>
7979
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">

Resources/views/Form/bootstrap_5_layout.html.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "bootstrap_base_layout.html.twig" %}
1+
{% use 'bootstrap_base_layout.html.twig' %}
22

33
{# Widgets #}
44

@@ -99,9 +99,9 @@
9999
{% set valid = true %}
100100
{% endif %}
101101
<div {{ block('widget_container_attributes') }}>
102-
{{- form_widget(form.date, { datetime: true } ) -}}
102+
{{- form_widget(form.date, {datetime: true}) -}}
103103
{{- form_errors(form.date) -}}
104-
{{- form_widget(form.time, { datetime: true } ) -}}
104+
{{- form_widget(form.time, {datetime: true}) -}}
105105
{{- form_errors(form.time) -}}
106106
</div>
107107
{%- endif -%}
@@ -226,7 +226,7 @@
226226
{%- if row_class is not empty -%}
227227
<div class="{{ row_class }}">
228228
{%- endif -%}
229-
{{- form_label(form, null, { widget: parent() }) -}}
229+
{{- form_label(form, null, {widget: parent()}) -}}
230230
{%- if row_class is not empty -%}
231231
</div>
232232
{%- endif -%}
@@ -247,7 +247,7 @@
247247
{%- if row_class is not empty -%}
248248
<div class="{{ row_class }}">
249249
{%- endif -%}
250-
{{- form_label(form, null, { widget: parent() }) -}}
250+
{{- form_label(form, null, {widget: parent()}) -}}
251251
{%- if row_class is not empty -%}
252252
</div>
253253
{%- endif -%}
@@ -278,13 +278,13 @@
278278
{%- if compound is defined and compound -%}
279279
{%- set element = 'legend' -%}
280280
{%- if 'col-form-label' not in parent_label_class -%}
281-
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label' )|trim}) -%}
281+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
282282
{%- endif -%}
283283
{%- else -%}
284284
{%- set row_class = row_class|default(row_attr.class|default('')) -%}
285285
{%- set label_attr = label_attr|merge({for: id}) -%}
286286
{%- if 'col-form-label' not in parent_label_class -%}
287-
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ('input-group' in row_class ? ' input-group-text' : ' form-label') )|trim}) -%}
287+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ('input-group' in row_class ? ' input-group-text' : ' form-label'))|trim}) -%}
288288
{%- endif -%}
289289
{%- endif -%}
290290
{%- endif -%}
@@ -300,7 +300,7 @@
300300
{%- endif -%}
301301
{%- set label_attr = label_attr|merge({class: label_attr_class|trim}) -%}
302302
{%- if not compound -%}
303-
{% set label_attr = label_attr|merge({'for': id}) %}
303+
{% set label_attr = label_attr|merge({for: id}) %}
304304
{%- endif -%}
305305
{%- if required -%}
306306
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
@@ -310,7 +310,7 @@
310310
{%- endif -%}
311311

312312
{{ widget|raw }}
313-
<label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
313+
<label{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}>
314314
{%- if label is not same as(false) -%}
315315
{{- block('form_label_content') -}}
316316
{%- endif -%}
@@ -326,7 +326,7 @@
326326
{%- endif -%}
327327
{%- set widget_attr = {} -%}
328328
{%- if help -%}
329-
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
329+
{%- set widget_attr = {attr: {'aria-describedby': id ~ '_help'}} -%}
330330
{%- endif -%}
331331
{%- set row_class = row_class|default(row_attr.class|default('mb-3')|trim) -%}
332332
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: row_class})} %}{{ block('attributes') }}{% endwith %}>

Resources/views/Form/bootstrap_base_layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% use "form_div_layout.html.twig" %}
1+
{% use 'form_div_layout.html.twig' %}
22

33
{# Widgets #}
44

@@ -54,8 +54,8 @@
5454
{%- if form.time.second is defined %}{{ form_label(form.time.second) }}{% endif -%}
5555
</div>
5656

57-
{{- form_widget(form.date, { datetime: true } ) -}}
58-
{{- form_widget(form.time, { datetime: true } ) -}}
57+
{{- form_widget(form.date, {datetime: true}) -}}
58+
{{- form_widget(form.time, {datetime: true}) -}}
5959
</div>
6060
{%- endif -%}
6161
{%- endblock datetime_widget %}

0 commit comments

Comments
 (0)