Skip to content

Commit

Permalink
Fix off-by-one error, scalameta#976.
Browse files Browse the repository at this point in the history
Interestingly, this had not been pointed out before.
  • Loading branch information
olafurpg committed Jun 17, 2017
1 parent 978c350 commit 2f2f86d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Expand Up @@ -93,6 +93,7 @@ trait Settings {

// TODO(olafur) move these elsewhere.
val testing = default.copy(
maxColumn = 79,
assumeStandardLibraryStripMargin = false,
includeCurlyBraceInSelectChains = false,
align = default.align.copy(tokens = Set.empty),
Expand All @@ -106,11 +107,10 @@ trait Settings {
runner = conservativeRunner
)
val unitTest80 = testing.copy(
maxColumn = 80,
continuationIndent = ContinuationIndent(4, 4)
)

val unitTest40 = unitTest80.copy(maxColumn = 40)
val unitTest40 = unitTest80.copy(maxColumn = 39)

def oneOf[T](m: Map[String, T])(input: String): Configured[T] =
m.get(input.toLowerCase()) match {
Expand Down
Expand Up @@ -100,7 +100,7 @@ object State {
}
val newPolicy: PolicySummary = policy.combine(split.policy, tok.left.end)
val splitWithPenalty = {
if (columnOnCurrentLine < style.maxColumn || {
if (columnOnCurrentLine <= style.maxColumn || {
val commentExceedsLineLength =
tok.right.is[Comment] &&
tokRightSyntax.length >= (style.maxColumn - newIndent)
Expand Down
1 change: 1 addition & 0 deletions scalafmt-tests/src/test/resources/binPack/LiteralList.stat
@@ -1,4 +1,5 @@
binPack.literalArgumentLists = true
maxColumn = 79
<<< basic
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)
>>>
Expand Down
@@ -1,7 +1,7 @@
continuationIndent.callSite = 5
continuationIndent.defnSite = 3
continuationIndent.extendSite = 2
maxColumn = 40
maxColumn = 39
<<< #143
def foo(
a: Int,
Expand Down
8 changes: 4 additions & 4 deletions scalafmt-tests/src/test/resources/test/DynamicStyle.stat
Expand Up @@ -5,27 +5,27 @@ indentOperator.exclude = ":\\+:"
align.tokens.add = [foo]
<<< dynamic
// scalafmt: { maxColumn = 20 }
function(aaaaaaaaaa, bbbbbbb)
function(aaaaaaaaaaa, bbbbbbb)
>>>
// scalafmt: { maxColumn = 20 }
function(
aaaaaaaaaa,
aaaaaaaaaaa,
bbbbbbb)
<<< multiline
/*
scalafmt: {
maxColumn = 20
}
*/
function(aaaaaaaaaa, bbbbbbb)
function(aaaaaaaaaaa, bbbbbbb)
>>>
/*
scalafmt: {
maxColumn = 20
}
*/
function(
aaaaaaaaaa,
aaaaaaaaaaa,
bbbbbbb)
<<< align.tokens.add
{
Expand Down
Expand Up @@ -126,7 +126,7 @@ trait HasTests extends FunSuiteLike with FormatAssertions {
spec match {
case "unit" => ScalafmtConfig.unitTest40
case "default" | "standard" | "scala" => ScalafmtConfig.unitTest80
case "scalajs" => ScalafmtConfig.scalaJs
case "scalajs" => ScalafmtConfig.scalaJs.copy(maxColumn = 79)
case style => throw UnknownStyle(style)
}

Expand Down

0 comments on commit 2f2f86d

Please sign in to comment.