Skip to content

Files

Latest commit

 

History

History
88 lines (73 loc) · 1.53 KB

return-in-computed-property.md

File metadata and controls

88 lines (73 loc) · 1.53 KB

Pattern: Missing return in computed property

Issue: -

Description

This rule enforces that a return statement is present in computed properties.

<script>
export default {
  computed: {
    /* ✓ GOOD */
    foo () {
      if (this.bar) {
        return this.baz
      } else {
        return this.baf
      }
    },
    bar: function () {
      return false
    },
    /* ✗ BAD */
    baz () {
      if (this.baf) {
        return this.baf
      }
    },
    baf: function () {}
  }
}
</script>

Options

{
  "vue/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.bar) {
        return undefined
      } else {
        return
      }
    },
    bar: function () {
      return
    },
    /* ✗ BAD */
    baz () {
      if (this.baf) {
        return this.baf
      }
    },
    baf: function () {}
  }
}
</script>

Further Reading