-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
I'm very excited to have this great new rule! Thank you @ngtan and @ljharb!
Unfortunately I've encountered a bug in the auto-fix code. The following test case demonstrates an error:
{
code: `
class Hello extends React.Component {
render = () => <div />
}
`,
features: ['class fields'],
errors: [{ message: 'render is a React lifecycle method, and should not be an arrow function or in a class field. Use an instance method instead.' }],
output: `
class Hello extends React.Component {
handleEventMethods = () => {}
render() { return <div />; }
}
`,
},AssertionError [ERR_ASSERTION]: A fatal parsing error occurred in autofix.
Error: Parsing error: Unexpected token <
Autofix output:
class Hello extends React.Component {
handleEventMethods = () => {}
render() <div />
}
The rule fix only really acts to modify the () part of the ArrowFunctionExpression. It does not touch the rest. In this case the body is an Expression and needs to be transformed into a BlockStatement+ReturnStatement.
I'd take a crack at this but my eslint ast modification is pretty weak (have some experience in jscodeshift)