Skip to content

vue/attributes-order: Prioritize v-if/v-else/v-else-if to v-for in SFC templates in Vue 3 #1952

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

Closed
kleinfreund opened this issue Aug 28, 2022 · 5 comments

Comments

@kleinfreund
Copy link

What rule do you want to change?

Prioritize conditionals (e.g. v-if, v-else, etc.) to v-for in the vue/attributes-order rule because conditionals are now prioritized to v-for in Vue 3 (see Vue 3 Migration Guide: v-if vs. v-for Precedence).

Does this change cause the rule to produce more or fewer warnings?

More for users that use the vue/attributes-order already. For other scenarios, this change shouldn’t produce much more or fewer warnings overall.

How will the change be implemented? (New option, new default behavior, etc.)?

New default behavior (switch precedence of LIST_RENDERING and CONDITIONALS).

Please provide some example code that this change will affect:

<span v-if="condition" />

<span
  v-for="item in items"
  :key="item"
  v-else
/>

What does the rule currently do for this code?

<span v-if="condition" />

<span
  v-for="item in items"
  v-else
  :key="item"
/>

What will the rule do after it's changed?

<span v-if="condition" />

<span
  v-else
  v-for="item in items"
  :key="item"
/>

Additional context

Besides of this being in line with how this code will be treated by Vue 3, I also think it’s preferable that v-for and key would be grouped together now because they belong together semantically.

@haoqunjiang
Copy link
Member

But there’s this essential rule already: https://eslint.vuejs.org/rules/no-use-v-if-with-v-for.html

@haoqunjiang
Copy link
Member

🤔 but that rule didn’t check v-else, maybe we need to check for it too. Because I don’t think v-else v-for on the same node should be encouraged.

@kleinfreund
Copy link
Author

Perhaps not. There are indeed scenarios in which this is ambiguous, but I think regardless of the existence of vue/no-use-v-if-with-v-for, the precedence should be changed in vue/attributes/order.

@FloEdelmann
Copy link
Member

that rule didn’t check v-else, maybe we need to check for it too

@sodatea see #1939

@kleinfreund
Copy link
Author

I don't think this proposal is relevant enough to keep open so I'm closing this for now.

@kleinfreund kleinfreund closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants