Skip to content

[react/prop-types] false positive when renaming in destructuring context #2944

@mladenoff

Description

@mladenoff

When following react/destructuring-assignment, if my prop shares a name with another constant I rename it during the destructure (prop.styles to propStyles below) to avoid the collision, I then start getting warned that styles.posterImage' is missing in props validation etc. for all keys of the styles object.

import styles from '../styles/Video'

// ...

  render() {
    const { altText, styles: propStyles, posterUrl, videoUrl, subtitleUrl } = this.props

    const poster = (
      <>
        <img
          className={css(propStyles, styles.posterImage, this.state.isHovering && styles.zoomed)}
          src={posterUrl}
          alt={altText}
        />

Expected behavior: styles is not recognized as a prop after destructuring but propStyles is. No false positives on constants that share name with renamed prop's original name on the props object.

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