You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please describe what the rule should do:
Discourage using a dynamic component when you can use a v-if/v-else for better readability & type hints.
When reading <component :is="componentType"> it doesn't give a lot of information to the reader (or static analyzer) so it feels like the component can be anything and increase mental burden when trying to understand what a component does.
If componentType is actually a toggle between 2, 3 components, I think a v-if/v-else would be preferable as it makes it clear what elements/components are used in the file.
What category should the rule belong to?
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Composition API with inline computed:
<scriptsetup>constprops=defineProps({ isButton:Boolean,});</script>
<template>
<component :is="isButton ?'button':'a'">
Text
</component>
</template>
Another example of code that can be prevented by this rule.
Obviously, the imported component shouldn't be anything particular like an icon... On the other hand, it might be a good idea to actually allow (or even enforce) such a technique if an imported component's path matches some regex like \.svg$ (should be configurable) because <my-icon></my-icon> is quite verbose and doesn't accept any props anyway.
Please describe what the rule should do:
Discourage using a dynamic component when you can use a
v-if
/v-else
for better readability & type hints.When reading
<component :is="componentType">
it doesn't give a lot of information to the reader (or static analyzer) so it feels like the component can be anything and increase mental burden when trying to understand what a component does.If
componentType
is actually a toggle between 2, 3 components, I think av-if
/v-else
would be preferable as it makes it clear what elements/components are used in the file.What category should the rule belong to?
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Composition API with inline computed:
Options API with computed property:
Additional context
The text was updated successfully, but these errors were encountered: