Skip to content

Rule Proposal: Props must explicitly state requirednessΒ #629

Open
@gwardwell

Description

@gwardwell

Please describe what the rule should do:
This rule should enforce including the required property, whether true or false, when defining a Vue Component prop as an object.

What category of rule is this? (place an "X" next to just one item)

[X] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

Valid props definition:

export default {
    props: {
        myProp: {
            type: String,
            required: true,
        },
        myProp: {
            type: Boolean,
            required: false,
            default: true,
        },
    },
}

Invalid props definition:

export default {
    props: {
        myProp: {
            type: String,
        },
        myProp: {
            type: Boolean,
            default: true,
        },
    },
}

Why should this rule be included?
Relying on the existence of a default property is not an indicator that a prop is required, nor is omitting the required property an indicator that the prop is not required. Explicitly stating whether or not a prop is required makes the component and how to use it easier to reason about.

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