Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unused-prop-types: Potential regression introduced in 7.5.0 #1542

Closed
LINKIWI opened this issue Nov 18, 2017 · 6 comments · Fixed by #1600
Closed

no-unused-prop-types: Potential regression introduced in 7.5.0 #1542

LINKIWI opened this issue Nov 18, 2017 · 6 comments · Fixed by #1600

Comments

@LINKIWI
Copy link

LINKIWI commented Nov 18, 2017

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)
@asafda
Copy link

asafda commented Dec 3, 2017

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 #1581

@ljharb
Copy link
Member

ljharb commented Dec 3, 2017

Yes, please open a new issue. Thanks!

@sscholle
Copy link

sscholle commented Dec 22, 2017

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

@a-nozeret
Copy link

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
}

@billyvg
Copy link

billyvg commented Jul 12, 2018

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),
      })
	)

@ljharb
Copy link
Member

ljharb commented Jul 12, 2018

@billyvg can you file a new issue, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants