Getter function of computed property should have return values
- VUE_MISSING_RETURN_VALUE_IN_COMPUTED
- Code Quality
- Medium
- vue
This rule applies when a getter function of a computed property does not return a value.
In this case, accessing the computed property always results in undefined
value, which could be unintended.
Noncompliant Code Example
View with compliant examples side by side<script>
export default {
data() {
return {
currentYear: new Date().getFullYear()
};
},
computed: {
prevYear() { // VUE_MISSING_RETURN_VALUE_IN_COMPUTED
this.currentYear - 1;
},
nextYear: {
get() { // VUE_MISSING_RETURN_VALUE_IN_COMPUTED
this.currentYear + 1;
},
set(nextYear) {
this.currentYear = nextYear - 1;
}
}
}
}
</script>
Compliant Code Example
View with noncompliant examples side by side<script>
export default {
data() {
return {
currentYear: new Date().getFullYear()
};
},
computed: {
prevYear() {
return this.currentYear - 1;
},
nextYear: {
get() {
return this.currentYear + 1;
},
set(nextYear) {
this.currentYear = nextYear - 1;
}
}
}
}
</script>
Version
This rule was introduced in DeepScan 1.15.0-beta.