Skip to content

Commit

Permalink
Test async functions and generators
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelnvk authored and ljharb committed May 8, 2019
1 parent 061d497 commit 4012bee
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rules/no-unused-class-component-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ module.exports = {
return isMethod || isArrowFunction;
};
const checkMethods = node => {
if (isNotComponent(node)) {
return;
}

const properties = astUtil.getComponentProperties(node);
let methods = properties
.filter(property => (
Expand Down Expand Up @@ -149,6 +145,10 @@ module.exports = {
const list = components.list();

Object.values(list).forEach(({ node }) => {
if (isNotComponent(node)) {
return;
}

checkMethods(node);
});
}
Expand Down
120 changes: 120 additions & 0 deletions tests/lib/rules/no-unused-class-component-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,56 @@ ruleTester.run('no-unused-class-component-methods', rule, {
}
`,
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
action = async () => {}
render() {
return <button onClick={this.action}>Click</button>;
}
}
`,
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
async action() {
console.log('error');
}
render() {
return <button onClick={() => this.action()}>Click</button>;
}
}
`,
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
* action() {
console.log('error');
}
render() {
return <button onClick={() => this.action()}>Click</button>;
}
}
`,
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
async * action() {
console.log('error');
}
render() {
return <button onClick={() => this.action()}>Click</button>;
}
}
`,
parser: 'babel-eslint'
}
],

Expand Down Expand Up @@ -232,6 +282,76 @@ ruleTester.run('no-unused-class-component-methods', rule, {
line: 3,
column: 11
}]
},
{
code: `
class Foo extends React.Component {
action = async () => {}
render() {
return null;
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Unused method "action" of class "Foo"',
line: 3,
column: 11
}]
},
{
code: `
class Foo extends React.Component {
async action() {
console.log('error');
}
render() {
return null;
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Unused method "action" of class "Foo"',
line: 3,
column: 11
}]
},
{
code: `
class Foo extends React.Component {
* action() {
console.log('error');
}
render() {
return null;
}
}
`,
parser: 'babel-eslint',
errors: [{
message: 'Unused method "action" of class "Foo"',
line: 3,
column: 11
}]
},
{
code: `
class Foo extends React.Component {
async * action() {
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 4012bee

Please sign in to comment.