Skip to content

Commit 6a68f09

Browse files
committed
[Fix] no-multi-comp: correctly ignore wrapped stateless components
Fixes #2145
1 parent 9497745 commit 6a68f09

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/rules/no-multi-comp.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
}]
3333
},
3434

35-
create: Components.detect((context, components) => {
35+
create: Components.detect((context, components, utils) => {
3636
const configuration = context.options[0] || {};
3737
const ignoreStateless = configuration.ignoreStateless || false;
3838

@@ -44,7 +44,12 @@ module.exports = {
4444
* @returns {Boolean} True if the component is ignored, false if not.
4545
*/
4646
function isIgnored(component) {
47-
return ignoreStateless && /Function/.test(component.node.type);
47+
return (
48+
ignoreStateless && (
49+
/Function/.test(component.node.type) ||
50+
utils.isPragmaComponentWrapper(component.node)
51+
)
52+
);
4853
}
4954

5055
// --------------------------------------------------------------------------

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ ruleTester.run('no-multi-comp', rule, {
9999
'};'
100100
].join('\n'),
101101
parserOptions: Object.assign({sourceType: 'module'}, parserOptions)
102+
}, {
103+
code: `
104+
const Hello = React.memo(function(props) {
105+
return <div>Hello {props.name}</div>;
106+
});
107+
class HelloJohn extends React.Component {
108+
render() {
109+
return <Hello name="John" />;
110+
}
111+
}
112+
`,
113+
options: [{
114+
ignoreStateless: true
115+
}]
102116
}],
103117

104118
invalid: [{

0 commit comments

Comments
 (0)