Skip to content

Rule Proposal: Prohibit calling computed properties like methods #928

Closed
@TheAlexLichter

Description

@TheAlexLichter

Please describe what the rule should do:
This rule should prohibit calling computed properties like methods. The only exception would be when a method is returned by that computed property. Not sure if this is actually "easily detectable" though.

What category should the rule belong to?

  • Enforces code style
  • Warns about a potential error
  • Suggests an alternate way of doing something
  • Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<template>
  <h1>
    <!-- .... -->
  </h1>
</template>

<script>
export default {
  props: {
    user: {
      type: [Object, Boolean],
      required: true
    }
  },
  computed: {
    isUserPresent () {
      return this.user
    },
  },
  methods: {
    greetUser () {
      if(this.isUserPresent()) { // oh oh! called the computed prop like a method
	   console.log('Hi user')
      }
    }
  }
}
</script>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions