vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 665 forks source link

Rule improvement: `no-side-effects-in-computed-properties` #97

Closed michalsnik closed 6 years ago

michalsnik commented 7 years ago

As @armano2 pointed in #58 we should consider supporting few more cases in this rule:

1. Plugins provided by vuejs team, like:

Vue-router

export default {
  computed: {
    foo () {
      this.$router.go(-1)
      this.$router.push({})
      this.$router.replace({})
      return true
    }
  }
}

or Vuex

export default {
  computed: {
    foo () {
      this.$store.commit({}) // Mutations
      this.$store.dispatch('', {}) // Actions
      return true
    }
  }
}

2. Prototype methods

return Array.prototype.unshift.apply(this.object, data) // i know this is invalid
return Object.assign(this.object, data);

There are probably more cases. We should gather them all here in this topic, discuss and choose which one are we going to support. Supporting different cases is good, but too many edge cases - not necessarily. We need to be smart about this.

michalsnik commented 6 years ago

Not a priority now. Current solution seems to be good enough.

ylc395 commented 2 months ago

This issue should be re-opened. Would you accept a PR about this proposal ? @michalsnik

We can add a option to this rule, for example: {checkFloatingCall: true} to report errors of this kind.

FloEdelmann commented 2 months ago

Please open a new issue following the issue template and link to this issue from there, rather than commenting on an issue closed 7 years ago.