-
-
Notifications
You must be signed in to change notification settings - Fork 681
Rule Proposal: Prevent accessing props directly in the template #2095
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 think it would make more sense to add a rule similar to core ESLint's Possible name for that rule: |
@FloEdelmann Oh, that sounds even better. I was thinking about this in a different perspective so |
Would you open a new issue for |
Note also the similar rule: https://eslint.vuejs.org/rules/no-template-shadow.html |
Closing in favor of #2096 |
Is there a rule or vue config enforce the use of props const in the template? Think enforcing the user to use the props constant in templates is a less magic way of doing things. ie: <script setup lang="ts">
const props = defineProps<{
msg: string;
}>()
</script>
<template>
<div>{{ props.msg }}</div> <!-- this will work -->
<div>{{ msg }}</div> <!-- this will fail -->
</template> |
No, there is none. Please open a new issue for this request and link to this issue here for reference. |
Please describe what the rule should do:
When using
<script setup>
, local variables declared with the same name as the props takes precedence over the props. To avoid potential issues where a locally declared variable has different values or type than the props, I think it would be nice to have a rule to enforce accessing props from a variable.For instance, enforce accessing props from
const props = defineProps(...)
, so in the template it will be{{ props.propsValue }}
.What category should the rule belong to?
[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
WARN
WARN
OK
Additional context
I understand that there are cases where a component's
<script setup>
is basically callingdefineProps
with no local variable declaration, so maybe we should be able to allow that? But I'm not sure if it's feasible.(Possibly) Related Issues
The text was updated successfully, but these errors were encountered: