Skip to content

Commit

Permalink
[fix] require-optimization: fix when using arrow function in class …
Browse files Browse the repository at this point in the history
…components
  • Loading branch information
jenil94 authored and ljharb committed Aug 17, 2019
1 parent 7bc55cc commit 57e2d72
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/require-optimization.js
Expand Up @@ -166,6 +166,10 @@ module.exports = {

return {
ArrowFunctionExpression(node) {
// Skip if the function is declared in the class
if (isFunctionInClass()) {
return;
}
// Stateless Functional Components cannot be optimized (yet)
markSCUAsDeclared(node);
},
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/rules/require-optimization.js
Expand Up @@ -118,6 +118,23 @@ ruleTester.run('react-require-optimization', rule, {
code: `
const obj = { prop: [,,,,,] }
`
}, {
code: `
import React from "react";
class YourComponent extends React.Component {
handleClick = () => {}
shouldComponentUpdate(){
return true;
}
render() {
return <div onClick={this.handleClick}>123</div>
}
}
`,
parser: parsers.BABEL_ESLINT,
errors: [{
message: MESSAGE
}]
}],

invalid: [{
Expand All @@ -142,6 +159,20 @@ ruleTester.run('react-require-optimization', rule, {
errors: [{
message: MESSAGE
}]
}, {
code: `
import React from "react";
class YourComponent extends React.Component {
handleClick = () => {}
render() {
return <div onClick={this.handleClick}>123</div>
}
}
`,
parser: parsers.BABEL_ESLINT,
errors: [{
message: MESSAGE
}]
}, {
code: `
import React, {Component} from "react";
Expand Down

0 comments on commit 57e2d72

Please sign in to comment.