Stay up to date on releases
Create your free account today to subscribe to this repository for notifications about new releases, and build software alongside 40 million developers on GitHub.
Sign up for free See pricing for teams and enterprises
release-drafter
released this
Thanks to the heroic efforts of @kitbellew, a lot of longstanding formatting quirks have been fixed in this release. If no issues are reported before December 4th, then this release will be promoted to v2.3.0.
Lambda parameters no longer force a newline
Previously, Scalafmt would force a newline before lambda parameters inside parentheses like this.
List(1).map(
x =>
someOperation(x)
.map(fn)
.collect { ... })
Now, Scalafmt puts the parameter on the same line as the opening parenthesis
List(1).map(x =>
someOperation(x)
.map(fn)
.collect { ... })
Example diffs from the wild
For more examples, see the huge diff in kitbellew/scala-repos@0ea4865?diff=unified
try/finally format similarly to if/else now
Previously, Scalafmt formatted try/finally in a funny way, see #350. Now, try/finally blocks format the same way as if/else.
One example:
// original
val template: String = try source.mkString finally source.close()
// before (old behavior)
val template: String = try source.mkString
finally source.close()
// after (new behavior)
val template: String =
try source.mkString
finally source.close()
For more example, see the huge diff in kitbellew/scala-repos@6199bb3?w=1&diff=unified
Native images for macOS and Linux
Our CI now builds native scalafmt
binaries with instant startup and fast performance for short-lived runs. Download scalafmt-macos.zip
and scalafmt-linux.zip
in this release to try it out. To download a native binary for any pull request or merged commit in master open the "Actions" section on GitHub (https://github.com/scalameta/scalafmt/actions) and download from the "Artifacts" tab under a given CI run
Big thanks to @mroth for creating https://github.com/mroth/scalafmt-native, which was the inspiration for this feature!
Steady performance improvements
The performance of Scalafmt has consistently improved over recent releases. The same benchmark formatting a ~4665 line file now completes in 0.63x of the time with v2.3.0 compared to v1.5.1 (which was released in April 2018).
# v2.3.0 (this release)
[info] Micro.ExtraLarge.scalafmt avgt 30 831.742 ± 49.979 ms/op
# v2.2.1
[info] Micro.ExtraLarge.scalafmt avgt 30 901.238 ± 10.708 ms/op
# v2.1.1
[info] Micro.ExtraLarge.scalafmt avgt 30 1262.053 ± 24.818 ms/op
# v1.5.1
[info] Micro.ExtraLarge.scalafmt avgt 30 1314.987 ± 47.105 ms/op
Staying on the old formatting behavior
To preserve the formatting behavior of the previous release, add the following to .scalafmt.conf
edition = 2019-10
The edition
setting exists to allow users to upgrade to the latest Scalafmt version while keeping the old formatting output. We always recommend upgrading to the latest Scalafmt to enjoy performance improvements and the latest fixes in the parser. We encourage everybody to stay on the latest edition in order to enjoy the latest improvements in formatting output.
Please report issues if you encounter unwanted formatting changes when upgrading Scalafmt without upgrading the edition.
Pull Requests
- Setup GitHub Actions to generate native images (#1561) @olafurpg
- Performance improvements (#1564) @olafurpg
- RedundantBraces: lambda braces to single-arg apply, remove arou… (#1563) @kitbellew
- Router: fix split rule after catch in try (#1562) @kitbellew
- Router: fix def body indent with a comment #1240 (#1556) @kitbellew
- Router: treat try/finally the same as if/else #350 (#1554) @kitbellew
- FormatWriter: insert newline after packages #1069 (#1555) @kitbellew
- Router: format lambda in 1-arg call as with braces (#1551) @kitbellew
- Remove irregular files, including symbolic links, from
git ls-files
. (#1559) @SamirTalwar - RedundantBraces: remove nested braces in lambda (#1549) @kitbellew
- Make it easier to test scalafmt local snapshot build (#1552) @tanishiking
- Revert avoidEmptyLinesAroundBlock feature (#1548) @poslegm