Skip to content

Commit

Permalink
Verify function expression
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelnvk authored and ljharb committed May 8, 2019
1 parent 4012bee commit c4dd9d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/no-unused-class-component-methods.js
Expand Up @@ -58,7 +58,12 @@ module.exports = {
node.type === 'ClassProperty' &&
node.value.type === 'ArrowFunctionExpression'
);
return isMethod || isArrowFunction;
const isFunctionExpression = (
node.type === 'ClassProperty' &&
node.value.type === 'FunctionExpression'
);

return isMethod || isArrowFunction || isFunctionExpression;
};
const checkMethods = node => {
const properties = astUtil.getComponentProperties(node);
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/rules/no-unused-class-component-methods.js
Expand Up @@ -228,6 +228,19 @@ ruleTester.run('no-unused-class-component-methods', rule, {
}
`,
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
action = function() {
console.log('error');
}
render() {
return <button onClick={() => this.action()}>Click</button>;
}
}
`,
parser: 'babel-eslint'
}
],

Expand Down Expand Up @@ -352,6 +365,24 @@ ruleTester.run('no-unused-class-component-methods', rule, {
line: 3,
column: 11
}]
},
{
code: `
class Foo extends React.Component {
action = function() {
console.log('error');
}
render() {
return null;
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Unused method "action" of class "Foo"',
line: 3,
column: 11
}]
}
]
});

0 comments on commit c4dd9d0

Please sign in to comment.