Open tmcdos opened 2 weeks ago
Additional context from https://github.com/vuejs/eslint-plugin-vue/pull/2513#issuecomment-2459347922:
There is a problem with this fix - it works only if
mapGetters
ormapState
ormapMutations
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 emittedcreated() { 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 emittedcreated() { if (this.getCountries.length === 0) { // ... fetching from server this.setCountries(data); // <==== linting error - but it should not be } }, methods: { ...mapMutations(['setCountries']), }
Another problem is that the fix for Vuex/Pinia in vue/no-undef-properties
rule only recognizes string literals - but ignores constants. So for example code like this will fail with a linting error:
import { mapGetters } from 'vuex';
const GET_SOMETHING = 'GET_SOMETHING';
export default
{
computed:
{
...mapGetters([GET_SOMETHING]),
},
methods:
{
someFunction()
{
if (this[GET_SOMETHING]) // <===== here will be a linting error "vue/no-undef-properties"
{
// .... some code
}
}
}
}
Checklist
Tell us about your environment
Please show your full configuration:
What did you do?
What did you expect to happen? I expect no linting error of type
vue/no-undef-properties
to be reported for lines 14:5 and 21:10What actually happened?
Repository to reproduce this issue
https://codesandbox.io/p/devbox/gallant-swirles-ljp5n5