-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Rule Idea: Using named argument for include with_context or boolean twig extension calls #295
Comments
Hi, First, I'm not sure about having such rule here since it may be consider too much opinionated.
Second, I'm not sure about how easy a fixer would be.
Maybe you could be interested in a custom Node-based rule like Since it play with Node rather than Token, you can easily access to function arguments, and you'll be able to write a rule:
The only drawback is the fact that Node-based rule are not fixable (so far). |
@VincentLanglet the basic idea what was in my mind case is if not on a specific argument instead a specific scalar types. If a given value to a twig extension call is a -{{ someExtension(someOtherExtension(true), {}, true) }}
+{{ someExtension(someOtherExtension(name_2: true), {}, name_2: true) }} cases like following would stay untouched as then already a meaning was give to the value via a param name: -{{ someExtension(someOtherExtension(otherArgument), {}, withContext) }}
+{{ someExtension(someOtherExtension(otherArgument), {}, withContext) }} But I understand your decision if its to complex to keep it out of core.
Current case I want to avoid adding non fixable validators to the twig lint task, but yeah would be another option which I keep in my backmind. |
I think this have to be on specific argument since I cannot guess the name of the argument.
and list all the wanted methods.
I'll let the issue open to get feedback/suggestions, ... but yeah I think it might be better out of core.
I understand. If you want to make the rule fixable it would require
It may be possible with TokenBasedRule with the logic:
|
Thank you for your detailed feedback. Let see if I'm the only one which searching for such rule. Are there some instruction docs about how to create custom Node or Token based rules? |
ATM no, you have to get inspired by existing rules. But it's on my todo to improve the doc. Any feedback/PR is welcomed. |
I'm working on documentation (still wip) about writing such rules https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/custom.md any feedback is welcome @alexander-schranz |
BTW @alexander-schranz #302 introduce a new NAMED_ARGUMENT_SEPARATOR_TYPE token which could help to write your rule. Anyway, I consider this rool won't be implemented in this library so I'll close. |
Rule(s) related to or rule(s) missing
Rule Idea.
Expected behavior
I'm using
with_context = false
a lot in my twig files. While updating twig cs fixer to the latest version I stumble over that existing{% include %}
where migrated and just use, false
for it. For more transparent I prefer to use named argument for thewith_context
parameter:So I thought maybe it would be nice to have a rule for the with_context or even for all boolean based twig extensin calls.
Actual behavior
No rule yet:
The text was updated successfully, but these errors were encountered: