You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this has been posted before, I looked and couldn't find anything in existing issues.
Proposal
Tweak the AST to be able to recognize the difference between a flow comment and runtime code, so that auto-fixing doesn't overwrite flow comments into runtime code.
For example, Prettier has had this issue open for this for quite a while: prettier/prettier#3493
The "workaround" has been to use babel's parser, which by default doesn't enable the flow comment syntax.
I'm looking to start supporting linting of flow comments just like we do flow typings with babel-eslint by enabling babel's flowComments parser plugin (some discussion in babel/babel#11423). Though, the same issue with prettier would present itself here, and would mean any autofixing rules for types would need to be disabled altogether.
Use case
Currently, the AST doesn't give any information about a node coming from a flow comment. Here's an example of a typing (link) being converted turned into a flow comment (link):
Ideally, there would be something in this AST to tell the difference between flow comments and flow typings, so that linters/auto-fixers can be aware and not overwrite the comments.
I think it would be useful if there was just a FlowComment node that had all nodes within it as child nodes, since auto-fixers generally respect the structure of the AST when rewriting the code.
Separate to that, I think it would be neat if we had a flag on each node within a flow comment like a boolean flowComment key. This is so that we can actually start creating lint rules specific to flow comments, which would be very cool. For example, a "no-flow-comments" rule or a version of "no-using-comment-vars" that prevents variables declared inside flow comments from being used outside of flow comments.
Example:
{"type": "TypeAlias","flowComment": true,// ...}
The text was updated successfully, but these errors were encountered:
Not sure if this has been posted before, I looked and couldn't find anything in existing issues.
Proposal
Tweak the AST to be able to recognize the difference between a flow comment and runtime code, so that auto-fixing doesn't overwrite flow comments into runtime code.
For example, Prettier has had this issue open for this for quite a while:
prettier/prettier#3493
The "workaround" has been to use
babel
's parser, which by default doesn't enable the flow comment syntax.I'm looking to start supporting linting of flow comments just like we do flow typings with
babel-eslint
by enablingbabel
'sflowComments
parser plugin (some discussion in babel/babel#11423). Though, the same issue with prettier would present itself here, and would mean any autofixing rules for types would need to be disabled altogether.Use case
Currently, the AST doesn't give any information about a node coming from a flow comment. Here's an example of a typing (link) being converted turned into a flow comment (link):
Ideally, there would be something in this AST to tell the difference between flow comments and flow typings, so that linters/auto-fixers can be aware and not overwrite the comments.
I think it would be useful if there was just a
FlowComment
node that had all nodes within it as child nodes, since auto-fixers generally respect the structure of the AST when rewriting the code.Example:
Separate to that, I think it would be neat if we had a flag on each node within a flow comment like a boolean
flowComment
key. This is so that we can actually start creating lint rules specific to flow comments, which would be very cool. For example, a "no-flow-comments" rule or a version of "no-using-comment-vars" that prevents variables declared inside flow comments from being used outside of flow comments.Example:
The text was updated successfully, but these errors were encountered: