-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Style/AndOr gets confused about autocorrect #1255
Comments
I think perhaps the autocorrect should look at both possibilities before deciding to fail |
I agree. There's something not quite right here. I think the problem is that Anyway it seems that a bit of context is needed when parsing |
@jonas054 Yes, it seems that the parser interprets the |
The code that evaluates whether the AST has changed is in No, it's better to compare a larger scope, as you also suggest. I think we can find a way to do that, even though there is no direct reference to the parent node in each node. |
Here you go, sir - whitequark/parser#111. |
@bbatsov Thanks! I still had problems crafting an acceptable solution, even with that bit of help. Luckily I came up with a quite simple fix that we can use instead. Today, we're creating the new source code, build the AST and compare it against the existing node. This doesn't always work, as @vrthra noticed, becuase the existing node is affected by its context. So instead of trying to replicate that context for the rewritten code, we remove it for the existing node. You'll see the details in an upcoming pull request. |
[Fix #1255] Compare without context in AutocorrectUnlessChangingAST
Style/AndOr gets confused when presented with a fragment such as
And refuses to autocorrect, while happly autocorrects if we pass in
It appears that the parser parses
a || b
aswhile it parses the
a or b
in the above expression asOn the other hand, if I change the definition to
def z
, the parsed expressions are fora or b
and
a || b
However, I don't see why having a def of the variables should result in a different result.
The text was updated successfully, but these errors were encountered: