vuejs / eslint-plugin-vue

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

Vuex and Pinia support for `no-undef-properties` #2513

Closed marcjfj-vmlyr closed 2 months ago

marcjfj-vmlyr commented 4 months ago

This PR adds support for Vuex and Pinia methods to the no-undef-properties rule, allowing properties defined by mapState, mapActions, mapGetters, mapMutations, and mapWritableState to be recognized as defined properties.

Test cases have been included for this enhancement.

kazupon commented 4 months ago

I think this rule should be supported by pinia or 3rd party plugin. You can discuss in the issue https://github.com/vuejs/pinia/issues/2612

marcjfj-vmlyr commented 4 months ago

I think this rule should be supported by pinia or 3rd party plugin. You can discuss in the issue vuejs/pinia#2612

Sure but it looks like the maintainers are welcoming these kinds of enhancements, as a similar fix was added for vue/no-unused-properties. See discussion here https://github.com/vuejs/eslint-plugin-vue/issues/1675.

nirinsanity commented 3 months ago

This is much required. Thanks to @marcjfj-vmlyr for working on this. Please merge as soon as possible.

marcjfj-vmlyr commented 2 months ago

@FloEdelmann Thanks for reviewing! I've made the requested changes.

marcjfj-vmlyr commented 2 months ago

Invalid test cases have been added.

horosin commented 2 months ago

this looks great, can't wait for it to ship!

tmcdos commented 2 weeks ago

There is a problem with this fix - it works only if mapGetters or mapState or mapMutations appears in the source code BEFORE the actual reference to the property or method. For example, in the following code no linting error will be emitted

  created()
  {
    if (this.getCountries.length === 0) this.fetchCountries();
  },
methods:
{
        ...mapMutations(['setCountries']),
      fetchCountries()
      {
          // ... fetching from server
          this.setCountries(data);
      }
}

However, in the following code a linting error setCountries is not defined vue/no-undef-properties will be emitted

  created()
  {
    if (this.getCountries.length === 0)
    {
          // ... fetching from server
          this.setCountries(data); // <==== linting error - but it should not be
    }
  },
methods:
{
        ...mapMutations(['setCountries']),
}
FloEdelmann commented 2 weeks ago

Please open a new issue following the bug template.