Skip to content

boolean-prop-naming triggers "Cannot read property 'properties' of undefined" #1594

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

Closed
fohrloop opened this issue Dec 11, 2017 · 1 comment
Closed

Comments

@fohrloop
Copy link

The problem is very similar to #1452 and #1354.

System setup

Windows 10, node v.8.9.3, eslint-plugin-react v. 7.5.1, ESLint v.3.19.0

Error

Cannot read property 'properties' of undefined
TypeError: Cannot read property 'properties' of undefined
    at EventEmitter.MemberExpression (C:\MyProject\node_modules\eslint-plugin-react\lib\rules\boolean-prop-naming.js:163:46)
    at emitOne (events.js:121:20)
    at EventEmitter.emit (events.js:211:7)
    at NodeEventGenerator.applySelector (C:\MyProject\node_modules\eslint\lib\util\node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (C:\MyProject\node_modules\eslint\lib\util\node-event-generator.js:294:22)
    at NodeEventGenerator.enterNode (C:\MyProject\node_modules\eslint\lib\util\node-event-generator.js:308:14)
    at CodePathAnalyzer.enterNode (C:\MyProject\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:602:23)
    at CommentEventGenerator.enterNode (C:\MyProject\node_modules\eslint\lib\util\comment-event-generator.js:98:23)
    at Traverser.enter (C:\MyProject\node_modules\eslint\lib\eslint.js:929:36)
    at Traverser.__execute (C:\MyProject\node_modules\estraverse\estraverse.js:397:31)

How to reproduce?

eslintrc.js

This happens with "any" rules given to react/boolean-prop-naming, for example: "react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+", "propTypeNames": ["bool"] }].

file_to_be_linted.js

I was using copy-pasted Icon component. The ~minimal code to reproduce the error is

import React from 'react'
import PropTypes from 'prop-types'

const IconBase = ({ width }, { reactIconBase = {} }) => {
  return (
    <h1>width</h1>
  )
}

IconBase.propTypes = {
  width: PropTypes.number
}

IconBase.contextTypes = {
  reactIconBase: PropTypes.shape(IconBase.propTypes)
}

export default IconBase

Minimal changes to fix the error

Use a copy-pasted (not calculated) object literal inside the values in contextTypes. For example:

import React from 'react'
import PropTypes from 'prop-types'

const IconBase = ({ width }, { reactIconBase = {} }) => {
  return (
    <h1>width</h1>
  )
}

IconBase.propTypes = {
  width: PropTypes.number
}

IconBase.contextTypes = {
  reactIconBase: PropTypes.shape({
    width: PropTypes.number
  })
}

export default IconBase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants