eslint-plugin-prefer-arrow-functions icon indicating copy to clipboard operation
eslint-plugin-prefer-arrow-functions copied to clipboard

Removes comments and formatting

Open privatenumber opened this issue 1 year ago • 2 comments

Description

Input code:

function someFn(
	// comment a
	a,
    // comment b
    b,
) {}

Fixed code:

const someFn = (a, b) => {};

Suggested Solution

Preserve whitespace and comments

Help Needed

privatenumber avatar Dec 20 '23 13:12 privatenumber

It looks like getSourceCode() used to rewrite the function body is now deprecated and instead context.sourceCode should be used. Here is some documentation on how eslint API handles comments: https://eslint.org/docs/latest/extend/custom-rules#accessing-the-source-text

cornellouis avatar May 03 '24 20:05 cornellouis

In case you're interested, I ended up rolling my own solution which makes autofixes with more precision: https://github.com/privatenumber/lintroll/tree/develop/src/custom-rules/prefer-arrow-functions

privatenumber avatar May 04 '24 10:05 privatenumber

Thanks @privatenumber, closing as it looks like you have a nice solution.

JamieMason avatar Jan 09 '25 22:01 JamieMason