Skip to content

Scalafmt v1.6.0-RC1

Pre-release
Pre-release

Choose a tag to compare

@olafurpg olafurpg released this 27 May 12:53
· 5297 commits to main since this release
c2e04be

This is the biggest Scalafmt release in over a year! If no issues are reported in the next week this release will be promoted to v1.6.0. The IntelliJ plugin is published in the "Nightly" channel instead of the typical "Stable" channel.

Clean issue tracker ✅

As part of an effort to triage Scalafmt issues, over 150 tickets have been closed since the last release. There are now "only" 19 open tickets! Around half of the closed tickets have been fixed in this release. The rest of the closed tickets were either closed due to inactivity or lack of actionable steps on how to fix them.

I did my best to respond to every issue with an explanation why it was closed. Please reopen if you think your ticket was unfairly closed and we can discuss how to best address the ticket.

New defaults 🆕

The following settings are now enabled by default

align.openParenCallSite = false // was true before
align.openParenDefnSite = false // was true before
danglingParentheses = true      // was false before

In summary, this implies the following change

// before
case class User(name: String,
                age: Int)
// after
case class User(
    name: String,
    age: Int
)

// before
List(
  libraryDependencies := List(
      "org" % "name" % "version",
      "org" % "name" % "version"),
  scalacOptions := List(
      "-Ywarn-unused-import",
      "-fatal-warning"))
// after
List(
  libraryDependencies := List(
      "org" % "name" % "version",
      "org" % "name" % "version"
  ),
  scalacOptions := List(
      "-Ywarn-unused-import",
      "-fatal-warning"
  )
)

For a larger example, see this diff from the jawn repo.

One additional benefit of this change is improved performance and fewer "Search state exploded" errors.

Thanks @dwijnand for starting this discussion in #1151.

Scalameta v4.0 ⬆️ ⬆️ ⬆️

PRs #1170 and #1145 by @olafurpg upgraded the Scalameta dependency from v1.7.0 to v4.0.0.
Upgrading Scalameta introduces a lot of nice improvements

  • Parsing and tokenizer bugs related to unicode handling are now fixed
  • Code splices inside XML literals are now formatted, previously they were left unchanged
  • We are getting close to supporting Scalafmt on native #1172
  • It will now be possible to use sbt-scalafmt and sbt-scalafix together without classpath conflicts
  • Simple function literals are now kept on a single line when possible
// before
(x: Int) =>
  x + 1
// after
(x: Int) => x + 1

Trailing commas 🔖

PR #1197 by @gabro added a new setting trailingCommas that can be used to enforce that trailing commas are either always used or never used. The default value is preserve that leaves trailing commas untouched. There is an ongoing vote in #1184 about changing the default.

Documentation 📘

Force numeric literal suffix 🔢

PR #1183 makes scalafmt forces that numeric literals use a consistent suffix

1l => 1L // uppercase L for longs 
1F => 1f // lowercase f for floats
1D => 1d // lowercase d for doubles

It's possible to configure this behavior with

literals.long = unchanged/upper/lower
literals.float = unchanged/upper/lower
literals.double = unchanged/upper/lower

Command-line improvements 🌞

Other highlights 🌷

The full list of merged PRs can be seen here https://github.com/scalameta/scalafmt/milestone/21?closed=1

Breaking changes ⚠️

The upgrade to Scalameta v4.0 changed the shape of the parsed syntax trees resulting in a couple of unavoidable breaking changes in the Scalafmt formatted output.
I ran scalafmt on a corpus of ~2 million lines of code and manually inspected the diff to make sure that the changed output did not introduce regressions. I did my best to make sure the new output is either unchanged or better than before. Please report an issue if you think v1.6 introduced a regression from v1.5.