Skip to content

More newlines in unit tests after updating to 3.8.0 #3800

@gijsbert802

Description

@gijsbert802

After updating from 3.7.17 to 3.8.0, the test code below now gets an additional newline in "example 1". It seems to be caused by newlines.topLevelBodyIfMinStatements = [before], but that wasn't the case in 3.7.x

Is this is a regression or is it by design?

Configuration (required)

version = 3.8.0

runner.dialect = Scala213Source3

maxColumn = 120

indentOperator.preset = akka-http

importSelectors = singleLine

trailingCommas = preserve

newlines.topLevelBodyIfMinStatements = [before]

rewrite {
  rules = [SortModifiers, Imports, PreferCurlyFors, AvoidInfix]
  sortModifiers.order = ["private", "protected", "implicit", "final", "sealed", "abstract", "override", "lazy"]
  imports.sort = scalastyle
}

continuationIndent {
  defnSite = 2
  extendSite = 2
  callSite = 2
}

align {
  arrowEnumeratorGenerator = false
  ifWhileOpenParen = false
  openParenCallSite = false
  openParenDefnSite = false

  tokens = ["%", "%%"]
}

Command-line parameters (required)

When I run scalafmt via CLI like this: scalafmt

Steps

Given code like this:

class DummyTest extends AnyWordSpecLike {

  private class Scope {
    // dummy for example 1
  }

  "Test" should {
    "example 1" in new Scope {
      val x = 1

      x shouldBe 1
    }

    "example 2" in {
      val x = 1

      x shouldBe 1
    }
  }
}

Problem

Scalafmt formats code like this:

class DummyTest extends AnyWordSpecLike {

  private class Scope {
    // dummy for example 1
  }

  "Test" should {
    "example 1, not ok" in new Scope {

      val x = 1

      x shouldBe 1
    }

    "example 2, ok" in {
      val x = 1

      x shouldBe 1
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions