Skip to content

Commit

Permalink
[Fix]: add arrow function to list of allowed position for component
Browse files Browse the repository at this point in the history
  • Loading branch information
jzabala committed Jul 11, 2020
1 parent e3e767b commit 0ecc48e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
3 changes: 2 additions & 1 deletion lib/util/Components.js
Expand Up @@ -668,7 +668,8 @@ function componentRule(rule, context) {
case 'AssignmentExpression':
case 'Property':
case 'ReturnStatement':
case 'ExportDefaultDeclaration': {
case 'ExportDefaultDeclaration':
case 'ArrowFunctionExpression': {
return true;
}
case 'SequenceExpression': {
Expand Down
66 changes: 47 additions & 19 deletions tests/lib/rules/no-this-in-sfc.js
Expand Up @@ -112,16 +112,6 @@ ruleTester.run('no-this-in-sfc', rule, {
};
}
}`
}, {
code: `
class Foo {
bar() {
() => () => {
this.something();
return null;
};
}
}`
}, {
code: `
class Foo {
Expand All @@ -131,15 +121,6 @@ ruleTester.run('no-this-in-sfc', rule, {
};
}`,
parser: parsers.BABEL_ESLINT
}, {
code: `
class Foo {
bar = () => () => {
this.something();
return null;
};
}`,
parser: parsers.BABEL_ESLINT
}, {
code: `
export const Example = ({ prop }) => {
Expand All @@ -151,6 +132,21 @@ ruleTester.run('no-this-in-sfc', rule, {
};
};`,
parser: parsers.BABEL_ESLINT
}, {
code: `
export const prepareLogin = new ValidatedMethod({
name: "user.prepare",
validate: new SimpleSchema({
}).validator(),
run({ remember }) {
if (Meteor.isServer) {
const connectionId = this.connection.id; // react/no-this-in-sfc
return Methods.prepareLogin(connectionId, remember);
}
return null;
},
});
`
}],
invalid: [{
code: `
Expand Down Expand Up @@ -217,6 +213,27 @@ ruleTester.run('no-this-in-sfc', rule, {
return <div onClick={onClick}>{this.props.foo}</div>;
}`,
errors: [{message: ERROR_MESSAGE}, {message: ERROR_MESSAGE}]
}, {
code: `
class Foo {
bar() {
return () => {
this.something();
return null;
}
}
}`,
errors: [{message: ERROR_MESSAGE}]
}, {
code: `
class Foo {
bar = () => () => {
this.something();
return null;
};
}`,
parser: parsers.BABEL_ESLINT,
errors: [{message: ERROR_MESSAGE}]
}, {
code: `
class Foo {
Expand All @@ -230,5 +247,16 @@ ruleTester.run('no-this-in-sfc', rule, {
}
}`,
errors: [{message: ERROR_MESSAGE}]
}, {
code: `
class Foo {
bar() {
() => () => {
this.something();
return null;
};
}
}`,
errors: [{message: ERROR_MESSAGE}]
}]
});

0 comments on commit 0ecc48e

Please sign in to comment.