eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

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

Open ylc395 opened this issue 1 year ago • 2 comments

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 avatar Sep 03 '24 07:09 ylc395

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

ylc395 avatar Sep 03 '24 10:09 ylc395

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!

FloEdelmann avatar Sep 03 '24 14:09 FloEdelmann