Skip to content

Commit 32b48d4

Browse files
authored
Merge pull request scalameta#982 from olafurpg/976
Fix off-by-one error, scalameta#976.
2 parents dd47430 + 1922203 commit 32b48d4

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

scalafmt-core/shared/src/main/scala/org/scalafmt/config/Settings.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ trait Settings {
9393

9494
// TODO(olafur) move these elsewhere.
9595
val testing = default.copy(
96+
maxColumn = 79,
9697
assumeStandardLibraryStripMargin = false,
9798
includeCurlyBraceInSelectChains = false,
9899
align = default.align.copy(tokens = Set.empty),
@@ -106,11 +107,10 @@ trait Settings {
106107
runner = conservativeRunner
107108
)
108109
val unitTest80 = testing.copy(
109-
maxColumn = 80,
110110
continuationIndent = ContinuationIndent(4, 4)
111111
)
112112

113-
val unitTest40 = unitTest80.copy(maxColumn = 40)
113+
val unitTest40 = unitTest80.copy(maxColumn = 39)
114114

115115
def oneOf[T](m: Map[String, T])(input: String): Configured[T] =
116116
m.get(input.toLowerCase()) match {

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/State.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object State {
100100
}
101101
val newPolicy: PolicySummary = policy.combine(split.policy, tok.left.end)
102102
val splitWithPenalty = {
103-
if (columnOnCurrentLine < style.maxColumn || {
103+
if (columnOnCurrentLine <= style.maxColumn || {
104104
val commentExceedsLineLength =
105105
tok.right.is[Comment] &&
106106
tokRightSyntax.length >= (style.maxColumn - newIndent)

scalafmt-tests/src/test/resources/binPack/LiteralList.stat

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
binPack.literalArgumentLists = true
2+
maxColumn = 79
23
<<< basic
34
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)
45
>>>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
style = default
2+
<<< n-th column is OK, #975
3+
object Wat {
4+
val a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
5+
}
6+
>>>
7+
object Wat {
8+
val a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
9+
}

scalafmt-tests/src/test/resources/test/ContinuationIndent.stat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
continuationIndent.callSite = 5
22
continuationIndent.defnSite = 3
33
continuationIndent.extendSite = 2
4-
maxColumn = 40
4+
maxColumn = 39
55
<<< #143
66
def foo(
77
a: Int,

scalafmt-tests/src/test/resources/test/DynamicStyle.stat

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ indentOperator.exclude = ":\\+:"
55
align.tokens.add = [foo]
66
<<< dynamic
77
// scalafmt: { maxColumn = 20 }
8-
function(aaaaaaaaaa, bbbbbbb)
8+
function(aaaaaaaaaaa, bbbbbbb)
99
>>>
1010
// scalafmt: { maxColumn = 20 }
1111
function(
12-
aaaaaaaaaa,
12+
aaaaaaaaaaa,
1313
bbbbbbb)
1414
<<< multiline
1515
/*
1616
scalafmt: {
1717
maxColumn = 20
1818
}
1919
*/
20-
function(aaaaaaaaaa, bbbbbbb)
20+
function(aaaaaaaaaaa, bbbbbbb)
2121
>>>
2222
/*
2323
scalafmt: {
2424
maxColumn = 20
2525
}
2626
*/
2727
function(
28-
aaaaaaaaaa,
28+
aaaaaaaaaaa,
2929
bbbbbbb)
3030
<<< align.tokens.add
3131
{

scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ trait HasTests extends FunSuiteLike with FormatAssertions {
126126
spec match {
127127
case "unit" => ScalafmtConfig.unitTest40
128128
case "default" | "standard" | "scala" => ScalafmtConfig.unitTest80
129-
case "scalajs" => ScalafmtConfig.scalaJs
129+
case "scalajs" => ScalafmtConfig.scalaJs.copy(maxColumn = 79)
130130
case style => throw UnknownStyle(style)
131131
}
132132

0 commit comments

Comments
 (0)