Skip to content

Commit

Permalink
Fix require-optimization warning on stateless components (fixes #687)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jul 25, 2016
1 parent c7a6c67 commit 046a723
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rules/require-optimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ module.exports = Components.detect(function (context, components) {
markSCUAsDeclared(node);
},

FunctionDeclaration: function (node) {
// Stateless Functional Components cannot be optimized (yet)
markSCUAsDeclared(node);
},

FunctionExpression: function (node) {
// Stateless Functional Components cannot be optimized (yet)
markSCUAsDeclared(node);
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/require-optimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ ruleTester.run('react-require-optimization', rule, {
].join('\n'),
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: [
'function FunctionalComponent(props) {' +
'return <div />;' +
'}'
].join('\n'),
parser: 'babel-eslint',
parserOptions: parserOptions
}, {
code: [
'const FunctionalComponent = (props) => {' +
Expand Down

0 comments on commit 046a723

Please sign in to comment.