From 827658e4f44399c71ccffce2dc4dc2caf3f8b770 Mon Sep 17 00:00:00 2001 From: Ev Haus Date: Thu, 31 Aug 2017 08:14:32 -0700 Subject: [PATCH] Fix another crash in boolean-prop-naming rule related to old-style Flow prop type definitions. --- lib/rules/boolean-prop-naming.js | 2 +- tests/lib/rules/boolean-prop-naming.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index 66462acd78..c9baaa70c6 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -118,7 +118,7 @@ module.exports = { const component = components.get(node) || node; const invalidProps = component.invalidProps || []; - proptypes.forEach(prop => { + (proptypes || []).forEach(prop => { const propKey = getPropKey(prop); const flowCheck = ( prop.type === 'ObjectTypeProperty' && diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 3c538703a6..6e10971ef3 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -257,6 +257,18 @@ ruleTester.run('boolean-prop-naming', rule, { rule: '^is[A-Z]([A-Za-z0-9]?)+' }], parser: 'babel-eslint' + }, { + // Ensure rule doesn't crash on on components reference old-style Flow props + code: [ + 'class Hello extends PureComponent {', + ' props: PropsType;', + ' render () { return
}', + '}' + ].join('\n'), + options: [{ + rule: '^is[A-Z]([A-Za-z0-9]?)+' + }], + parser: 'babel-eslint' }], invalid: [{