Skip to content

Commit 94fa138

Browse files
author
Evgueni Naverniouk
committed
Ensure SFC are ignored for the require-optimization rule.
1 parent 547cb5f commit 94fa138

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/rules/require-optimization.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,23 @@ module.exports = Components.detect(function (context, components) {
9696
};
9797

9898
return {
99+
ArrowFunctionExpression: function (node) {
100+
// Stateless Functional Components cannot be optimized (yet)
101+
markSCUAsDeclared(node);
102+
},
103+
99104
ClassDeclaration: function (node) {
100105
if (!hasPureRenderDecorator(node)) {
101106
return;
102107
}
103108
markSCUAsDeclared(node);
104109
},
105110

111+
FunctionExpression: function (node) {
112+
// Stateless Functional Components cannot be optimized (yet)
113+
markSCUAsDeclared(node);
114+
},
115+
106116
MethodDefinition: function (node) {
107117
if (!isSCUDeclarеd(node.key)) {
108118
return;

tests/lib/rules/require-optimization.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ ruleTester.run('react-require-optimization', rule, {
6161
].join('\n'),
6262
parser: 'babel-eslint',
6363
parserOptions: parserOptions
64+
}, {
65+
code: [
66+
'const FunctionalComponent = function (props) {' +
67+
'return <div />;' +
68+
'}'
69+
].join('\n'),
70+
parser: 'babel-eslint',
71+
parserOptions: parserOptions
72+
}, {
73+
code: [
74+
'const FunctionalComponent = (props) => {' +
75+
'return <div />;' +
76+
'}'
77+
].join('\n'),
78+
parser: 'babel-eslint',
79+
parserOptions: parserOptions
6480
}],
6581

6682
invalid: [{

0 commit comments

Comments
 (0)