Skip to content

Commit

Permalink
[Fix] no-multi-comp: correctly ignore wrapped stateless components
Browse files Browse the repository at this point in the history
Fixes #2145
  • Loading branch information
yannickcr committed Jan 27, 2019
1 parent 9497745 commit 6a68f09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/rules/no-multi-comp.js
Expand Up @@ -32,7 +32,7 @@ module.exports = {
}]
},

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

Expand All @@ -44,7 +44,12 @@ module.exports = {
* @returns {Boolean} True if the component is ignored, false if not.
*/
function isIgnored(component) {
return ignoreStateless && /Function/.test(component.node.type);
return (
ignoreStateless && (
/Function/.test(component.node.type) ||
utils.isPragmaComponentWrapper(component.node)
)
);
}

// --------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-multi-comp.js
Expand Up @@ -99,6 +99,20 @@ ruleTester.run('no-multi-comp', rule, {
'};'
].join('\n'),
parserOptions: Object.assign({sourceType: 'module'}, parserOptions)
}, {
code: `
const Hello = React.memo(function(props) {
return <div>Hello {props.name}</div>;
});
class HelloJohn extends React.Component {
render() {
return <Hello name="John" />;
}
}
`,
options: [{
ignoreStateless: true
}]
}],

invalid: [{
Expand Down

0 comments on commit 6a68f09

Please sign in to comment.