Eslint-plugin-vue: vue/order-in-components doesn't fix warnings

Created on 14 Dec 2018  Â·  8Comments  Â·  Source: vuejs/eslint-plugin-vue

105:5  warning  The "computed" property should be above the "created" property on line 73  vue/order-in-components

Expected: vue/order-in-components is supposed to be fixable
(https://github.com/vuejs/eslint-plugin-vue/issues/299)
Current: not fixable

eslint-plugin-vue v5.0.0
node v9.11.1

Thanks!

Most helpful comment

@jean-moldovan we are not auto sorting it because of spread operator. live demo

All 8 comments

Hi @jean-moldovan This rule is fixable actually, but not in all cases. We explicitly disable auto-fix, when we detect that some of the nodes might contain side-effects. We want you to be safe and not break your app in hard to debug way - so we suggest you to consciously fix order by yourself.

Thanks, @michalsnik. Mind sharing an example of a possible side-effect when "computed" goes above "created"?

Thanks again!

My example:

<template>
  <div />
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    mounted () {
      console.info(this.welcomeMsg, this.versionMsg)
    },
    computed: {
      ...mapGetters(['companyName', 'version']),

      welcomeMsg () {
        return `Welcome to ${this.companyName}! `
      },
      versionMsg () {
        return `v${this.version}`
      }
    }
  }
</script>

<style scoped>

</style>

The "computed" property should be above the "mounted" property on line 9

What is the algorithm for the side-effect detection here, @michalsnik ?

Thanks!

@jean-moldovan we are not auto sorting it because of spread operator. live demo

Hi
Why this issue is closed ?

We explicitly disable auto-fix, when we detect that some of the nodes might contain side-effects.

Can you explain more ? update doc ? or fix side effects ?

@jean-moldovan we are not auto sorting it because of spread operator. live demo

What is the side effect caused by the spread operator? Sorry if this is a newbie question 😅

I for 1 would really find this feature useful.

I extracted my javascript code to a .js file visual studio code fixes the code aplying the recommended rules, I just had to wrap my component with Vue.extend(

export default Vue.extend({
  name: "PageIndex",
  mixins: [ClienteHttp],
...
});

I know it's not a real fix, but... it's something! ¯\_(ツ)_/¯

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodrigoabb picture rodrigoabb  Â·  3Comments

Hyzual picture Hyzual  Â·  3Comments

xiGUAwanOU picture xiGUAwanOU  Â·  3Comments

soullivaneuh picture soullivaneuh  Â·  3Comments

apertureless picture apertureless  Â·  4Comments