Open FloEdelmann opened 3 years ago
Thank you for suggesting this option. I find it difficult to check the type.
Also, I don't think contextual
can consider formats like i in 10
.
I prefer the object format option so that it can be set flexibly according to the user's preference.
e.g. { object: 'in', array: 'of', number: 'in', string: 'of', iterable: 'of' }
What rule do you want to change?
v-for-delimiter-style
Does this change cause the rule to produce more or fewer warnings? Without a configuration change, the number won't change.
How will the change be implemented? (New option, new default behavior, etc.)? New option
contextual
(instead ofin
orof
).Please provide some example code that this change will affect:
What does the rule currently do for this code? Either
in
orof
are required everywhere.What will the rule do after it's changed? With the
contextual
option, this rule requires usingin
when looping through object entries, andof
for arrays. When the loop variable type can't be determined, the rule should not enforce eitherin
orof
with thecontextual
style.When using this
contextual
style, just glancing over the template is enough to know the loop variable type (array or object), because it mimics a native JavaScriptfor … in
orfor … of
loop.Additional context I've created a diff file that updates the rule documentation and tests:
Diff
````diff diff --git a/docs/rules/v-for-delimiter-style.md b/docs/rules/v-for-delimiter-style.md index 7239ef0..486de70 100644 --- a/docs/rules/v-for-delimiter-style.md +++ b/docs/rules/v-for-delimiter-style.md @@ -34,12 +34,13 @@ Default is set to `in`. ```json { - "vue/v-for-delimiter-style": ["error", "in" | "of"] + "vue/v-for-delimiter-style": ["error", "in" | "of" | "contextual"] } ``` - `"in"` (default) ... requires using `in`. - `"of"` ... requires using `of`. +- `"contextual"` ... requires using `in` when looping through object entries, and `of` for arrays. ### `"of"` @@ -55,6 +56,31 @@ Default is set to `in`. ``` +### `"contextual"` + +v-for-delimiter-contextual.diff.txt
Unfortunately, the type of the loop variable can't be easily determined, so implementing the actual code is too involved for me.