require-default-prop
Angular templatesHTMLVue / SvelteVue / Sveltesuspiciousno fixdefault: warnhtml/eslint-plugin-vue-recommended
What it does
Section titled “What it does”Reports a prop that is not required, has no default and is not a Boolean (defineProps({ a: String })). With a type (defineProps<{ a?: string }>()) only a component that sets defaults (withDefaults, a props destructure) is checked.
Why it matters
Section titled “Why it matters”The prop is undefined when the parent leaves it out, and the template or code then fails on it or shows undefined.
To fix, add a default, or mark the prop required.
Example
Section titled “Example”<script>export default { props: { a: String, b: { type: String, default: '' }, c: { required: true, type: Number }, d: Boolean, e: [String, Number], f: {}, g: Object, }, data() {...Configuration
Section titled “Configuration”angular: lint: rules: require-default-prop: warn # off, warn (default), errorhtml: lint: rules: require-default-prop: warn # off, warn (default), errorsvelte: lint: rules: require-default-prop: warn # off, warn (default), errorvue: lint: rules: require-default-prop: warn # off, warn (default), errorEnabled by the presets: html/eslint-plugin-vue-recommended.
Suppress one line with sudsy-disable-next-line require-default-prop in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint-plugin-vue | require-default-prop |
partial | a type that comes from another file is skipped (the plugin has no type information there either), a component object only at the top level as for no-dupe-keys |