Skip to content

prop-types rule reports for Array.prototype.length is missing #1047

Closed
@ashleahhill

Description

h2. Expected

When a propType React.PropTypes.arrayOf(<something>), you shouldn't be prompted to add
length by eslint.

h2. What happens

You get '.length' is missing in props validation (react/prop-types) from eslint

h2. Example

class MyClass extends React.Component {
    static propTypes = {
        results: PropTypes.arrayOf(
            PropTypes.shape({
                items: PropTypes.arrayOf(PropTypes.shape(<Shape definition>))
            })
        )
    };

    get hasItems() {
        this.props.results && this.props.results.items && this.props.results.items.length > 0; 
    }
}

Results in this:
'results.items.length' is missing in props validation (react/prop-types)

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