-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should refactoring for "Use guard" be disabled? #1165
Comments
Is it possible to make hlint keep attached comments instead? i.e. are they available during parsing in the ast? |
Is there some automatic way to figure out when a refactoring would lose comments and disable it automatically? In the same way we automatically disable a hint if it causes additional free variables. |
Ah that's a good idea. I think this can be done in apply-refact without modiyfing HLint, so I'll just close this issue. @googleson78 Yeah the comments are available in |
What exactly do you mean by this? |
@josephcsible - for match hints, we run the hint, and if the RHS had new free variables that the LHS didn't have, we assume variables got captured/uncaptured or otherwise screwed up, and don't make the suggestion. I think the suggestion is analogous to that - try it, if it appears to have gone wrong, don't do it. |
From a bug reported by @jneira in mpickering/apply-refact#93
The problem with "Use guard" refactoring is that it can lose comments, e.g.
The comments are lost because they are originally attached to
HsIf
nodes which don't appear in the output.In general, any hint that removes stuff can cause comments to be lost during refactoring, for instance
But "Use guard" is particularly bad because it is not uncommon for people to write comments above "if" and "else". This also means it is probably not a good idea to add specific logic for "Use guard" to save the comments; rather, it should be solved in a principled way.
@ndmitchell do you think the refactoring for "Use guard" should be turned off because of this, or is it still worth having it?
The text was updated successfully, but these errors were encountered: