eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

vue/require-valid-default-prop does not work with type Object and return undefined

Open xianshenglu opened this issue 4 years ago • 4 comments

Checklist

  • [x] I have tried restarting my IDE and the issue persists.
  • [x] I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 7.2.0
  • eslint-plugin-vue version: 7.5.0
  • Node version: v10.16.3
  • Operating System: windows10

Please show your full configuration:

{
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "globals": {
    "BMap": true
  },
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "babel-eslint",
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "generators": false,
      "objectLiteralDuplicateProperties": false
    }
  },
  "plugins": ["import", "vue"],
  "rules": {
    "vue/require-valid-default-prop": ["error"]
  }
}

What did you do?

export default {
  name: 'Settings',
  props: {
    a: {
      type: Object,
      default() {},
    },
    b: {
      type: Object,
      default: () => {},
    },
    c: {
      type: Object,
      default: () => undefined,
    },
    d: {
      type: Object,
      default: () => false,
    },
  },
}

What did you expect to happen?

error: Type of the default value for 'a' prop must be a object (vue/require-valid-default-prop) error: Type of the default value for 'b' prop must be a object (vue/require-valid-default-prop) error: Type of the default value for 'c' prop must be a object (vue/require-valid-default-prop) error: Type of the default value for 'd' prop must be a object (vue/require-valid-default-prop)

What actually happened?

error: Type of the default value for 'd' prop must be a object (vue/require-valid-default-prop)

Repository to reproduce this issue

xianshenglu avatar Jan 25 '21 06:01 xianshenglu

Thank you for this issue. I think we need to add another rule to check for the existence of return. It's similar to vue/return-in-computed-property rule.

ota-meshi avatar Feb 07 '21 09:02 ota-meshi

@ota-meshi Hi And what should I do with the next? alt text

VRuzhentsov avatar Apr 05 '21 17:04 VRuzhentsov

@ota-meshi Hi And what should I do with the next? alt text

change query type to Array. Also, the default value of settings should be ({}) instead of {}.

xianshenglu avatar Apr 06 '21 02:04 xianshenglu

change query type to Array. Also, the default value of settings should be ({}) instead of {}.

Totally missed that thank you so much

VRuzhentsov avatar Apr 06 '21 06:04 VRuzhentsov