From 71b522aca491dc2dc7da1f280ceb5d7b80724fdc Mon Sep 17 00:00:00 2001 From: Nicholas Latham Date: Fri, 29 Jun 2018 10:17:21 +1200 Subject: [PATCH 1/2] Stop crashing on undefined or null properties Similar to other fix for flow intersection (#1806) --- lib/rules/prop-types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index bd66503f58..1895727984 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -360,7 +360,7 @@ module.exports = { and property value. (key, value) => void */ function iterateProperties(properties, fn) { - if (properties.length && typeof fn === 'function') { + if (properties && properties.length && typeof fn === 'function') { for (let i = 0, j = properties.length; i < j; i++) { const node = properties[i]; const key = getKeyValue(node); From 87a0818715a33b8b592530d44b4c1bddc3a9bc81 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Wed, 4 Jul 2018 22:06:39 +1200 Subject: [PATCH 2/2] Add test cases --- tests/lib/rules/prop-types.js | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 443d3bd10b..75d358426a 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1872,6 +1872,25 @@ ruleTester.run('prop-types', rule, { }; `, parser: 'babel-eslint' + }, + { + code: ` + // @flow + import * as React from 'react' + + type Props = {} + + const func = (arg) => arg + + const hoc = () => () => { + class Inner extends React.Component { + render() { + return
+ } + } + } + `, + parser: 'babel-eslint' } ], @@ -3627,6 +3646,38 @@ ruleTester.run('prop-types', rule, { message: '\'fooBar\' is missing in props validation' }], parser: 'babel-eslint' + }, + { + code: ` + type ReduxState = {bar: number}; + + const mapStateToProps = (state: ReduxState) => ({ + foo: state.bar, + }); + // utility to extract the return type from a function + type ExtractReturn_ R> = R; + type ExtractReturn = ExtractReturn_<*, T>; + + type PropsFromRedux = ExtractReturn; + + type OwnProps = { + baz: string, + } + + // I want my Props to be {baz: string, foo: number} + type Props = PropsFromRedux & OwnProps; + + const Component = (props: Props) => ( +
+ {props.baz} + {props.bad} +
+ ); + `, + errors: [{ + message: '\'bad\' is missing in props validation' + }], + parser: 'babel-eslint' } ] });