Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Optimization breaks when using arrow function Fix #2385

Merged
merged 1 commit into from Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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