Eslint-plugin-react: no-unused-prop-types: Potential regression introduced in 7.5.0

Created on 18 Nov 2017  路  6Comments  路  Source: yannickcr/eslint-plugin-react

Hi there.

Noticed that my lint step failed after tagging my library with no code changes:

https://travis-ci.org/LINKIWI/react-elemental/builds/304035438
https://travis-ci.org/LINKIWI/react-elemental/builds/304036629

Interestingly, the failing build pulled in 7.5.0 of eslint-plugin-react which was published a couple minutes before the build kicked off.

I haven't had time to do thorough investigation yet, but the 7.5.0 release seems to have introduced a regression in no-unused-prop-types:

Cannot read property 'properties' of undefined

TypeError: Cannot read property 'properties' of undefined

    at markPropTypesAsUsed (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:658:40)

    at handleSetStateUpdater (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:955:7)

    at Object.handleFunctionLikeExpressions (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:964:7)

    at updatedRuleInstructions.(anonymous function) (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint-plugin-react/lib/util/Components.js:654:75)

    at listeners.(anonymous function).forEach.listener (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/util/safe-emitter.js:47:58)

    at Array.forEach (native)

    at Object.emit (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/util/safe-emitter.js:47:38)

    at NodeEventGenerator.applySelector (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/util/node-event-generator.js:251:26)

    at NodeEventGenerator.applySelectors (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/util/node-event-generator.js:280:22)

    at NodeEventGenerator.enterNode (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/util/node-event-generator.js:294:14)

    at CodePathAnalyzer.enterNode (/home/travis/build/LINKIWI/react-elemental/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
bug help wanted

Most helpful comment

I'm still getting this with v7.10.0, when using the setState callback

    this.setState(
      state => ({
        data: state.data.filter(({id}) => id !== authorization.id),
      })
    )

All 6 comments

I'm still getting this error when passing an empty function as a default props.
In my code:

FeedWithSubheader.propTypes = {
  componentRef: (() => {})
};

I get this error:

TypeError: Cannot read property 'properties' of undefined
    at markPropTypesAsUsed (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:656:38)
    at iterateProperties (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:825:15)
    at iterateProperties (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:361:11)
    at markPropTypesAsDeclared (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:810:11)
    at MemberExpression (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:1027:13)
    at listeners.(anonymous function).forEach.listener (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (native)
    at Object.emit (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/asafdavid/homeis-dev/home-is-mobile/node_modules/eslint/lib/util/node-event-generator.js:280:22)

Also, should I open this as a separate issue? ==> Opened a new issue https://github.com/yannickcr/eslint-plugin-react/issues/1581

Yes, please open a new issue. Thanks!

I am still getting this issue in v7.5.1 see #1446

The error appears when you mistakenly define your propTypes,
e.g.:

Component.propTypes = {
   onClick: () => {}, // Wrong
}

instead of

Component.propTypes = { 
   onClick: PropTypes.func, // Correctly defined propType
}

or

Component.defaultProps = {
   onClick: () => {},  // Correctly defined defaultProp
}

I'm still getting this with v7.10.0, when using the setState callback

    this.setState(
      state => ({
        data: state.data.filter(({id}) => id !== authorization.id),
      })
    )

@billyvg can you file a new issue, please?

Was this page helpful?
0 / 5 - 0 ratings