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

Space before context bound colon only when there is more than one #916

Closed
durban opened this Issue Apr 29, 2017 · 3 comments

Comments

2 participants
@durban

durban commented Apr 29, 2017

Feature request: space before context bound colon only when there is more than one

  • Version: 0.6.8
  • Integration: sbt
  • Configuration: default

Problem

Scalafmt formats code like this:

final class Test[A: Monoid] {}
final class More[A: Monoid: Eq] {}
final class Sup[A <: Foo: Eq] {}
final class Sub[A >: Foo: Eq] {}
final class Lot[A >: Foo: Eq: Monoid] {}

With spaces.beforeContextBoundColon = true it formats code like this:

final class Test[A : Monoid] {}
final class More[A : Monoid : Eq] {}
final class Sup[A <: Foo : Eq] {}
final class Sub[A >: Foo : Eq] {}
final class Lot[A >: Foo : Eq : Monoid] {}

Expectation

I would like the formatted output to look like this:

final class Test[A: Monoid] {}
final class More[A : Monoid : Eq] {}
final class Sup[A <: Foo : Eq] {}
final class Sub[A >: Foo : Eq] {}
final class Lot[A >: Foo : Eq : Monoid] {}

That is, I would not like a space before a context bound colon if and only if the type parameter has only one bound. If it has more than one bound (any kind, not just context), I would like a space before the context bound colon.

Notes

This preference was already mentioned here in #180, but it seems it wasn't implemented.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Apr 29, 2017

Member

Thank you for reporting! I'm open to add an option for this, considering the interest from Gitter.

If someone wants to take a stab at this, a good place to start would be here

if (style.spaces.beforeContextBoundColon) Space else NoSplit

What would be a good name for this option?

Member

olafurpg commented Apr 29, 2017

Thank you for reporting! I'm open to add an option for this, considering the interest from Gitter.

If someone wants to take a stab at this, a good place to start would be here

if (style.spaces.beforeContextBoundColon) Space else NoSplit

What would be a good name for this option?

@durban

This comment has been minimized.

Show comment
Hide comment
@durban

durban May 4, 2017

Is it possible to make spaces.beforeContextBoundColon take an enum instead of a boolean? If yes, it could be something like always (the current true), never (the current false) and ifMultipleBounds, for example.

durban commented May 4, 2017

Is it possible to make spaces.beforeContextBoundColon take an enum instead of a boolean? If yes, it could be something like always (the current true), never (the current false) and ifMultipleBounds, for example.

hejfelix pushed a commit to hejfelix/scalafmt that referenced this issue May 31, 2017

hejfelix pushed a commit to hejfelix/scalafmt that referenced this issue May 31, 2017

olafurpg added a commit that referenced this issue May 31, 2017

Merge pull request #956 from hejfelix/master
#916 Add option to space context bounds only when multiple. ReaderUti…
@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Jul 9, 2017

Member

This was fixed in #956

Member

olafurpg commented Jul 9, 2017

This was fixed in #956

@olafurpg olafurpg closed this Jul 9, 2017

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