Releases: scalameta/scalafmt
v2.5.0-RC2
Pull Requests
- Binpack literals: allow simple expressions, too (#1902) @kitbellew
- FormatWriter: fix indent for complex interpolation (#1901) @kitbellew
- RedundantParens: support additional patterns (#1897) @kitbellew
- BinPack: allow single-line formatting of literals (#1900) @kitbellew
- #1627 [21]: Router: improve source=fold formatting of val/def (#1899) @kitbellew
- AvoidInfix: correctly determine when to wrap LHS (#1898) @kitbellew
- #1627 [20]: Router bugfix: binPack call rules: overflow, dangling parens (#1894) @kitbellew
- FormatOps: fix infix indent if followed by comment (#1893) @kitbellew
- Router: force indent before comment, not break (#1891) @kitbellew
- RedundantBraces: exclude nested partial function (#1890) @kitbellew
- Router: indent comments in the middle of a select (#1888) @kitbellew
- Presets: automatically decode all config builtins (#1886) @kitbellew
- ScalafmtConfig: move default40 into the test suite (#1885) @kitbellew
- FormatBenchmark: fix, use the correct parameter (#1884) @kitbellew
- Documentation: clarify glob pattern in the example (#1883) @kitbellew
- [docs] Pipe Bash script to Bash, not sh (#1880) @bsolomon1124
- Docs: Assembling and Executing New CLI Artifacts (#1879) @aarsenij
- Fix literals.double example (#1878) @xavierguihot
v2.5.0-RC1
TL;DR
This release candidate may be unstable but we will be grateful for early adoption and bug reports. More detailed release notes coming soon with stable release.
- Introduced experimental newlines.source setting
implicit
arguments formatting improvedtrailingCommas = multiple
introduced- Aligning improved
- More configuration for literals
Migration Guide
In this release changed default formatting of hex literals and literals in scientific notation. Currently hex digits and e
symbol will lowercased. More details is in the documentation. If you don't want large diff after scalafmt update, you can set
literals.hexDigits=unchanged
literals.scientific=unchanged
newlines.alwaysBeforeMultilineDef
may seem too aggressive now. You can disable it if you don't like newlines in diff newlines.alwaysBeforeMultilineDef=false
.
Usage Improvements
- CLI: add explicit flag --reportError to exit 1 on malformatted code (#1872) @kitbellew
- ScalafmtConfig: allow overriding per file pattern (#1865) @kitbellew
- Error.NoMatchingFiles: don't display a stack trace (#1860) @kitbellew
- ScalafmtConfig: define edition 2020-03 (#1733) @kitbellew
- Sunset editions (#1839) @olafurpg
Formatting Improvements
- #1627 [18]: FormatOps: ignore line breaks in infix expressions (#1855) @kitbellew
- TreeOps: use numParents for nestedApplies/Select (#1859) @kitbellew
- FormatOps: implement recursive findToken method (#1853) @kitbellew
- #1627 [17]: Several fixes for ApplyType, symbolic select, if in case clause (#1849) @kitbellew
- State: clarify how priority is determined (#1850) @kitbellew
- FormatOps: don't start a statement on a comment (#1846) @kitbellew
- TokenOps bugfix: logic for newline on docstring (#1834) @kitbellew
- Hide lambda body squashing under newlines.source=fold (#1832) @poslegm
- #1627 [14]: Router: single-line Defn lambda for fold only (#1810) @kitbellew
- #1627 [13]: Router: ignore line breaks in comma-separated args (#1808) @kitbellew
- #1627 [12]: Router: ignore line breaks in enumerators (#1806) @kitbellew
- #1627 [11]: Router: relax restrictions on breaks within interpolate (#1805) @kitbellew
- #1627 [10]: Router: ignore line breaks in select chains (#1796) @kitbellew
- #1627 [09]: Router: ignore line breaks in case clauses (#1793) @kitbellew
- #1627 [08]: Router: ignore line breaks in annotations (#1792) @kitbellew
- #1627 [07]: FormatOps: ignore line breaks in rhsOptimalToken (#1790) @kitbellew
- #1627 [06]: Router: ignore line breaks for config style apply (#1786) @kitbellew
- Router bugfix: handle implicit consistently (#1789) @kitbellew
- #1627 [05]: Router: ignore line breaks in def/val assignments (#1779) @kitbellew
- #1627 [04]: Router: ignore line breaks in if-else and bodies (#1778) @kitbellew
- Router: modify indent of case clauses consistently (#1776) @kitbellew
- #1627 [03]: Router: newlines.source=unfold for semicolons (#1774) @kitbellew
- #1627 [02]: Router: ignore line breaks for blocks (#1772) @kitbellew
- BestFirstSearch: check optimal token not to overflow (#1771) @kitbellew
- #1627 [01]: ScalafmtConfig: flag to ignore input line breaks (#1765) @kitbellew
- Alignment by right-side expression (#1759) @poslegm
- Align lines with different columns count (#1785) @poslegm
- Align strip margin: allow disabling the alignment (#1837) @kitbellew
- Preserve newlines in for comprehension generators and values (#1795) @poslegm
- Flexible literal formatting (#1857) @poslegm
- Router: remove unnecessary splits cache, used once (#1874) @kitbellew
- RedundantBraces: re-enable general expressions (#1873) @kitbellew
- Router: fix strip margin in interpolated strings (#1870) @kitbellew
- Newlines: allow break after top-level statements (#1864) @kitbellew
- Newlines: implicitParamListModifier to replace two (#1863) @kitbellew
- Router: remove currently unused comma split (#1763) @kitbellew
- VerticalMultiline: check config style (#1696) @kitbellew
- DanglingParentheses: move
exclude
list from VerticalMultiline (#1761) @kitbellew - Router: fix #1749, conflict with #1755 (#1760) @kitbellew
- Router: handle implicit in non-vertical-multiline (#1749) @kitbellew
- poorMansTrailingCommasInConfigStyle deprecation (#1758) @poslegm
- FormatWriter: do not rewrite {} => () around Defn (#1757) @kitbellew
- TrailingCommas: add the
multiple
option (#1755) @kitbellew - RedundantBraces: don't rewrite to parens if nested typed func (#1750) @kit@kitbellew ormatOps: find the exact param group for each "(" (#1745) @kitbellew
- Router: for multiple args, all or one on a line (#1743) @kitbellew
- FormatOps: in one-arg-per-line, handle lbrace case (#1722) @kitbellew
- Split: switch ignoreIf to tag, allows more control (#1737) @kitbellew
- BestFirstSearch: don't retry if didn't optimize (#1738) @kitbellew
Bugfixes
- Fixed AST changes after formatting variant types with symbolic name (#1762) @poslegm
- Router bugfix: extend line break past infix for any block (#1766) @kitbellew
- Router bugfix: regression in statement/comments (#1854) @kitbellew
- "// format: off" enabled for comments, literals, etc. (#1773) @poslegm
- Fixed contradiction between blankLineBeforeDocstring name and value (#1768) @poslegm
- Fixed newlines on NewAnonymous with empty arguments lambda (#1833) @poslegm
- Fixed alignment overriding (#1869) @poslegm
Documentation
- Documentation improvements (#1767) @poslegm
- Document config overriding functionality (#1781) @poslegm
- Dynamic configuration doc moved to "Disabling or customizing formatting" section (#1868) @poslegm
- Release notes for 2.5.0-RC1 to website (#1876) @poslegm
- Documentation: explain
newlines.topLevelStatements
(#1866) @kitbellew - #1627 [19]: Documentation: describe
newlines.afterInfix
(#1856) @kitbellew - #1627 [15]: Documentation: describe newlines.source (#1847) @kitbellew
- Documentation: add availability for recent params (#1862) @kitbellew
- Fixed unclear example for danglingParentheses in documentation (#1812) @poslegm
- Changelog updated (#1777) @poslegm
- AvoidInfix: simplify, fix incorrect rewrites (#1875) @kitbellew
- literals.* docs (#1867) @poslegm
Build and Code Health
- All tests moved into the scalafmt-tests package (#1807) @dkartashev
- GraalVM Native Image fix (#1791) @poslegm
- Various minor fixes to logging and tests (#1734) @kitbellew
- Test debug: create a debug instance per test (#1735) @kitbellew
- CI moved from Travis to GitHub Actions (#1732) @poslegm
- SBT_OPTS tuning (#1739) @poslegm
- CI tuning (#1751) @poslegm
- Fetch tags on CI (#1770) @poslegm
- All tests enabled on CI (and fixed) (#1784) @poslegm
- Add script to test that a release succeeded (#1782) @olafurpg
- Tests for already fixed SearchStateExploded error (#1527) (#1836) @poslegm
- Compiler warnings enabled (#1843) @poslegm
- Enforce Prettier formatting on markdown sources. (#1840) @olafurpg
- Minor refactoring to prepare for #1627 (#1764) @kitbellew
- #1627 [16]: ScalafmtConfig: refactor checking source errors (#1848) @kitbellew
- Debug: move printing debug info from FormatWriter (#1851) @kitbellew
Dependency Updates
- Scalameta update (#1780) @poslegm
- Upgrade to the latest Metaconfig (#1852) @olafurpg
- Update sbt-native-packager to 1.7.0 (#1827) @scala-steward
- Update sbt-native-packager to 1.6.2 (#1816) @scala-steward
- Update sbt-scalajs to 1.0.1 (#1818) @scala-steward
- Update sbt-mdoc to 2.1.5 (#1820) @scala-steward
- Update scalameta, testkit to 4.3.7 (#1823) @scala-steward
- Update scalafmt-core to 2.4.2 (#1822) @scala-steward
- Update scala-xml to 1.3.0 (#1819) @scala-steward
- Update sbt-mima-plugin to 0.7.0 (#1815) @scala-steward
- Update scalatest to 3.1.1 (#1824) @scala-steward
- Update sbt-scalafmt to 2.3.2 (#1821) @scala-steward
- Update scalatags to 0.8.6 (#1814) @scala-steward
- Update metaconfig-core, ... to 0.9.9 (#1813) @scala-steward
Scalafmt v2.4.2
Features
- RedundantBraces: add parensForOneLineApply flag (#1723) @kitbellew
Bug fixes
- BestFirstSearch: if failed without a solution, retry without optimization (#1731) @kitbellew
- BestFirstSearch: don't give up too soon (#1729) @kitbellew
- Documentation: describe a few important parameters (#1725) @kitbellew
- Router bugfix: find the correct lambda right arrow (#1719) @kitbellew
- FormatWriter: don't rewrite {} => () in assignment (#1715) @kitbellew
Fixes: #448 #1462 #1482 #1485 #1599 #1659 #1714 #1717 #1718 #1720
Pull Requests
- Release Drafter workflow (#1730) @poslegm
- TreeOps: structure the details of defns or calls (#1710) @kitbellew
- Various cleanup and refactoring changes in BestFirstSearch (#1728) @kitbellew
- Documentation: describe a few important parameters (#1725) @kitbellew
- Dummy parameter against github caches (#1727) @poslegm
- GraalVM to 20.0.0 (#1726) @poslegm
- FormatOps: extract methods to get func/case arrow (#1724) @kitbellew
- Update scalafmt-core to 2.4.1 (#1713) @scala-steward
Scalafmt v2.4.1
Scalafmt v2.4.0
Pull Requests
- Trailing commas bugfix: can't have trailing comma in
preserve
without a break (#1705) @kitbellew - A couple of bugfixes in handling of first arg after "(" (#1701) @kitbellew
- Various cleanup and refactor changes (#1700) @kitbellew
- Policy: add apply() with partial func in 2nd group (#1691) @kitbellew
- TreeOps: find a parent, avoid getting all parents (#1688) @kitbellew
- Tests: determine test's location, provide to Intellij (#1698) @kitbellew
- Router: extract simple T.Dot patterns before chain (#1689) @kitbellew
- Router: minor refactor for align vars in apply (#1690) @kitbellew
- Resource folder path resolution from classloader (#1692) @poslegm
Dependency updates
- Update sbt-scalajs-crossproject to 1.0.0 (#1695) @scala-steward
- Update metaconfig-core, ... to 0.9.8 (#1699) @scala-steward
Scalafmt v2.4.0-RC2
Edition 2020-01
Formatting and rewrite of single-line curly lambdas
Allow curly lambdas to format on a single line
RedundantBraces: Replace inner braces and parens with outer braces for single-line lambdas (previously, only multiline)
RedundantBraces: Format single-line curly lambdas using parens
Other apply and init rewrites
RedundantParens: Remove parens around an apply of block
RedundantBraces: Remove braces around an apply argument
RedundantBraces: Remove braces around a single-statement lambda in constructors
Don't force break before parameters of lambda as the only constructor argument
Fixes
Pull Requests
- Rewrites: traverse tree once, applying all rules (#1677) @kitbellew
- RewriteTrailingCommas: trivial, remove duplicate (#1679) @kitbellew
- RedundantBraces: use () for {} one-line lambdas (#1663) @kitbellew
- Router: treat single-arg lambda of init like apply (#1666) @kitbellew
- Scalafmt is supported by format-all for emacs (#1675) @sideshowcoder
- ScalafmtConfig: clean up unused code, move some to tests (#1674) @kitbellew
- ScalafmtConfig bugfix: read align tokens as seq, not set (#1673) @kitbellew
- Trailing commas: add a rewrite rule, remove first (#1669) @kitbellew
- RedundantParens: rewrite single-arg apply of block (#1665) @kitbellew
- Minor improvements to split, decision and policy logic (#1661) @kitbellew
- RedundantBraces: update method body rewrite rules (#1662) @kitbellew
- Router: allow single-line curly lambdas (#1660) @kitbellew
Dependency updates
- Update metaconfig-core, ... to 0.9.5 (#1685) @scala-steward
- Update sbt-mima-plugin to 0.6.4 (#1683) @scala-steward
- Update sbt-ci-release to 1.5.2 (#1684) @scala-steward
- Update scalatags to 0.8.5 (#1680) @scala-steward
- Update sbt-scalajs to 1.0.0 (#1676) @scala-steward
- Update sbt to 1.3.8 (#1672) @scala-steward
Scalafmt v2.4.0-RC1
Edition 2020-01
Line breaks
Allow breaks after assignment
Preserve line breaks before single-line comments when bin-packing
Breaks within a method call if a long single-line comment follows
Preserve single-line formatting for if/try: fixed issues #271 #1002 #1043
Fix formatting for lambda functions in infix expressions:
Avoid line-too-long in lambda functions:
Rewrite rules
- Abide by "no-format" tags when rewriting
- Fix rewrite rules for infix expressions
- Fix newline handling while rewriting, such as to preserve config-style formatting
Fixes
#271 #1002 #1043 #1413 #1506 #1547 #1592 #1624 #1631 #1633
Pull Requests
- Enable to download and run snapshot version from dynamic (#1656) @tanishiking
- Scalafmt bugfix: restore .format signatures while passing filename (#1654) @kitbellew
- Router bugfix: break on else, indent for block within case (#1652) @kitbellew
- Policy: always pass sourcecode.Line implicitly (#1651) @kitbellew
- State/FormatWriter: various optimizations and simplifications (#1647) @kitbellew
- SortModifiers: Use .syntax on tokens, not tree (#1649) @kitbellew
- RedundantBraces: fix various bugs with general expressions (#1635) @kitbellew
- Rewrite: rewrite patchsets unless any is no-format (#1625) @kitbellew
- Add headers for each invidiual editor that Metals supports. (#1629) @olafurpg
- add in a bit of documentation about Metals (#1617) @ckipp01
- FormatOps: check "new anonymous" in infix indent (#1626) @kitbellew
- Router bugfix: improve optimal token for assign (#1623) @kitbellew
- Router: preserve single-line formatting for if/try (#1560) @kitbellew
- FormatOps: consider comment for RHS optimal token (#1604) @kitbellew
- Don't silence stdout when it is the only output (#1622) @sideshowcoder
- Router bugfix: keep single-line comment split (#1614) @kitbellew
- Some performance optimizations for FormatToken (#1616) @kitbellew
- Various refactoring and simplification commits (#1615) @kitbellew
- Various bugfixes for single-arg apply of a lambda (#1612) @kitbellew
- Router: dangle only if breaking in multi-line lambda (#1600) @kitbellew
- FormatOps: allow break after assign in infixSplit (#1608) @kitbellew
Dependency updates
- Update paradise to 2.1.1 (#1620) @scala-steward
- Update sbt-native-packager to 1.6.1 (#1658) @scala-steward
- Update sbt-scalafmt to 2.3.1 (#1657) @scala-steward
- Update sbt-mdoc to 2.1.1 (#1621) @scala-steward
- Update interface to 0.0.17 (#1650) @scala-steward
- Update sbt-scalajs to 0.6.32 (#1642) @scala-steward
- Update sbt-native-packager to 1.6.0 (#1641) @scala-steward
- Update scalatags to 0.8.4 (#1636) @scala-steward
- Update sbt to 1.3.7 (#1634) @scala-steward
- Update scalatags to 0.8.3 (#1619) @scala-steward
- Update sbt to 1.3.6 (#1610) @scala-steward
- Update sbt-ci-release to 1.5.0 (#1613) @scala-steward
- Update sbt-mdoc to 2.1.0 (#1611) @scala-steward
- Update sbt to 1.3.5 (#1601) @scala-steward
- Update scalacheck to 1.14.3 (#1602) @scala-steward
- Update sbt-native-packager to 1.5.2 (#1598) @scala-steward
- Update scalafmt-core to 2.3.2 (#1597) @scala-steward
- Update sbt-scalafmt to 2.3.0 (#1596) @scala-steward
Scalafmt v2.3.2
Pull Requests
- Upgrade to Scalatest 3.1 (#1595) @olafurpg
- Do not add a new line in multilevel chained package clause (#1594) @iRevive
- adding possibility to specify custom repositories for coursier (#1521) (#1586) @slivkamiro
- Update scalafmt-core to 2.3.1 (#1590) @scala-steward
- Update interface to 0.0.16 (#1589) @scala-steward
Scalafmt v2.3.1
This release is mostly identical to 2.3.0-RC1 excluding a small regression fix for RedundantBraces
and library dependency updates from Scala Steward.
v2.3.0-RC2 Release notes
See https://github.com/scalameta/scalafmt/releases/tag/v2.3.0-RC2
Pull Requests
- RedundantBraces: fix how we find {} in func body (#1588) @kitbellew
- Add installation instructions for scalafmt-native. (#1570) @olafurpg
- Router: break between curly and catch, like else (#1567) @kitbellew
- Formatter upgraded to 2.3.0-RC1 (#1566) @poslegm
Dependency updates
- Update typesafe:config to 1.4.0 (#1584) @scala-steward
- Update sbt-mdoc to 2.0.3 (#1585) @scala-steward
- Update typesafe:config to 1.3.4 (#1573) @scala-steward
- Update sbt-scalajs to 0.6.31 (#1578) @scala-steward
- Update sbt-jmh to 0.3.7 (#1581) @scala-steward
- Update sbt-mdoc to 2.0.2 (#1579) @scala-steward
- Update paiges-core to 0.3.0 (#1580) @scala-steward
- Update sbt-scalajs-crossproject to 0.6.1 (#1577) @scala-steward
- Update sbt-buildinfo to 0.9.0 (#1572) @scala-steward
- Update interface to 0.0.14 (#1575) @scala-steward
- Update sbt-coursier to 1.0.3 (#1576) @scala-steward
- Update sbt-mima-plugin to 0.6.1 (#1574) @scala-steward
- Update sbt-assembly to 0.14.10 (#1571) @scala-steward
Scalafmt v2.3.0-RC2
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