Skip to content

Conversation

@sabiwara
Copy link
Contributor

This PR adds the enforce_calls_on_right_hand_side_of option to the formatter as specified in #11811.

Note: I noticed a possible unintended consequence with this, which is that defining operators might trigger the formatter for arguments:

defmacro x |> f, do: foo(f, x)

# becomes

defmacro x |> f(), do: foo(f, x)

I managed to circumvent this by checking the :no_parens_arg context, but it feels a bit hacky and will still format the argument as f() in the following:

defmacro(x |> f, do: foo(f, x))

As far as I know, there is no difference at the AST level that we can use to distinguish an argument declaration from an expression, so is this approach good enough in practice? Or is there a better way?

@josevalim
Copy link
Member

As far as I know, there is no difference at the AST level that we can use to distinguish an argument declaration from an expression, so is this approach good enough in practice? Or is there a better way?

This is a very good call. This immediate false negative is let down. I will have to think a little bit how we want to move forward with this. Thanks for the PR! :)

@whatyouhide
Copy link
Member

Yeah, I don't see an easy way to fix the false positive in the operator definition 😞 We might have to drop this change, right. The PR is great in any case, thanks @sabiwara 🙃

@josevalim
Copy link
Member

Closing this for now then. If we have new ideas, I will let you know @sabiwara! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants