Skip to content

v2.5.0

Choose a tag to compare

@github-actions github-actions released this 30 Apr 20:56

Major changes

Managed formatting modes

We are defining the newlines.source parameter (see https://scalameta.org/scalafmt/docs/configuration.html#newlinessource), which introduces managed, wholesale changes to how code is formatted. One of the options (keep) is intended to hand control over line breaks to the user, while the other two (fold and unfold) will in fact completely ignore user input.

These modes are new and will potentially have a few bugs here and there (especially keep), in addition to, possibly, causing mixed sentiment of the "this looks almost good, if only we could do this differently" type. That is expected and likely par for the course for an opinionated formatter that scalafmt was intended to be.

However, please submit your bugs and opinions via https://github.com/scalameta/scalafmt/issues/new or comment on existing ones, so that if there are ideas on how to modify the behaviour in a way that resonates with the community, without violating the constraints (for fold/unfold, user input must be ignored), we'll implement them.

Editions

Editions were envisioned as a way to allow formatter upgrades while preserving formatting behaviour, but this turned out to be substantially harder to do, so edition 2020-01 is the last one. Also, the same result can easily be accomplished by not upgrading the formatter.

File overrides

One can customize configuration to apply to a subset of files, based on a file pattern. Cases can include special formatting rules for sbt files, or others for test suites (for instance, using AvoidInfix rewrite for main code with an empty rewrite.neverInfix.excludeFilters while allowing special scalatest DSL for tests with rewrite.neverInfix.excludeFilters containing should etc.).

See https://scalameta.org/scalafmt/docs/configuration.html#fileoverride

Infix formatting

Formatting line breaks around infix expressions turned out to be a difficult problem, and a couple of years ago scalafmt gave up on that and let the user choose where to break. Here, we are definining a couple of parameters to try and take that control back, by adding newlines after an infix operator (as the only universally safe place; there are some cases when a break can happen before an infix operator, but those are rare, and this logic doesn't attempt to discern them).

See https://scalameta.org/scalafmt/docs/configuration.html#newlinesafterinfix

Presets

This is not a new setting but a new, more general way to specify groups of parameters. Previously, you'd use style = defaultWithAlign or align = most or danglingParentheses = true. However, because configuration is represented using HOCON/json, doing it like that meant one couldn't partially override these presets.

The new approach is to define preset = defaultWithAlign, or align.preset = most, or danglingParentheses.preset = true. This way, naming is standardized, and partial overrides are possible.

Please see https://scalameta.org/scalafmt/docs/configuration.html#presets.

Alignment

The major additions, apart from several bug fixes, are

Formatting around implicit and dangling

This was handled in fixed way in classic formatting mode while had some control in verticalMultiline mode. We brought those styles together, by adding a few parameters to control the outcome.

Please see:

Indentation

We added several new options to control indentation:

Top-level statements

In addition to enforcing breaks before top-level statements, we now allow the same after the top-level statements. Also, there's a more granular control of which top-level statements are considered. Please see https://scalameta.org/scalafmt/docs/configuration.html#newlinestoplevelstatements

Rewrites

Literals

A number of new parameters is available to control formatting of numeric literals. Please see https://scalameta.org/scalafmt/docs/configuration.html#literals.

Defaults

The following are changes in default behaviour:

Pull Requests since v2.5.0-RC3