Closed michalsnik closed 7 years ago
I personally prefer having all assets at top of the component (like dependencies), and then group all state-related options (props, data, computed), hence:
Alright @yyx990803, it makes sense 👍 We can make this order the default one, but we'll also make it possible for devs to change the order in .eslintrc
so our recomendation is not the only right choice.
I started to work on this, and there are far more properties that we should take into consideration. Order I came up with is as follows:
name
, delimiters
, functional
, model
)el
components
, directives
, filters
)parent
, mixins
, extends
, provide
, inject
)props
propsData
data
computed
methods
watch
template
render
renderError
What is in braces should be treated equally in terms of order, the rest should be in the exact order.
I kept grouping of some properties (misc
, assets
and composition
) in tact with official documentation, but had to tear DOM
properties. I'd like to know your thought on this guys. I'll start implementing it and if we came up with different order we'll simply change the default configuration. If there are any other properties that I should take into consideration let me know!
cc @yyx990803 @chrisvfritz
Another thing is what kind components definitions are we going to support. My first thoughts are:
export.default {}
in *.vue
fileVue.component('xxx', {})
in any fileBut sometimes we also assign simple objects directly to a variable and this is our component, but this way we have no chance to recognise if it is actually a vue
component, so I think we should rather focus only on those two scenarios I mentioned above. I just want to make sure.
// Update
I found another one: async component, but it might be harder to detect because of different ways of declaring component's body in this case. It certainly would not be enough to find resolve
in async component's function..
Looks good - tweaked a bit more:
The main thing is I moved template
up alongside el
, and moved methods
to be after lifecycle hooks.
It's interesting because putting render
last is kind of a convention from React land, but I'm much more used to seeing templates earlier to get a visual understanding of a component.
Just wanted to weigh in that we've created a similar plugin to tackle the same issue. It's in use in our agency so it's sort of battle tested. Maybe this helps you solve this task faster 🙂
Thanks @Nirazul , I did similar rule in eslint-plugin-ember
already so it won't be a problem :) I just need to get my head around it, probably tomorrow :)
Released as v3.2.0
. Rule is disabled by default, that's why it's a minor release. We'll change it to be enabled by default while finishing beta period.
As I mentioned in #10, I think that creating separate issue for each rule proposition has many benefits, so this is my first proposition:
Rule name:
order-in-components
Description: Keep order of properties in components according to https://docs.gitlab.com/ce/development/fe_guide/style_guide_js.html#orderingGitlab's style guide lists all properties, I would however consider grouping lifecycle hooks in order to make it simpler, like so:
Introducing order rule we can make sure that every component is written in exactly the same way, which would make it more readable and consistent across codebase.
This rule should be configurable, so that anyone can amend proposed order in
.eslintrc
.