Skip to content

Conversation

@Kristinita
Copy link
Contributor

1. Summary

eslint-plugin-prefer-arrow-functions with my changes preserves Flow comment types and their formatting.

My changes should fix the issue #24.

2. The reason for the need for the feature

Before my changes, eslint-plugin-prefer-arrow-functions removed all Flow comment types if a user ran ESLint with the argument --fix. It’s the critical problem for users using Flow comment-based syntax. Flow checks types inside comments.

I tested my changes in my real project with Flow comment types, and I can’t find cases of unexpected behavior.

3. Notes

  1. Not solely Flow users may need to preserve comments. I don’t know all the ways users add comments. Additional pull requests may be required.

  2. The plugin doesn’t preserve formatting if a user has a multiline comment before a fat arrow. In CoffeeScript, I use a syntax like this:

    loadPreviousMetadata = (metadataFilePath ###: string ###) ###:
      {[key: string]: {files: {[key: string]: number, timestamp: number}}}
    ### ->
      # Function body

    JavaScript doesn’t support this syntax:

    loadPreviousMetadata = (metadataFilePath/*: string */)/*:
    	{[key: string]: {files: {[key: string]: number, timestamp: number}}}
    */ => {
      // Function body
    };

    To preserve code validity I couldn’t think of anything better than to convert multiline comments to single-line ones:

    loadPreviousMetadata = (metadataFilePath/*: string */)/*: {[key: string]: {files: {[key: string]: number, timestamp: number}}} */ => {
      // Function body
    };

Thanks.

fix JamieMason#24

Signed-off-by: Kristinita <Kristinita@users.noreply.github.com>
Signed-off-by: Kristinita <Kristinita@users.noreply.github.com>
@Kristinita Kristinita force-pushed the KiraPreserveFlowAnnotationTypes branch from aeef4bf to 559b928 Compare December 29, 2025 09:57
…on body

test(comments): add more tests

refactor(comments): refactor the methods preserving comments

Signed-off-by: Kristinita <Kristinita@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant