Scalafmt v1.6.0-RC1
Pre-releaseThis 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 beforeIn 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 + 1Trailing 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 📘
- #1164 by @rockjam Add section about scalafmt support in mill http://www.lihaoyi.com/mill/page/configuring-mill.html#reformatting-your-code
- #1165 Update installation instructions for using scalafmt with Maven
- #1155 by @mads-hartmann Reorganise the documentation for configuration options
- #1156 by @mads-hartmann Fix the full-width example styling
- #1163 by @mads-hartmann Render the used config values as part of formatting examples
- (WIP) #1199 by @gabro Migrate the website to Docusaurus and tut. Feedback and help welcome!
- #1177 by @olafurpg Add more examples for standalone library usage
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 doublesIt'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 🌞
- #1186 by @olafurpg Print out unified diff on --test failure.
- #1185 by @olafurpg Pretty-print parse error more nicely.
- #1189 by @olafurpg Clean up handling of exit codes in the cli
Other highlights 🌷
- #1154 by @mads-hartmann Make it configurable when to exclude dangling parens for vertical
- #1169 by @iantabolt, allow with-chain wrapping for all params
- #1188 by @slavaschmidt Add option
spaces.afterSymbolicDef - #1187 by @slavaschmidt Force blocks in try / finally to format on multiple lines
- #1181 by @olafurpg Fix indent for nested infix operators
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.