Skip to content

Rule enhancement: vue/attributes-order #968

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
1 of 4 tasks
sense-it-gmbh opened this issue Sep 30, 2019 · 6 comments · Fixed by #1022
Closed
1 of 4 tasks

Rule enhancement: vue/attributes-order #968

sense-it-gmbh opened this issue Sep 30, 2019 · 6 comments · Fixed by #1022

Comments

@sense-it-gmbh
Copy link

Please describe what the rule should do:

Enforce alphabetic order within attributes of same block (eg DEFINITION, LIST_RENDERING, see rule details). This concerns mainly the custom attributes and directives, events and global attributes (OTHER_DIRECTIVES, OTHER_ATTR, GLOBAL, EVENTS).

This could be an optional rule-option.

What category should the rule belong to?

  • 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 should warn about:

<!-- ✓ GOOD -->
<my-component
  a-custom-prop="value"
  :another-custom-prop="1 + 1"
  :blue-color="false"
  boolean-prop-again
  z-prop="Z"
  @change="someMethod"
  @input="someOtherMethod"
>
  <!-- content -->
</my-component>

<!-- ✗ BAD -->
<my-component
  z-prop="Z"
  :another-custom-prop="1 + 1"
  :blue-color="false"
  boolean-prop-again
  a-custom-prop="value"
  @input="someOtherMethod"
  @change="someMethod"
>
  <!-- content -->
</my-component>

Additional context

@erindepew
Copy link
Contributor

If no one has picked this up yet I can grab it, it's an enhancement to the rule I added a while back here anyway #209

@erindepew
Copy link
Contributor

erindepew commented Dec 28, 2019

It's been a while since I've contributed 😄 so I'm sure I missed a step or two in there, but the code works.
Also I know the example above had it sorting on the function name, but for the actual attribute sorting it goes off of the key name. For consistency sake it would make more sense to keep it just to the key names and not the values. e.g.

  z-prop="Z"
  :another-custom-prop="1 + 1"
  :blue-color="false"
  boolean-prop-again
  a-custom-prop="value"
  @input="someOtherMethod"
  @change="someMethod"
>

would be incorrect because @change should come before @input

@sense-it-gmbh
Copy link
Author

Also I know the example above had it sorting on the function name

Hm, as far as I remember I intended to sort first by type (event, prop, directive, condition) and second by key-name (without :). I never intended to sort by value which would not make sense at all on dynamic values like user input.

Did I get something wrong or did you @erindepew ?

@erindepew
Copy link
Contributor

🤔I think we agree on this @sense-it-gmbh and maybe I was just confused by the initial example. Mind taking a look at the tests I wrote for this and see if it all works the way you were expecting?

@sense-it-gmbh
Copy link
Author

🤔I think we agree on this @sense-it-gmbh and maybe I was just confused by the initial example. Mind taking a look at the tests I wrote for this and see if it all works the way you were expecting?

I tried but I'm afraid I don't know enough about how these work so I cant really tell whether they are as expected.

@erindepew
Copy link
Contributor

So you can review either the documentation I added:
https://github.com/vuejs/eslint-plugin-vue/pull/1022/files#diff-042799d8ab84dca42fc7dd1aa33dbb03R114
Or the tests https://github.com/vuejs/eslint-plugin-vue/pull/1022/files#diff-b1c806eb1ceb57105d9b7236f347d207R296

But it's fine, your example works and this will give you the output you're expecting. I just misspoke above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants