Skip to content

Commit 046a723

Browse files
committed
Fix require-optimization warning on stateless components (fixes jsx-eslint#687)
1 parent c7a6c67 commit 046a723

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/rules/require-optimization.js

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ module.exports = Components.detect(function (context, components) {
134134
markSCUAsDeclared(node);
135135
},
136136

137+
FunctionDeclaration: function (node) {
138+
// Stateless Functional Components cannot be optimized (yet)
139+
markSCUAsDeclared(node);
140+
},
141+
137142
FunctionExpression: function (node) {
138143
// Stateless Functional Components cannot be optimized (yet)
139144
markSCUAsDeclared(node);

tests/lib/rules/require-optimization.js

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ ruleTester.run('react-require-optimization', rule, {
6969
].join('\n'),
7070
parser: 'babel-eslint',
7171
parserOptions: parserOptions
72+
}, {
73+
code: [
74+
'function FunctionalComponent(props) {' +
75+
'return <div />;' +
76+
'}'
77+
].join('\n'),
78+
parser: 'babel-eslint',
79+
parserOptions: parserOptions
7280
}, {
7381
code: [
7482
'const FunctionalComponent = (props) => {' +

0 commit comments

Comments
 (0)