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-danger-with-children exception when props contains spread #771

Closed
btmills opened this issue Aug 16, 2016 · 2 comments
Closed

no-danger-with-children exception when props contains spread #771

btmills opened this issue Aug 16, 2016 · 2 comments

Comments

@btmills
Copy link

btmills commented Aug 16, 2016

#768 fixed #767 directly by allowing {...props} on JSX elements, but it's getting tripped up when it goes to find the definition of props and finds spreads there.

// .eslintrc.js
module.exports = {
    "root": true,
    "parserOptions": {
        "ecmaVersion": 6,
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        }
    },
    "plugins": ["react"],
    "rules": {
        "react/no-danger-with-children": "error"
    }
};
// pass.jsx
const props = { foo: 42 };
(<div {...props}>Children</div>);
// fail1.jsx
const { a, b, ...props } = this.props;
(<div {...props}>Children</div>);
// fail2.jsx
const props = { foo: 42, ...rest };
(<div {...props}>Children</div>);
$ npm ls --depth=0
~/test
├── eslint@3.3.1
└── eslint-plugin-react@6.1.1

$ node_modules/.bin/eslint pass.jsx
$ node_modules/.bin/eslint fail1.jsx
Cannot read property 'find' of undefined
TypeError: Cannot read property 'find' of undefined
    at findObjectProp (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:28:29)
    at ~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:46:20
    at Array.find (native)
    at findJsxProp (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:40:25)
    at EventEmitter.JSXElement (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:66:14)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (~/test/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (~/test/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (~/test/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
$ node_modules/.bin/eslint fail2.jsx
Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
    at ~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:29:24
    at Array.find (native)
    at findObjectProp (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:28:30)
    at ~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:46:20
    at Array.find (native)
    at findJsxProp (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:40:25)
    at EventEmitter.JSXElement (~/test/node_modules/eslint-plugin-react/lib/rules/no-danger-with-children.js:66:14)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (~/test/node_modules/eslint/lib/util/node-event-generator.js:40:22)
@klimashkin
Copy link

The same issue

@btmills btmills changed the title no-danger-with-props exception when props contains spread no-danger-with-children exception when props contains spread Aug 16, 2016
petersendidit added a commit to petersendidit/eslint-plugin-react that referenced this issue Aug 16, 2016
petersendidit added a commit to petersendidit/eslint-plugin-react that referenced this issue Aug 16, 2016
@petersendidit
Copy link
Contributor

#773 should fix these problems.

randycoulman added a commit to CodingZeal/eslint-config-zeal that referenced this issue Aug 16, 2016
This rule has a bug when working with spread properties (see
jsx-eslint/eslint-plugin-react#771).

Temporarily disable the rule to avoid the bug for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants