Skip to content

Allow require-default-prop to be set to false for non required props #326

@filipalacerda

Description

@filipalacerda

Hello!

While adding this plugin to our project, I'm finding the need to add configuration to this rule: https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/require-default-prop.js

It is helpful to have a default prop in most cases, but sometimes we use the non existence of one to check if a certain part of a component should be rendered.

For example:
For the non-required string prop title, checking if title exists is enough:

props: {
  title: {
    type: String, 
    required: false,
  },
},
...
<p v-if="title>{{ title }}</p>

If I have to set a default to an empty string, I need an extra check.

Or for a datepicker component that accepts a minDate as a non required prop, it is very helpful to not have a default value, in the cases where a min date is not needed.

This was something that we found useful after starting the style guide: https://docs.gitlab.com/ce/development/fe_guide/style_guide_js.html#props

Default key should be provided if the prop is not required. Note: There are some scenarios where we need to check for the existence of the property. On those a default key should not be provided.

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