Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsx-sort-default-props] Bug fix for one case with spread #2182

Merged
merged 1 commit into from Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/jsx-sort-default-props.js
Expand Up @@ -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];
}

Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/jsx-sort-default-props.js
Expand Up @@ -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) => <div />;',
'export const propTypes = {',
' a: PropTypes.string,',
' b: PropTypes.string,',
' z: PropTypes.string,',
'};',
'export const defaultProps = {',
' ...defaults,',
ljharb marked this conversation as resolved.
Show resolved Hide resolved
' a: "a",',
' z: "z",',
'};',
'First.propTypes = propTypes;',
'First.defaultProps = defaultProps;'
].join('\n')
}],

invalid: [{
Expand Down