Skip to content

Commit

Permalink
FormatWriter: replace single-line mlc with slc
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 26, 2021
1 parent e7f4857 commit 9b5ada7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,12 @@ class FormatWriter(formatOps: FormatOps) {
val contents = text.substring(2).trim
val wordIter = splitAsIterator(slcDelim)(contents)
sb.append(if (useSlc) "//" else "/*")
iterWords(wordIter, appendLineBreak, getFirstLineLength)
if (!useSlc) sb.append(" */")
val curlen = sb.length
val lines = iterWords(wordIter, appendLineBreak, getFirstLineLength)
if (!useSlc)
if (lines == 0 && style.comments.wrapSingleLineMlcAsSlc)
sb.setCharAt(curlen - 1, '/')
else sb.append(" */")
}
}

Expand Down Expand Up @@ -773,8 +777,11 @@ class FormatWriter(formatOps: FormatOps) {
}
}
sb.append("/*")
iterSections(sectionIter, getFirstLineLength)
sb.append(" */")
val curlen = sb.length
val lines = iterSections(sectionIter, getFirstLineLength)
if (lines == 0 && style.comments.wrapSingleLineMlcAsSlc)
sb.setCharAt(curlen - 1, '/')
else sb.append(" */")
} else {
val trimmed = removeTrailingWhiteSpace(text)
sb.append(leadingAsteriskSpace.matcher(trimmed).replaceAll(spaces))
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/unit/Comment.stat
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ object a {
}
>>>
object a {
/* mlc */ /* foo bar */
/* mlc */ // foo bar
}
<<< wrap with empty first line 2
comments.wrap = trailing
Expand All @@ -438,7 +438,7 @@ object a {
}
>>>
object a {
/* mlc */ /* foo bar */
/* mlc */ // foo bar
}
<<< #2043
object a {
Expand Down

0 comments on commit 9b5ada7

Please sign in to comment.