-
Notifications
You must be signed in to change notification settings - Fork 277
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
Router: disallow breaks in args in binpack=oneline #3067
Conversation
@sjrd @ekrich please verify that this addresses: scala-js/scala-js#4522 (comment) |
Yes, that looks perfect. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question, but otherwise LGTM
@sjrd let me do another iteration, so that we don't have to come back to this later. first, can you describe the binpack rule for definitions? so far, we focused on method calls, but what about parameters of a second, coming back to one-argument case:
@tgodzik made a really good observation about the test, and while i explained it away, i don't think that that was the intention, since the code forces a single line block only until a comma, which means multiple arguments. so, just want to be very sure about this. |
@sjrd for the examples above, please imagine they are taking 3 or more lines, since we can't implement the two-line custom rule you mentioned once before. |
For definition site:
Normally, none of those would be OK. But there is another rule, which I'm sure I explained somewhere, and I think you implemented it, because in the Scala.js PR and its diff I see this for example emitted by scalafmt: Some(genApplyStatic(implMethodSym,
js.This()(currentClassType) :: jsParams.map(_.ref))) which is good. The rule is that, if there is one spot, after a That rule is what keeps most binpacking code fairly tight-fitted. One often needs two physical lines for a logical one. But it's comparatively rare that one needs 3 lines or more, so the more explosive (in terms of line count but also in terms of formatter search space) situations do not come up so often. I think it is that rule that was applied in the formatting of when(audienceService.publish(any[Tenant], any[Int])).thenReturn(Success[NonEmptyList[String],
ApiAudience](apiAudience.copy(status = AudienceStatus.Pending.name))) (although it was not meant to apply within type parameters 🤷♂️ ) With that rule, the following of your examples is OK: val foo = foo(foo(bar,
bar)) but the others are not OK because it's not after a val foo = foo(
bar && bar)
val foo = foo(foo( // this is a break allowed by the above rule
bar && bar))
val foo = foo(
foo(
"""
bar""")) That said, it's not really an issue if scalafmt doesn't follow that by default. In my experience, it has been possible to nudge it into not splitting in bad places like that: if we write by hand correctly, then scalafmt tends to preserve it. It's OK if scalafmt lets me write the correct thing, even if I have to nudge it into doing it. What is annoying is when it forces a bad formatting and prevents from writing the right thing (like the case with the |
i didn't implement the rule as you mention, with two lines and a comma. i simply didn't force anything with one argument, even if multiline. should i change it now, or are you ok with forced break only if there are multiple arguments? as you said, you don't expect three lines in most cases. |
Ah, that's interesting! Perhaps it's good enough as is. |
great, then we'll keep it, and force only with multiple arga. I'll do another look over the code before merging, then. |
Fix bug in binpack=oneline implementation: - handling of the first arg is different from subsequent ones (which uses a single-line block no-split policy) - the single-line block policy must also exclude multiline strings.
Fix bug in binpack=oneline implementation:
- handling of the first arg is different from subsequent ones (which
uses a single-line block no-split policy)
- the single-line block policy must also exclude multiline strings.