Closed renato-bohler closed 4 months ago
While validating this plugin against a big codebase, I found an edge case where it auto-fixes incorrectly.
If the function has a dollar sign ($) on its body, it gets incorrectly transformed somehow.
$
export function foo() { const bar = '$'; return bar };
Gets transformed into an invalid syntax. Notice the lack of the dollar sign, the missing single quote, and the extra semicolon at the end:
export const foo = () => { const bar = '; return bar };;
If the dollar sign is in backticks:
export function foo() { const bar = `$`; return bar };
Then this happens:
export const foo = () => { const bar = `(PARAMS)RETURN_TYPE => ; return bar };;
(PARAMS)RETURN_TYPE => is leaking from the writeArrowFunction function somehow
(PARAMS)RETURN_TYPE =>
writeArrowFunction
https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/blob/9b76409f17deaa5d820c92adbb32cdc462fb3ec4/src/prefer-arrow-functions.ts#L137-L146
If there are two dollar signs, then the transformation is different, but still incorrect:
export function foo() { const bar = `$$`; return bar };
And this happens:
export const foo = () => { const bar = `const foo = ; return bar };;
No idea why that happens, so I'd have to investigate. Probably need to escape $ when replacing or something?
I just need time to look into that.
haha wow, this is an interesting one.
Description
While validating this plugin against a big codebase, I found an edge case where it auto-fixes incorrectly.
If the function has a dollar sign (
$
) on its body, it gets incorrectly transformed somehow.Example 1
Gets transformed into an invalid syntax. Notice the lack of the dollar sign, the missing single quote, and the extra semicolon at the end:
Example 2
If the dollar sign is in backticks:
Then this happens:
(PARAMS)RETURN_TYPE =>
is leaking from thewriteArrowFunction
function somehowhttps://github.com/JamieMason/eslint-plugin-prefer-arrow-functions/blob/9b76409f17deaa5d820c92adbb32cdc462fb3ec4/src/prefer-arrow-functions.ts#L137-L146
Example 3
If there are two dollar signs, then the transformation is different, but still incorrect:
And this happens:
Suggested Solution
No idea why that happens, so I'd have to investigate. Probably need to escape
$
when replacing or something?Help Needed
I just need time to look into that.