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

prop-types rule fails to parse rules that are created by extending using spread #389

Closed
marcins opened this issue Jan 11, 2016 · 0 comments

Comments

@marcins
Copy link

marcins commented Jan 11, 2016

It appears that the prop-types rule fails parsing propTypes that are defined by use of the spread operator. This code causes the prop-types rule to throw an exception when parsing:

import React from 'react';

export default class Test extends React.Component {
    render() {
        return  <div>{this.props.firstName} {this.props.lastName}</div>;
    }
};

const otherPropTypes = {
    lastName: React.PropTypes.string
};

Test.propTypes = {
    ...otherPropTypes,
    firstName: React.PropTypes.string
};
/private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:232
      value.type === 'MemberExpression' &&
           ^

TypeError: Cannot read property 'type' of undefined
    at buildReactDeclarationTypes (/private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:232:12)
    at /private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:493:36
    at iterateProperties (/private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:209:9)
    at markPropTypesAsDeclared (/private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:492:9)
    at EventEmitter.MemberExpression (/private/tmp/foo/node_modules/eslint-plugin-react/lib/rules/prop-types.js:612:11)
    at emitOne (events.js:77:13)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (/private/tmp/foo/node_modules/eslint/lib/util/node-event-generator.js:42:22)
    at CommentEventGenerator.enterNode (/private/tmp/foo/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
    at Controller.controller.traverse.enter (/private/tmp/foo/node_modules/eslint/lib/eslint.js:767:36)

This is because iterateProperties in doesn't expect the "ExperimentalSpreadProperty" node.

At the very least this should have the same behaviour referencing an external object and should disable the rule for the component.

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

No branches or pull requests

2 participants