Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Sep 12, 2024

Conversation

marcjfj-vmlyr
Copy link
Contributor

@marcjfj-vmlyr marcjfj-vmlyr commented Jul 21, 2024

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
Copy link
Member

kazupon commented Jul 21, 2024

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

@marcjfj-vmlyr
Copy link
Contributor Author

marcjfj-vmlyr commented Jul 21, 2024

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 #1675.

@nirinsanity
Copy link

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

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice, thank you!

I have a few small suggestions.

lib/rules/no-undef-properties.js Outdated Show resolved Hide resolved
lib/rules/no-undef-properties.js Outdated Show resolved Hide resolved
@marcjfj-vmlyr
Copy link
Contributor Author

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

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have one more change request, then it's good to go from my side 🙂

tests/lib/rules/no-undef-properties.js Show resolved Hide resolved
@marcjfj-vmlyr
Copy link
Contributor Author

Invalid test cases have been added.

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One more minor thing I just noticed.

tests/lib/rules/no-undef-properties.js Outdated Show resolved Hide resolved
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now 🙂

@horosin
Copy link

horosin commented Sep 11, 2024

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

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi ota-meshi merged commit 8b877f7 into vuejs:master Sep 12, 2024
10 checks passed
@tmcdos
Copy link

tmcdos commented Nov 6, 2024

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
Copy link
Member

FloEdelmann commented Nov 6, 2024

Please open a new issue following the bug template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants