From cd0ca8d265d22a1c012e85958fa57ae594b4ff81 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 28 Feb 2019 23:40:27 +0100 Subject: [PATCH] [Fix] `jsx-sort-default-props`: fix case with spread --- lib/rules/jsx-sort-default-props.js | 2 +- tests/lib/rules/jsx-sort-default-props.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/rules/jsx-sort-default-props.js b/lib/rules/jsx-sort-default-props.js index ca9b0fc714..13e869fec0 100644 --- a/lib/rules/jsx-sort-default-props.js +++ b/lib/rules/jsx-sort-default-props.js @@ -96,7 +96,7 @@ module.exports = { */ function checkSorted(declarations) { declarations.reduce((prev, curr, idx, decls) => { - if (/SpreadProperty$/.test(curr.type)) { + if (/Spread(?:Property|Element)$/.test(curr.type)) { return decls[idx + 1]; } diff --git a/tests/lib/rules/jsx-sort-default-props.js b/tests/lib/rules/jsx-sort-default-props.js index 4c804a10ba..96ab8ddc91 100644 --- a/tests/lib/rules/jsx-sort-default-props.js +++ b/tests/lib/rules/jsx-sort-default-props.js @@ -326,6 +326,25 @@ ruleTester.run('jsx-sort-default-props', rule, { 'First.propTypes = propTypes;', 'First.defaultProps = defaultProps;' ].join('\n') + }, { + code: [ + 'const defaults = {', + ' b: "b"', + '};', + 'const First = (props) =>
;', + 'export const propTypes = {', + ' a: PropTypes.string,', + ' b: PropTypes.string,', + ' z: PropTypes.string,', + '};', + 'export const defaultProps = {', + ' ...defaults,', + ' a: "a",', + ' z: "z",', + '};', + 'First.propTypes = propTypes;', + 'First.defaultProps = defaultProps;' + ].join('\n') }], invalid: [{