Skip to content

no-unused-prop-types sometimes fails to detect props in functions on stateless components #885

Closed
singapore/lint-condo
#240
@pfhayes

Description

@pfhayes

Here is a minimal example that triggers this:

const PagingBlock = function(props) {
  return (
    <span>
      <a onClick={() => props.previousPage()}/>
      <a onClick={() => props.nextPage()}/>
    </span>
 );
};

PagingBlock.propTypes = {
  nextPage: React.PropTypes.func.isRequired,
  previousPage: React.PropTypes.func.isRequired,
};

The error message is:

  18:17  error  'previousPage' PropType is defined but prop is never used  react/no-unused-prop-types

Notes:

  • Converting this to a React.createClass with static propTypes fixes the issue
  • Removing either <a/> tag produces the correct lint error, the false error only occurs when both are present
  • The error is notified for the first tag (switching nextPage and previousPage inside the render function will make the error text say nextPage is defined but not used

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions