Skip to content

Commit

Permalink
Update scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Form…
Browse files Browse the repository at this point in the history
…atWriter.scala

Co-authored-by: Albert Meltzer <7529386+kitbellew@users.noreply.github.com>
  • Loading branch information
dos65 and kitbellew authored Jan 28, 2022
1 parent 1d9798e commit d57be51
Showing 1 changed file with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -995,27 +995,16 @@ class FormatWriter(formatOps: FormatOps) {
val offsetOpt =
if (isRelative) None
else {
val spaces = code
.filter(_.nonEmpty)
.flatMap { x =>
val matcher = docstringLeadingSpace.matcher(x)
if (matcher.lookingAt()) {
val leadingSpaces = matcher.end()
Some(leadingSpaces)
} else
None
}

if (spaces.nonEmpty) {
val minSpaces = spaces.min
val offset = minSpaces - termIndent.length()
val out =
if (offset > 0)
(getIndentation(offset), minSpaces)
else
("", minSpaces)
Some(out)
} else None
val minSpaces = code.foldLeft(Int.MaxValue) { (res, x) =>
val matcher = docstringLeadingSpace.matcher(x)
if (matcher.lookingAt()) math.min(res, matcher.end())
else res
}
if (minSpaces < Int.MaxValue) {
val offset = minSpaces - termIndent.length()
val spaces = if (offset > 0) getIndentation(offset) else ""
Some((spaces, minSpaces))
} else None
}

appendBreak()
Expand Down

0 comments on commit d57be51

Please sign in to comment.