-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Fix] no-unstable-components
: improve handling of objects containing render functions
#3111
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -383,6 +383,78 @@ ruleTester.run('no-unstable-nested-components', rule, { | |||||||||
`, | ||||||||||
options: [{ allowAsProps: true }], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{ | ||||||||||
thing.match({ | ||||||||||
renderLoading: () => <div />, | ||||||||||
renderSuccess: () => <div />, | ||||||||||
renderFailure: () => <div />, | ||||||||||
}) | ||||||||||
} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
const thingElement = thing.match({ | ||||||||||
renderLoading: () => <div />, | ||||||||||
renderSuccess: () => <div />, | ||||||||||
renderFailure: () => <div />, | ||||||||||
}); | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{thingElement} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{ | ||||||||||
thing.match({ | ||||||||||
loading: () => <div />, | ||||||||||
success: () => <div />, | ||||||||||
failure: () => <div />, | ||||||||||
}) | ||||||||||
} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
options: [{ | ||||||||||
allowAsProps: true, | ||||||||||
}], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
const thingElement = thing.match({ | ||||||||||
loading: () => <div />, | ||||||||||
success: () => <div />, | ||||||||||
failure: () => <div />, | ||||||||||
}); | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{thingElement} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
options: [{ | ||||||||||
allowAsProps: true, | ||||||||||
}], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
|
@@ -500,6 +572,9 @@ ruleTester.run('no-unstable-nested-components', rule, { | |||||||||
return <Table rows={rows} />; | ||||||||||
} | ||||||||||
`, | ||||||||||
options: [{ | ||||||||||
allowAsProps: true, | ||||||||||
}], | ||||||||||
Comment on lines
+575
to
+577
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same change throughout There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this case was previously allowed without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, this should not have been an allowed pattern. Requiring the It was marked as error by initial implementation. It seems there were some changes made to general component detection which affected this. 860ebea#diff-2c6ecc4f3063d33adbe4b551631a53d57725100435423ed732f4e8ea752d821aL1013 |
||||||||||
}, | ||||||||||
/* TODO These minor cases are currently falsely marked due to component detection | ||||||||||
{ | ||||||||||
|
@@ -1042,5 +1117,63 @@ ruleTester.run('no-unstable-nested-components', rule, { | |||||||||
// Only a single error should be shown. This can get easily marked twice. | ||||||||||
errors: [{ message: ERROR_MESSAGE }], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{ | ||||||||||
thing.match({ | ||||||||||
loading: () => <div />, | ||||||||||
success: () => <div />, | ||||||||||
failure: () => <div />, | ||||||||||
}) | ||||||||||
} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
errors: [ | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
const thingElement = thing.match({ | ||||||||||
loading: () => <div />, | ||||||||||
success: () => <div />, | ||||||||||
failure: () => <div />, | ||||||||||
}); | ||||||||||
return ( | ||||||||||
<SomeComponent> | ||||||||||
{thingElement} | ||||||||||
</SomeComponent> | ||||||||||
) | ||||||||||
} | ||||||||||
`, | ||||||||||
errors: [ | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }, | ||||||||||
], | ||||||||||
}, | ||||||||||
{ | ||||||||||
code: ` | ||||||||||
function ParentComponent() { | ||||||||||
const rows = [ | ||||||||||
{ | ||||||||||
name: 'A', | ||||||||||
notPrefixedWithRender: (props) => <Row {...props} /> | ||||||||||
}, | ||||||||||
]; | ||||||||||
return <Table rows={rows} />; | ||||||||||
} | ||||||||||
`, | ||||||||||
errors: [{ message: ERROR_MESSAGE_COMPONENT_AS_PROPS }], | ||||||||||
}, | ||||||||||
]), | ||||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same change throughout