fix(comments): preserve comments #68
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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.
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:
JavaScript doesn’t support this syntax:
To preserve code validity I couldn’t think of anything better than to convert multiline comments to single-line ones:
Thanks.