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 1 commit into
base: 7.4
Choose a base branch
from
Open

Conversation

94noni
Copy link
Contributor

@94noni 94noni commented Jun 11, 2025

Q A
Branch? 7.4
Bug fix? no (improve Twig file coding standard consistency)
New feature? no
Deprecations? no
Issues Fix #54799
License MIT

This PR adds config file for the tool twig-cs-fixer (via)

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:

TODOs:

  • decide if its wanted/needed or not
  • act default rule set for this PR
  • define CI

Friendly ping @VincentLanglet @smnandre as issue commenters

Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

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

this should have a GitHub Actions workflow running the tool in CI, otherwise it won't be enforced.

regarding your summary in the description, this is not a new feature. It is about tooling for contributors and CI, but it does not bring any new feature in Symfony (and does not require a mention in changelog either, as users of Symfony won't care)

@94noni
Copy link
Contributor Author

94noni commented Jun 11, 2025

this should have a GitHub Actions workflow running the tool in CI, otherwise it won't be enforced.

totally agree,
the main idea here is really to see how it behaves on the codebase as per issue comment

and does not require a mention in changelog either

top make sens, lets not add it and update the desc

<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group')|trim})} %}{{ block('attributes') }}{% endwith %}>{#- -#}
<div class="{{ block('form_label_class') }}"></div>{#- -#}
Copy link
Member

Choose a reason for hiding this comment

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

@VincentLanglet I think even your opinionated standard should allow the short whitespace-control command {#--#} without requiring a space.
Requiring a space around the comment text is good (and is part of the official Twig coding standards), but is not worth it if there is no text IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it's better.

For this rule I blindly follow the twig coding standard coming from https://twig.symfony.com/doc/3.x/coding_standards.html#coding-standards

Put exactly one space after the start of a delimiter ({{, {%, and {#) and before the end of a delimiter (}}, %}, and #}):
When using the whitespace control character, do not put any spaces between it and the delimiter:

So, what might be great would be to update this page and then to update the rule on my side.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened the PR on the standard here twigphp/Twig#4649

@94noni
Copy link
Contributor Author

94noni commented Jun 12, 2025

i do think I've addressed the comments (standard to chose, exclude fixtures, and composer min)

for the adding ci, I am not so aware of best practice of it (when no vendor lock) so please review appreciated
(inspired by the psalm one and some reading)

@94noni 94noni force-pushed the dev-twig-cs branch 3 times, most recently from e2f08ac to f03c7a8 Compare June 12, 2025 07:37
@94noni 94noni changed the title chore(twig): leveragetwig-cs-fixer chore(twig): leverage twig-cs-fixer Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] include a new dev config file for twig-cs-fixer in the codebase
4 participants