# san/return-in-computed-property
enforce that a return statement is present in computed property
- ⚙️ This rule is included in all of
"plugin:san/essential"
,"plugin:san/strongly-recommended"
and"plugin:san/recommended"
.
# 📖 Rule Details
This rule enforces that a return
statement is present in computed
properties.
<script>
export default {
computed: {
/* ✓ GOOD */
foo() {
if (this.data.get('bar')) {
return this.data.get('baz')
} else {
return this.data.get('baf')
}
},
bar: function () {
return false
},
/* ✗ BAD */
baz () {
const baf = this.data.get('baf')
if (baf) {
return baf
}
},
baf: function () {}
}
}
</script>
# 🔧 Options
{
"san/return-in-computed-property": ["error", {
"treatUndefinedAsUnspecified": true
}]
}
This rule has an object option:
"treatUndefinedAsUnspecified"
:true
(default) disallows implicitly returning undefined with areturn
statement.
# treatUndefinedAsUnspecified: false
<script>
export default {
computed: {
/* ✓ GOOD */
foo () {
if (this.data.get('bar')) {
return undefined
} else {
return
}
},
bar: function () {
return
},
/* ✗ BAD */
baz () {
const baf = this.data.get('baf')
if (baf) {
return baf
}
},
baf: function () {}
}
}
</script>