-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
base: 2.x
Are you sure you want to change the base?
Conversation
I'm not sure about a So I would say:
But the goal would be to have Symfony members adding rules directly in the Symfony standard :) |
->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()) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
->addRule(new BlankEOFRule()) | ||
->addRule(new BlockNameSpacingRule()) | ||
->addRule(new EmptyLinesRule()) | ||
->addRule(new IncludeFunctionRule()) | ||
->addRule(new SingleQuoteRule()) | ||
->addRule(new TrailingSpaceRule()) | ||
->addRule(new TrailingCommaSingleLineRule()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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, '_')) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 😊
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 %}
(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) ?