Rule Proposal: `vue/require-valid-default-prop`
See original GitHub issuePlease describe what the rule should do:
Enforces prop default values to be valid. In vue we have 2 ways to define default
prop value:
- by function
{ foo: { default () {} } }
- by literal value
{ foo: { default: '' } }
Literal value is not is not valid when type is specified and set to Array or Object
This rule should also check type of literal values and determine if types match. When variable is passed as default we should omit checking
What category of rule is this? (place an “X” next to just one item)
[ ]
Enforces code style
[x]
Warns about a potential error
[ ]
Suggests an alternate way of doing something
[ ]
Other (please specify:)
Valid:
Vue.component('example', {
props: {
// basic type check (`null` means accept any type)
propA: Number,
// multiple possible types
propB: [String, Number],
// a number with default value
propD: {
type: Number,
default: 100
},
// object/array defaults should be returned from a factory function
propE: {
type: Object,
default: function () {
return { message: 'hello' }
}
}
}
})
Invalid:
Vue.component('example', {
props: {
propA: {
type: String,
default: {}
},
propB: {
type: String,
default: []
},
propC: {
type: Object,
default: []
},
propD: {
type: Array,
default: []
},
propE: {
type: Object,
default: { message: 'hello' }
}
}
})
see more at: https://vuejs.org/v2/guide/components.html#Prop-Validation
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
vue/require-valid-default-prop
This rule checks whether the default value of each prop is valid for the given type. It should report an error when default...
Read more >vue/require-valid-default-prop | eslint-plugin-vue - GitHub Pages
This rule checks whether the default value of each prop is valid for the given type. It should report an error when default...
Read more >eslint-plugin-vue - npm
Start using eslint-plugin-vue in your project by running `npm i ... vue/require-valid-default-prop, enforce props default values to be valid.
Read more >vue props type null - You.com | The Search Engine You Control
In your code, you are saying that the prop is required and so Vuejs is showing the ... child.vue <script> export default {...
Read more >Validation Provider - VeeValidate
<template> <ValidationProvider rules="required" v-slot="{ errors }"> <input ... The default tag can be changed using the provider's tag prop.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@michalsnik we should distinct both of rules,
require-default-prop
should be optional, and its should require to specify default value if"required"
is not set or set to false.require-valid-default-prop
should be enabled by default (in next release), its catching errors / issues.good