vuejs / eslint-plugin-vue

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

Feature Request: floating call expressions in `vue/no-side-effects-in-computed-properties` #2542

Open ylc395 opened 2 months ago

ylc395 commented 2 months ago

What rule do you want to change? vue/no-side-effects-in-computed-properties

Does this change cause the rule to produce more or fewer warnings? More warnings

How will the change be implemented? (New option, new default behavior, etc.)? Add a option to this rule, for example: { noFloatingCall: true }

Please provide some example code that this change will affect: Examples from here: https://github.com/vuejs/eslint-plugin-vue/issues/97

export default {
  computed: {
    foo () {
      this.$store.commit({}) // Mutations
      this.$store.dispatch('', {}) // Actions
      return true
    },
    bar () {
      this.$router.go(-1)
      this.$router.push({})
      this.$router.replace({})
      return true
    }
  }
}

and composition-api:

const foo = computed(() => {
  callSomething();
});

What does the rule currently do for this code? Do nothing.

What will the rule do after it's changed? Report a side-effect-in-computed warning.

Additional context https://github.com/vuejs/eslint-plugin-vue/issues/58#issuecomment-311921206 https://github.com/vuejs/eslint-plugin-vue/issues/97

ylc395 commented 2 months ago

I can commit a PR if this feature request is acceptable.

FloEdelmann commented 2 months ago

I actually don't think that an option is required; this should be the rule's default behavior.

All call expressions that are not used in return statements, variable assignments or function parameters are probably side effects and thus should be reported. PR is welcome for that!