-
-
Notifications
You must be signed in to change notification settings - Fork 681
Rule proposal: simple-expressions-in-templates
#253
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
Comments
I like the node type strategy better, as I definitely like long (especially computed) property names. 😄 |
How does this rule handle filters? |
I think we can ignore filters (not mark them as a complex node type). |
@chrisvfritz i agree with you, but there has to be some additional conditions
<div v-for="todos of todosGroups">
{{ todos.map(todo => todo.name )}}
</div> example is simple but i have few use cases for that 😄
<p>{{ $t('message.hello', {'0': 'hello'}) }}</p> https://kazupon.github.io/vue-i18n/guide/formatting.html#list-formatting unless we up default limit to 2-3 and let users decide how many its allowed {
"vue/simple-expressions-in-templates": ["error", {
"allowedCallExpression": "off" | number,
"allowedFunctionExpression": "off" | number,
}]
} we can always go for list of excluded |
Maybe we should define complexity as logical branches or state changes? So loops, conditionals, and any other time a variable/argument can have different values could be considered complex. @armano2 In your map example, I would say that's a good opportunity for a method other utility. 🙂 It's easy for that simple map to become more and more complex with time, possibly also adding a filter and other transforms eventually. |
We're very interrested in this rule being added and are open to implementing it. Perhaps adding a |
Style guide:
https://vuejs.org/v2/style-guide/#Simple-expressions-in-templates-strongly-recommended
Description:
This rule would enforce usage of simple expressions in templates. Instead of writing complex logic in templates it should be moved to computed properties and only referenced using them in templates.
What should we check?
{{}}
)v-bind:foo=""
and:foo=""
)When should we throw a warning?
Simplest solution would be to define number of letters inside expressions, and to be honest I think it should work well for most cases.
Let's say we throw error when there are at least 20 signs in expressions:
The bad example has 26 non-empty signs. It's clear that it would be too hard to fit any logic in 20 signs, so we could be quite certain this is a good and not overcomplicated solution.
On the other hand I can think of longer than 20 signs words, e.g.:
allNotCompletedTodosNames
So the other way would be to check for existence of one of the following types of nodes inside expressions:
The text was updated successfully, but these errors were encountered: