Skip to content
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

No indentation after operator #216

Open
dhoepelman opened this issue Mar 22, 2016 · 5 comments
Open

No indentation after operator #216

dhoepelman opened this issue Mar 22, 2016 · 5 comments

Comments

@dhoepelman
Copy link

Akka HTTP uses a routing DSL in which routes are constructed as follows:

def route =
  route1 ~
  route2 ~
  route3 

Scalariform formats this as:

def route =
  route1 ~
    route2 ~
    route3 

This causes unnecessary indenting and less readability. Here's a larger example.

It would be very nice if an option was added to not indent when an expression continues on a new line after an operator.

@ktoso
Copy link
Contributor

ktoso commented Mar 22, 2016

Would indeed be nice if we could solve this (same applied to Spray back in the days, and also to the | operator).

I think it could be formulated as "do not indent when line ends with XXX call", perhaps having that XXX configurable?

@acjay
Copy link

acjay commented Apr 2, 2016

Perhaps another reason to prefer akka/akka#19678 :)

@ktoso
Copy link
Contributor

ktoso commented Apr 2, 2016

yes and no. akka/akka#19678 is not a magic bullet so let's not play it as one ;-)

@acjay
Copy link

acjay commented Apr 3, 2016

No, it's not a magic bullet. But it's possible that the hanging-indent behavior is desirable for most infix situations, but just not when the arguments themselves are really long, or multi-line, as they tend to be for Route. So:

val aggregatedResult =
  operand1 + operand2 + operand3 + operand4 +
    operand5 + operand6

Might make sense, but not so much:

val aggregatedResult = 
  bigOperation1(
    a + whole + lot + of + stuff,
    other + things) ~
  bigOperation2(
   whatever + else + is + left)

But one might also argue that the latter case is actually a poor fit for infix operators in the first place, as the infix operators get lost in the mix. AKA the reason for the Akka thought bubble in the first place. Right now, a missing ~ is not a compile error, but Scalariform will actually help you out by formatting the cases differently, tipping you off that something is wrong. So the desire for safe code and pretty code are in conflict.

@jkinkead
Copy link
Collaborator

I think it's a fairly reasonable enhancement to be able to specify "non-continuation" operators in a config.

This would be a fairly big change if it were made general-purpose, since there isn't a way to provide a string (or set of strings) to a preference setting at the moment.

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

No branches or pull requests

4 participants