# 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>
Now loading...

# 🔧 Options

{
  "san/return-in-computed-property": ["error", {
    "treatUndefinedAsUnspecified": true
  }]
}

This rule has an object option:

  • "treatUndefinedAsUnspecified": true (default) disallows implicitly returning undefined with a return 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>
Now loading...

# 🔍 Implementation

Last Updated: 10/26/2021, 7:23:11 AM