VueJS - Unexpected Empty Method in props

  • Bitbucket Cloud
  • SonarCloud
  • Javascript Repository

For Vue.JS files, if you have a prop that defaults to an object or an array it is recommended you do this with an empty method, such as

props: {
  client: {
      type: Object,
      default: () => {},
  }
}

This triggers javascript:S1186

We can disable this rule for the time being, but it would be super handy if it could detect whether it is inside a Vue props object and ignore the rule.

1 Like

Hey,

I checked the link you provided, and (even if I am not a Vue expert) I understood that default property should be a function returning a default value for your property. In your case your function (as being empty) will return undefined. Don’t you think you should put parentheses so that function returns empty object?

props: {
  client: {
      type: Object,
      default: () => ({}),
  }
}

we have the same issue - did you resolve it somehow?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.