Skip to content
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

[Site] Custom TwigCsFixer config #1948

Draft
wants to merge 6 commits into
base: 2.x
Choose a base branch
from

Conversation

smnandre
Copy link
Collaborator

(will be rebased after #1947)

Answering you here @VincentLanglet (regarding #1935 (comment))

Would this be the "good/safe" way to go... ?

...or should we create a Standard (and just customize the demo/memory thing here) ?

@VincentLanglet
Copy link

should we create a Standard

I'm not sure about a SymfonyUX standard. I tried recently to make the Symfony standard compatible with the ux components with those changes VincentLanglet/Twig-CS-Fixer@35a824e.

So I would say:

But the goal would be to have Symfony members adding rules directly in the Symfony standard :)

Comment on lines +18 to +26
->addStandard(new Twig())
// Symfony standard (customized for Symfony UX)
->addRule(new DirectoryNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components']))
->addRule(new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components'], optionalPrefix: '_'))
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))
->addRule(new FileExtensionRule())
Copy link

@VincentLanglet VincentLanglet Jun 30, 2024

Choose a reason for hiding this comment

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

You might prefer

->addStandard(new Symfony())
->overrideRule(new DirectoryNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components']))
->overrideRule(new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles', 'components', 'demos/live_memory/components'], optionalPrefix: '_'))
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'templates/components'))
->addRule(new DirectoryNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))
->addRule(new FileNameRule(case: DirectoryNameRule::PASCAL_CASE, baseDirectory: 'demos/live_memory/components'))

it includes the Symfony (in case some other rule are included), and avoid for instance to manually add FileExtensionRule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm feeling directory and filename always go by two.... or is it a specific case right there ?

Choose a reason for hiding this comment

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

I'm feeling directory and filename always go by two

Yes

Comment on lines +28 to +34
->addRule(new BlankEOFRule())
->addRule(new BlockNameSpacingRule())
->addRule(new EmptyLinesRule())
->addRule(new IncludeFunctionRule())
->addRule(new SingleQuoteRule())
->addRule(new TrailingSpaceRule())
->addRule(new TrailingCommaSingleLineRule())

Choose a reason for hiding this comment

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

Maybe some of these rules could be added to the Symfony standard but this need to be validated by a Symfony member.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is clearly out of the scope of this discussion 😅

Choose a reason for hiding this comment

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

Sure

->addRule(new SingleQuoteRule())
->addRule(new TrailingSpaceRule())
->addRule(new TrailingCommaSingleLineRule())
->overrideRule(new VariableNameRule(VariableNameRule::SNAKE_CASE, '_'))

Choose a reason for hiding this comment

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

Maybe this should be the "default" in the Twig Standard

The standard say Use lower cased and underscored variable names: cf https://twig.symfony.com/doc/3.x/coding_standards.html

Does allowing a _ prefix is "standard" for twig variable ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, to be honest, but it's a habit I've had for a long time 😊

Choose a reason for hiding this comment

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

I'm curious, when do you use _foo ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In a given template where you have "categories" (the list) and "category" (the current one) for instance

I often do stuff like that

{% for _category in categories %}

    <a href="#" class="{{ _category.id == category.id ? 'current' }}">{{ category.name }}</a>

{% endfor %}  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants