Skip to content

Commit cd0ca8d

Browse files
VincentLangletljharb
authored andcommitted
[Fix] jsx-sort-default-props: fix case with spread
1 parent 752de70 commit cd0ca8d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/rules/jsx-sort-default-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = {
9696
*/
9797
function checkSorted(declarations) {
9898
declarations.reduce((prev, curr, idx, decls) => {
99-
if (/SpreadProperty$/.test(curr.type)) {
99+
if (/Spread(?:Property|Element)$/.test(curr.type)) {
100100
return decls[idx + 1];
101101
}
102102

tests/lib/rules/jsx-sort-default-props.js

+19
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,25 @@ ruleTester.run('jsx-sort-default-props', rule, {
326326
'First.propTypes = propTypes;',
327327
'First.defaultProps = defaultProps;'
328328
].join('\n')
329+
}, {
330+
code: [
331+
'const defaults = {',
332+
' b: "b"',
333+
'};',
334+
'const First = (props) => <div />;',
335+
'export const propTypes = {',
336+
' a: PropTypes.string,',
337+
' b: PropTypes.string,',
338+
' z: PropTypes.string,',
339+
'};',
340+
'export const defaultProps = {',
341+
' ...defaults,',
342+
' a: "a",',
343+
' z: "z",',
344+
'};',
345+
'First.propTypes = propTypes;',
346+
'First.defaultProps = defaultProps;'
347+
].join('\n')
329348
}],
330349

331350
invalid: [{

0 commit comments

Comments
 (0)