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

Really long list, caveats inside #431

Closed
RatanRSur opened this Issue Sep 10, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@RatanRSur
Contributor

RatanRSur commented Sep 10, 2016

I understand that for many situations, since arguments are usually not the same length (not just a single char as in this case) a newline for every argument would definitely be the prettiest solution. I just wanted to report this because it's a situation where the default behavior seems a bit pathological and bin packing looks a lot better.

Original:

  val secret: List[Bit] = List(0,0,1,1,1,0,1,0,1,1,1,0,0,1,1,0,1,0,0,1,1,0,1,0,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,1,0,1,1,1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,1)

Scalafmt:

  val secret: List[Bit] = List(0,
                               0,
                               1,
                               1,
                               1,
                               0,
                               1,
                               0,
                               1,
                               1,
                               1,
                               0,
                               0,
                               1,
                               1,
                               0,
                               1,
                               0,
                               0,
                               1,
                               1,
                               0,
                               1,
                               0,
                               1,
                               1,
                               0,
                               0,
                               1,
                               1,
                               1,
                               1,
                               1,
                               0,
                               1,
                               0,
                               1,
                               1,
                               0,
                               0,
                               0,
                               0,
                               1,
                               0,
                               1,
                               1,
                               1,
                               0,
                               0,
                               1,
                               0,
                               0,
                               1,
                               0,
                               0,
                               0,
                               1,
                               0,
                               0,
                               0,
                               1,
                               0,
                               1)

I would like the input to look like this:

  val secret: List[Bit] = List(0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0,
                               1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1,
                               1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0,
                               0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1) 
@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Sep 19, 2016

Member

I agree this is unfortunate output. See #347 for related discussion. The scala.js style would format your example like this

object foo {
  def main(args: Array[String]) {
    val secret: List[Bit] = List(0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1,
        0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0,
        0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1)
  }
}

Making it align by the open parenthesis should be an easy fix (not implemented yet).

I don't think it's a good idea to make scalafmt "smarter" by guessing when to bin pack and when not to bin pack.

Your best shot for now is to use // format: off. #315 may give offer a slightly better solution but that feature is blocked by #316.

Member

olafurpg commented Sep 19, 2016

I agree this is unfortunate output. See #347 for related discussion. The scala.js style would format your example like this

object foo {
  def main(args: Array[String]) {
    val secret: List[Bit] = List(0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1,
        0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0,
        0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1)
  }
}

Making it align by the open parenthesis should be an easy fix (not implemented yet).

I don't think it's a good idea to make scalafmt "smarter" by guessing when to bin pack and when not to bin pack.

Your best shot for now is to use // format: off. #315 may give offer a slightly better solution but that feature is blocked by #316.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Sep 27, 2016

Member

0.4.0 introduces "dynamic styles" which allows you to specify configuration for a file or block of code, https://olafurpg.github.io/scalafmt/#0.4.1 Is that enough to close this issue?

I would love it if scalafmt could be smarter and automatically figure out when to use bin packing, but I'm afraid that any rule that we come up with will misbehave in some cases.

Member

olafurpg commented Sep 27, 2016

0.4.0 introduces "dynamic styles" which allows you to specify configuration for a file or block of code, https://olafurpg.github.io/scalafmt/#0.4.1 Is that enough to close this issue?

I would love it if scalafmt could be smarter and automatically figure out when to use bin packing, but I'm afraid that any rule that we come up with will misbehave in some cases.

@olafurpg

This comment has been minimized.

Show comment
Hide comment
@olafurpg

olafurpg Dec 20, 2016

Member

Good news! I was able to add a setting binPack.literalArgumentLists: Boolean which will automatically bin-pack argument lists if all arguments are literals. It's turned on by default with an exclusion rule for string literals. You can include/exclude the types of literals with

binPack.literalsInclude = [regex1]
binPack.literalsExclude = [regex2]

Give it a try in 0.5.0, once it's out, and let me know how you like it!

Member

olafurpg commented Dec 20, 2016

Good news! I was able to add a setting binPack.literalArgumentLists: Boolean which will automatically bin-pack argument lists if all arguments are literals. It's turned on by default with an exclusion rule for string literals. You can include/exclude the types of literals with

binPack.literalsInclude = [regex1]
binPack.literalsExclude = [regex2]

Give it a try in 0.5.0, once it's out, and let me know how you like it!

@RatanRSur

This comment has been minimized.

Show comment
Hide comment
@RatanRSur

RatanRSur Dec 21, 2016

Contributor

Thanks! I'll give it a shot

Contributor

RatanRSur commented Dec 21, 2016

Thanks! I'll give it a shot

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