Skip to content

Commit

Permalink
Fix no-danger-with-children crash with spread on global variables (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Croissant committed Nov 13, 2016
1 parent 1df6118 commit fe5594b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
return attributes.find(function (attribute) {
if (attribute.type === 'JSXSpreadAttribute') {
var variable = findSpreadVariable(attribute.argument.name);
if (variable && variable.defs[0].node.init) {
if (variable && variable.defs.length && variable.defs[0].node.init) {
return findObjectProp(variable.defs[0].node.init, propName);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ ruleTester.run('no-danger-with-children', rule, {
code: '<div>Children</div>',
parserOptions: parserOptions
},
{
code: '<div {...props} />',
parserOptions: parserOptions,
globals: {
props: true
}
},
{
code: '<div dangerouslySetInnerHTML={{ __html: "HTML" }} />',
parserOptions: parserOptions
Expand Down

0 comments on commit fe5594b

Please sign in to comment.