Skip to content

Commit

Permalink
Fix no-children-prop spread support
Browse files Browse the repository at this point in the history
  • Loading branch information
randycoulman authored and yannickcr committed Sep 24, 2016
1 parent 2adefb7 commit f227eb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-children-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {

var props = node.arguments[1].properties;
var childrenProp = props.find(function(prop) {
return prop.key.name === 'children';
return prop.key && prop.key.name === 'children';
});

if (childrenProp) {
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/no-children-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var RuleTester = require('eslint').RuleTester;
var parserOptions = {
ecmaVersion: 6,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true
}
};
Expand Down Expand Up @@ -170,6 +171,14 @@ ruleTester.run('no-children-prop', rule, {
{
code: 'React.createElement(MyComponent, {className: "class-name"}, "Children");',
parserOptions: parserOptions
},
{
code: '<MyComponent className="class-name" {...props} />;',
parserOptions: parserOptions
},
{
code: 'React.createElement(MyComponent, {className: "class-name", ...props});',
parserOptions: parserOptions
}
],
invalid: [
Expand Down Expand Up @@ -232,6 +241,16 @@ ruleTester.run('no-children-prop', rule, {
code: 'React.createElement(MyComponent, {children: "Children", className: "class-name"});',
errors: [{message: CREATE_ELEMENT_ERROR}],
parserOptions: parserOptions
},
{
code: '<MyComponent {...props} children="Children" />;',
errors: [{message: JSX_ERROR}],
parserOptions: parserOptions
},
{
code: 'React.createElement(MyComponent, {...props, children: "Children"})',
errors: [{message: CREATE_ELEMENT_ERROR}],
parserOptions: parserOptions
}
]
});

0 comments on commit f227eb4

Please sign in to comment.