Replace require-v-for-key with new rule just for stateful elements
See original GitHub issueThe Problem
A lot of users get upset when the linter yells at them for not providing a key when it doesn’t create a real problem and Vue itself doesn’t complain. The real intent with this rule is to maintain object constancy to avoid:
- Losing state in non-functional components (e.g.
dataproperties being reset, lifecycle methods being re-run unnecessarily) - Losing state in stateful non-component elements such as
input,select, etc (e.g.valuebeing lost if not passed as a prop) - Visual inconsistencies on elements wrapped by
<transition>or<transition-group>elements.
Potential Solution
To make everyone happy, I’m wondering if we may want to rename require-v-for-key to something like require-v-for-key-stateful-elements, then change its behavior so that it only gives a warning on:
- Components
- Stateful non-component elements
- Non-stateful elements that use
v-html - Non-stateful elements that contain any of the above
- Non-stateful elements whose parent element is
<transition>or<transition-group>.
Thoughts?
I’d like to get some other people weighing in on this before making the change, as there may be other cases I’m not considering.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:5 (3 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m adding some specific messages and examples for each case here, to make building the rule easier.
Missing
keywithv-foron componentMessage
Examples
Missing
keywithv-foron stateful elementMessage
Examples
Missing
keywithv-foron element usingv-htmlMessage
Examples
Missing
keywithv-foron element with stateful contentMessage
Examples
Non-unique
keywithv-forMessage
Examples
Notes
This would require us to be able to access the names of any properties (e.g.
nin the examples above) and ensure that it is used within the value of thekey, if thekeyif usingv-bind.Missing
keywithv-foron transitioned elementMessage
Examples
Notes
This one isn’t really related to
v-forspecifically, as it also applies to elements withv-if/v-else-if/v-elsethat share a tag name. So maybe it should be in a separate rule?@michalsnik @chrisvfritz Ping?