-
-
Notifications
You must be signed in to change notification settings - Fork 681
Rule Proposal vue/attribute-order
#170
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'd be open to a better name for this rule 😄 |
I wonder if more fine-grained control could be added to the config. I'm thinking something similar to to the config options for eslint-plugin-import's order rule. |
I very much like this idea, plus it have already been mentioned in #77 |
https://vuejs.org/v2/style-guide/#Element-attribute-order-recommended is the best point of reference how the config should look like :) |
@michalsnik @mikegreiling I just opened a PR for this rule #209 is this what you had in mind? |
Hi @michalsnik @mikegreiling, thanks for all the hard work that's already gone into this plugin. I've been working to add configuration to this rule with @erindepew. Before moving forward, we just want to ensure that we're not doing duplicate work and that we're moving in the right direction.
Let me know if it seems like we're moving in the right direction. |
That sounds good to me 👍 |
Yeah @matt-oconnell @erindepew, you seem to go in the right direction, just to sum up:
Example config could look like:
But I also started to wonder if it wouldn't be even better to be more explicit and give users the ability to amend the order of groups as well using 2d arrays:
We could even combine those two ideas, and initially transform settings with group names to be replaced by the explicit arrays of attributes, and then perform all checks on it. It would be possible to easily override order in specific groups instead of the whole configuration. What do you think? |
As a starting place, seems like having the current groupings specified by the style guide could be a good place to start. Adding the ability to create custom groupings would be a non-breaking change and could easily be added in the future, and could make it easier to land this and get the rule out in the wild sooner. My biggest concern with this rule is the error messaging and having to keep track of such a long list of arbitrarily ordered groupings. Autofixing is great, but I think the warning message should be useful in its own right, since not everyone autofixes when writing a file (I know I don't!). As an example, what happens when someone turns this rule on for an existing codebase that doesn't follow the enforced order at all? Will it only report one attribute at a time, making the user fix each order change operation individually? I think that would be a frustrating experience for any elements that have a lot of attributes. As a proposed solution (and hopefully there's a better one), I wonder if we could notify the user of the overall grouping order in the error message? I'm envisioning something along the lines of an error message that says where the first offending node should be moved to and then Finally, if we do this, I think custom groups should also be named so that they can also be included in the error message: 'vue/attributes-order': [2, {
order: [
{
name: 'CUSTOM_CONDITIONALS',
group: ['v-show', 'v-cloak', 'v-if', 'v-else-if', 'v-else']
},
{
name: 'SOME_OTHER_CUSTOM_GROUP',
group: ['v-once', 'v-pre']
}
'OTHER_ATTRS'
],
}] It's a bit verbose, but the above configuration could then yield the following information in the error: |
Was #170 (comment) ever taken forward? Have just updated to 4.4.0 and am implementing this as a new rule we have, but have found it's not flexible enough. Was wondering if it's worth disabling this in the meantime if this was likely to be done? |
@robsterlini not that I know of, but I think that @kaicataldo proposed solution would certainly work and I'm happy to open up another PR with the enhancement. What do you think @michalsnik? |
No, it hasn't been taken forward yet. Feel free to submit PR with proposed changes - so we can challenge it :) Another idea for possible settings: 'vue/attributes-order': [2, {
groups: {
CUSTOM_CONDITIONALS: ['v-show', 'v-cloak', 'v-if', 'v-else-if', 'v-else'],
SOME_OTHER_GROUP: ['v-once', 'v-pre'],
},
order: [
'CUSTOM_CONDITIONALS',
'SOME_OTHER_GROUP',
'OTHER_ATTRS'
],
}] I think it would be even easier to set-up :) |
At the moment there is still no way to set the order of the attributes more accurately? For example : [class, v-for, v-if, etc.] |
Please describe what the rule should do:
Provide a template rule to enforce placing vue-specific attributes before other properties in a template tag.
What category of rule is this? (place an "X" next to just one item)
[X] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Configuration
'vue/closing-bracket-location': ['alphabetical' | 'vue-first']
Examples:
The text was updated successfully, but these errors were encountered: