Skip to content

Commit 2b0f500

Browse files
authored
Merge branch 'master' into add-disallow-list-for-component-props
2 parents 83893d4 + 8aa023a commit 2b0f500

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1212
* [`no-unknown-property`]: add `viewBox` on `marker` ([#3416][] @ljharb)
1313
* [`no-unknown-property`]: add `noModule` on `script` ([#3414][] @ljharb)
1414
* [`no-unknown-property`]: allow `onLoad` on `<object>` ([#3415][] @OleksiiKachan)
15+
* [`no-multi-comp`]: do not detect a function property returning only null as a component ([#3412][] @ljharb)
1516

1617
### Changed
1718

@@ -21,6 +22,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2122
[#3415]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3415
2223
[#3414]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3414
2324
[#3413]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3413
25+
[#3412]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3412
2426

2527
## [7.31.7] - 2022.09.05
2628

lib/util/Components.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ function componentRule(rule, context) {
592592
return undefined;
593593
}
594594

595+
if (parent.type === 'Property' && utils.isReturningOnlyNull(node)) {
596+
return undefined;
597+
}
598+
595599
return node;
596600
}
597601

tests/lib/rules/no-multi-comp.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ ruleTester.run('no-multi-comp', rule, {
236236
export default MenuList;
237237
`,
238238
},
239+
{
240+
code: `
241+
const MenuList = forwardRef(({ onClose, ...props }, ref) => {
242+
const onLogout = useCallback(() => {
243+
onClose()
244+
}, [onClose])
245+
246+
return (
247+
<BlnMenuList ref={ref} {...props}>
248+
<BlnMenuItem key="logout" onClick={onLogout}>
249+
Logout
250+
</BlnMenuItem>
251+
</BlnMenuList>
252+
)
253+
})
254+
255+
MenuList.displayName = 'MenuList'
256+
257+
MenuList.propTypes = {
258+
onClose: PropTypes.func
259+
}
260+
261+
MenuList.defaultProps = {
262+
onClose: () => null
263+
}
264+
265+
export default MenuList
266+
`,
267+
},
239268
]),
240269

241270
invalid: parsers.all([

0 commit comments

Comments
 (0)