From d8dff2639d7085ccbf9dd52d027e787f1494c962 Mon Sep 17 00:00:00 2001 From: Justin Anastos Date: Wed, 31 Jan 2018 14:17:31 -0500 Subject: [PATCH 1/2] test(sort-prop-types) Add failing test for when `sortShapeProp` is true and shape not object literal --- tests/lib/rules/sort-prop-types.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/lib/rules/sort-prop-types.js b/tests/lib/rules/sort-prop-types.js index 51d5a6a892..01095ee035 100644 --- a/tests/lib/rules/sort-prop-types.js +++ b/tests/lib/rules/sort-prop-types.js @@ -365,6 +365,24 @@ ruleTester.run('sort-prop-types', rule, { options: [{ sortShapeProp: true }] + }, { + code: ` + class Component extends React.Component { + render() { + return
; + } + } + Component.propTypes = { + a: PropTypes.any, + b: PropTypes.any, + c: PropTypes.shape( + importedPropType, + ), + }; + `, + options: [{ + sortShapeProp: true + }] }], invalid: [{ From 17ac433b4d97659b74cf682b7e79d48542a13822 Mon Sep 17 00:00:00 2001 From: Justin Anastos Date: Wed, 31 Jan 2018 14:20:04 -0500 Subject: [PATCH 2/2] fix(sort-prop-types): Fix sortShapeProp when shape is not an object literal --- lib/rules/sort-prop-types.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index 8ca7879623..a56cf4b786 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -77,6 +77,12 @@ module.exports = { * @returns {void} */ function checkSorted(declarations) { + // Declarations will be `undefined` if the `shape` is not a literal. For + // example, if it is a propType imported from another file. + if (!declarations) { + return; + } + declarations.reduce((prev, curr, idx, decls) => { if (/SpreadProperty$/.test(curr.type)) { return decls[idx + 1];