JamieMason / eslint-plugin-prefer-arrow-functions

Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
MIT License
43 stars 11 forks source link

Removes comments and formatting #24

Open privatenumber opened 6 months ago

privatenumber commented 6 months ago

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

cornellouis commented 1 month ago

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

privatenumber commented 1 month ago

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