Skip to content

Commit

Permalink
Scalafmt: handle empty code differently
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 3, 2023
1 parent 0b6043b commit 36f2d16
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ object Scalafmt {
if (isWin) code.replaceAll(WinLineEnding, UnixLineEnding) else code
doFormat(unixCode, style, filename, range) match {
case Failure(e) => Formatted.Result(Formatted.Failure(e), style)
case Success(s) =>
case Success(x) =>
val s = if (x.isEmpty) UnixLineEnding else x
val asWin = style.lineEndings == LineEndings.windows ||
(isWin && style.lineEndings == LineEndings.preserve)
val res = if (asWin) s.replaceAll(UnixLineEnding, WinLineEnding) else s
Expand Down Expand Up @@ -136,7 +137,7 @@ object Scalafmt {
file: String,
range: Set[Range] = Set.empty
): Try[String] =
if (code.matches("\\s*")) Try("\n")
if (code.matches("\\s*")) Try("")
else {
val runner = style.runner
val codeToInput: String => Input = toInput(_, file)
Expand Down

0 comments on commit 36f2d16

Please sign in to comment.