Releases: swiftlang/swift-format
510.1.0
What's Changed
- Update to non-optional leading/trailingTrivia swift-syntax API by @bnbarham in #497
- Adjustments to split
FunctionParameterSyntax
into multiple nodes for function parameters, closure parameters and enum parameters by @ahoppen in #495 - Prepare 508.0.0 release. by @allevato in #506
- Fix formatting of import with multiple attributes (fixes #445) and ensure that imports never wrap by @stackotter in #501
- Fix fatal error caused by switch cases without any statements (#473) by @stackotter in #499
- Remove the
swift-tools-support-core
dependency from swift-format. by @allevato in #509 - Fix pretty printing of multi-statement closures (issue #494) by @stackotter in #498
- Avoid removing certain disambiguating parens from conditions (fixes #298) by @stackotter in #503
- Fix more postfix pound if scenarios by @DavidBrunow in #402
- Remove usages of functions that shouldn’t be part of SwiftSyntax’s public API by @ahoppen in #504
- Removed warnings by @CippoX in #510
- Adjustment for SwiftSyntax rename
members
->memberBlock
by @ahoppen in #512 - [SwiftSyntax] Remove force unwrapping for source location by @kimdv in #513
- Change version dependency on
swift-argument-parser
to fromupToNextMinor
toupToNextMajor
by @ahoppen in #517 - Replace deprecated code of swift-syntax with the latest code to remove warning by @TTOzzi in #531
- Fix indentation of multiline strings when part of a larger expression. by @allevato in #532
- Fix
try
/await
expressions inNoAssignmentInExpressions
. by @allevato in #533 - Further improve multiline string formatting. by @allevato in #534
- Allow exceptions to
NoAssignmentInExpressions
. by @allevato in #535 - Add
Token.break
after fixity in operator declaration by @StevenWong12 in #536 - Rename
elementList
inTupleExprSyntax
toelements
by @StevenWong12 in #537 - Fix
async throws
function types when they appear in an expression context. by @allevato in #539 - Replace deprecated code from swift-syntax by @TTOzzi in #540
- Wrap keypath literals appropriately. by @allevato in #545
- Format
macro
declarations. by @allevato in #546 - Insert white space before trailing closure of a macro expression by @kimberninger in #544
- Rename 'squareBracket' to 'square' by @TTOzzi in #541
- Delete
UnknownNodeTests
. by @allevato in #548 - Fix formatting of
@backDeploy
attribute. by @allevato in #550 - Don't insert an extra break inside empty multiline strings. by @allevato in #551
- Downgrade
editor placeholder in source file
from error to warning. by @allevato in #547 - Improve wrapping of if/switch expressions. by @allevato in #553
- Fix postfix-
#if
formatting when they come after a closing parenthesis. by @allevato in #554 - Fix indentation of multiline strings in enum case raw values. by @allevato in #555
- Fix deprecated SwiftSyntax api warnings by @kitasuke in #558
- Remove the compiler condition guarding
DerivativeRegistrationAttributeArgumentsSyntax
. by @allevato in #559 - Use swift-markdown to parse documentation comments. by @allevato in #560
- Adjustment because of a property rename in swift-syntax by @ahoppen in #561
- Replace
[TriviaPiece].Index
withArray<TriviaPiece>.Index
. by @allevato in #565 - Remove --mode flag for configuration dump by @Gray-Wind in #566
- Use newer equivalents of deprecated nodes names by @Matejkob in #567
- Add XCTest exclusion comment for lint rules by @kitasuke in #568
- Use methods on Sequence instead of SyntaxCollection by @kitasuke in #569
- Update swift-format for renamed children in SwiftSyntax by @ahoppen in #562
- Fix deprecated warnings regarding swift-syntax changes by @kitasuke in #570
- Adjustments for node renames in swift-syntax by @ahoppen in #572
- Remove
initializer
fromTupleTypeElementSyntax
initializer call by @ahoppen in #573 - Rename children of differentiability nodes by @ahoppen in #574
- Adjustments for refactoring of representation of Accessors in SwiftSyntax by @ahoppen in #576
- Use
where
instead of filter forfor
loops by @ahoppen in #575 - Adjustments for usage of
DeclReferenceExprSyntax
as child ofMemberAccessExprSyntax
by @ahoppen in #577 - [Core] Add new finding severity kinds -
refactoring
andconvention
by @xedin in #578 - Fix deprecation warnings from renamed nodes / types in SwiftSyntax by @ahoppen in #579
- Move the default
Configuration.init()
into a separate file. by @allevato in #580 - Don't alter doc line comments unnecessarily. by @allevato in #581
- Improve a bunch of diagnostic messages. by @allevato in #583
- Migrate away from the latest deprecated APIs. by @allevato in #584
- Replace the
ReplaceTrivia
rewriter with direct trivia mutations. by @allevato in #588 - Parenthesize
some/any
types when convertingOptional
to?
. by @allevato in #589 - Update for the fact that syntax collections are always non-optional in SwiftSyntax now by @ahoppen in #585
- Make
shebang
a child ofSourceFileSyntax
by @StevenWong12 in #590 - [Lint] Add a rule to detect that type declarations are not capitalized by @xedin in #587
- Don't warn about a redundant synthesized memberwise init if it has attributes. by @allevato in #592
- Collapse almost everything into a single
SwiftFormat
module. by @allevato in #593 - Refactor tests. by @allevato in #595
- Don't do anything if the input is empty. by @allevato in #599
- Fix a bunch of FIXMEs around linter findings. by @allevato in #597
- [Lint/Format] Add a rule to omit
return
from functions, closures, subscripts, and variables by @xedin in #596 - [Lint] Add a rule to replace
.forEach
with a for-in loop by @xedin in #603 - Replace
with
calls with in-place mutation; clean up helpers. by @allevato in #609 - Actually implement
NoPlaygroundLiterals
rule. by @allevato in #613 - Adjust for "remark" diagnostic severity by @DougGregor in #605
- Move
Configuration
into theSwiftFormat
module. by @allevato in #614 - Fix invalid links in README by @woxtu in #594
- Default to all targets when plugin
--target
parameter missing. Fix #483 by @BrianHenryIE in #608 - Remove unnecessary casting by @Matejkob in #618
- Output a warning for unknown configuration rules in
.swift-format
by @natikgadzhi in #612 - Generate rule docs automatically by @natikgadzhi in #615
- [5.10] Add fixes that were present in 509.0.0 but not release/5.10 by @ahoppen in #704
New Contributors
- @stackotter made their first contribution in #501
- @CippoX made their first contribution in #510
- @StevenWong12 ...
509.0.0
This release is compatible with Swift 5.9.
Significant changes since the last release:
New rules
AlwaysUseLiteralForEmptyCollectionInit
: transforms no-argument initializer calls on collection types to use the empty collection literal instead. For example,let x = [Int]()
will be transformed intolet x: [Int] = []
. This rule is opt-in (disabled by default).NoPlaygroundLiterals
: emits lint findings when the playground literals (#colorLiteral
,#fileLiteral
,#imageLiteral
) are used in code. Enabled by default.OmitExplicitReturns
: removes unnecessaryreturn
keywords from single-expression function/closure/subscript/accessor bodies. This rule is opt-in (disabled by default).ReplaceForEachWithForLoop
: emits lint findings when theforEach
method is called with a closure literal at the end of a member access chain, indicating that it should be replaced by afor
loop instead. Enabled by default.TypeNamesShouldBeCapitalized
: emits lint findings when a type is declared with a name that is notUpperCamelCase
. Enabled by default.
New configuration settings
multiElementCollectionTrailingCommas
(boolean): When set tofalse
, the last element of a multi-element array or dictionary literal will not have a trailing comma, even when the literal wraps across multiple lines. Defaults totrue
(preserving the behavior of previous releases).
Bug fixes and behavior changes
- swift-format no longer crashes when formatting a
case
block that contains no statements. - In multi-statement closures, there is now always a line break between the
in
keyword and the first statement. - Attributes before
import
statements are no longer wrapped. - The
NoParensAroundConditions
rule no longer removes parentheses around an immediately called closure. - The
NoAssignmentInExpressions
rule can be configured to ignore assignments that occur inside certain function calls. The default configuration ignores assignments insideXCTAssertNoThrow
. - When an editor placeholder is found in the source, this is now treated as a warning instead of an error. This allows formatting to continue, treating the placeholder as a regular identifier.
- Keypath literals are properly wrapped and indented.
- Postfix-
#if
expressions are no longer indented too far when they follow a closing parenthesis. - Indentation of multiline strings has been fixed in a number of locations.
- Documentation comment parsing has improved for rules like
BeginDocumentationCommentWithOneLineSummary
,UseTripleSlashForDocumentationComments
, andValidateDocumentationComments
. - Diagnostic messages throughout swift-format have been cleaned up and improved.
- The
UseShorthandTypeNames
rule properly parenthesizes optionalsome/any
types; for example,Optional<any P>
becomes(any P)?
, notany P?
(which is invalid). - The
UseSynthesizedInitializer
rule no longer warns that an initializer is redundant if it is declared with any attributes. - The lint/format plugins for SPM now default to processing all targets if the
--target
argument is not specified. - swift-format now emits a warning if you configure a rule that does not exist. This is meant to help catch typos in the configuration file.
- swift-format now does nothing if its input is empty (i.e., a zero-byte file). This suppresses a single trailing newline that would have otherwise been added in this case.
API changes
For developers using swift-format as a library, the types in the SwiftFormatConfiguration
module have been folded into the SwiftFormat
module. The SwiftFormat
module is now the sole module you should import to use the linter/formatter APIs.
The SwiftFormatConfiguration
module still exists to re-export the types for backwards compatibility, but this will be removed in the 510.0.0 release.
Swift 5.10 Release
What's Changed
- Update to non-optional leading/trailingTrivia swift-syntax API by @bnbarham in #497
- Adjustments to split
FunctionParameterSyntax
into multiple nodes for function parameters, closure parameters and enum parameters by @ahoppen in #495 - Prepare 508.0.0 release. by @allevato in #506
- Fix formatting of import with multiple attributes (fixes #445) and ensure that imports never wrap by @stackotter in #501
- Fix fatal error caused by switch cases without any statements (#473) by @stackotter in #499
- Remove the
swift-tools-support-core
dependency from swift-format. by @allevato in #509 - Fix pretty printing of multi-statement closures (issue #494) by @stackotter in #498
- Avoid removing certain disambiguating parens from conditions (fixes #298) by @stackotter in #503
- Fix more postfix pound if scenarios by @DavidBrunow in #402
- Remove usages of functions that shouldn’t be part of SwiftSyntax’s public API by @ahoppen in #504
- Removed warnings by @CippoX in #510
- Adjustment for SwiftSyntax rename
members
->memberBlock
by @ahoppen in #512 - [SwiftSyntax] Remove force unwrapping for source location by @kimdv in #513
- Change version dependency on
swift-argument-parser
to fromupToNextMinor
toupToNextMajor
by @ahoppen in #517 - Replace deprecated code of swift-syntax with the latest code to remove warning by @TTOzzi in #531
- Fix indentation of multiline strings when part of a larger expression. by @allevato in #532
- Fix
try
/await
expressions inNoAssignmentInExpressions
. by @allevato in #533 - Further improve multiline string formatting. by @allevato in #534
- Allow exceptions to
NoAssignmentInExpressions
. by @allevato in #535 - Add
Token.break
after fixity in operator declaration by @StevenWong12 in #536 - Rename
elementList
inTupleExprSyntax
toelements
by @StevenWong12 in #537 - Fix
async throws
function types when they appear in an expression context. by @allevato in #539 - Replace deprecated code from swift-syntax by @TTOzzi in #540
- Wrap keypath literals appropriately. by @allevato in #545
- Format
macro
declarations. by @allevato in #546 - Insert white space before trailing closure of a macro expression by @kimberninger in #544
- Rename 'squareBracket' to 'square' by @TTOzzi in #541
- Delete
UnknownNodeTests
. by @allevato in #548 - Fix formatting of
@backDeploy
attribute. by @allevato in #550 - Don't insert an extra break inside empty multiline strings. by @allevato in #551
- Downgrade
editor placeholder in source file
from error to warning. by @allevato in #547 - Improve wrapping of if/switch expressions. by @allevato in #553
- Fix postfix-
#if
formatting when they come after a closing parenthesis. by @allevato in #554 - Fix indentation of multiline strings in enum case raw values. by @allevato in #555
- Fix deprecated SwiftSyntax api warnings by @kitasuke in #558
- Remove the compiler condition guarding
DerivativeRegistrationAttributeArgumentsSyntax
. by @allevato in #559 - Use swift-markdown to parse documentation comments. by @allevato in #560
- Adjustment because of a property rename in swift-syntax by @ahoppen in #561
- Replace
[TriviaPiece].Index
withArray<TriviaPiece>.Index
. by @allevato in #565 - Remove --mode flag for configuration dump by @Gray-Wind in #566
- Use newer equivalents of deprecated nodes names by @Matejkob in #567
- Add XCTest exclusion comment for lint rules by @kitasuke in #568
- Use methods on Sequence instead of SyntaxCollection by @kitasuke in #569
- Update swift-format for renamed children in SwiftSyntax by @ahoppen in #562
- Fix deprecated warnings regarding swift-syntax changes by @kitasuke in #570
- Adjustments for node renames in swift-syntax by @ahoppen in #572
- Remove
initializer
fromTupleTypeElementSyntax
initializer call by @ahoppen in #573 - Rename children of differentiability nodes by @ahoppen in #574
- Adjustments for refactoring of representation of Accessors in SwiftSyntax by @ahoppen in #576
- Use
where
instead of filter forfor
loops by @ahoppen in #575 - Adjustments for usage of
DeclReferenceExprSyntax
as child ofMemberAccessExprSyntax
by @ahoppen in #577 - [Core] Add new finding severity kinds -
refactoring
andconvention
by @xedin in #578 - Fix deprecation warnings from renamed nodes / types in SwiftSyntax by @ahoppen in #579
- Move the default
Configuration.init()
into a separate file. by @allevato in #580 - Don't alter doc line comments unnecessarily. by @allevato in #581
- Improve a bunch of diagnostic messages. by @allevato in #583
- Migrate away from the latest deprecated APIs. by @allevato in #584
- Replace the
ReplaceTrivia
rewriter with direct trivia mutations. by @allevato in #588 - Parenthesize
some/any
types when convertingOptional
to?
. by @allevato in #589 - Update for the fact that syntax collections are always non-optional in SwiftSyntax now by @ahoppen in #585
- Make
shebang
a child ofSourceFileSyntax
by @StevenWong12 in #590 - [Lint] Add a rule to detect that type declarations are not capitalized by @xedin in #587
- Don't warn about a redundant synthesized memberwise init if it has attributes. by @allevato in #592
- Collapse almost everything into a single
SwiftFormat
module. by @allevato in #593 - Refactor tests. by @allevato in #595
- Don't do anything if the input is empty. by @allevato in #599
- Fix a bunch of FIXMEs around linter findings. by @allevato in #597
- [Lint/Format] Add a rule to omit
return
from functions, closures, subscripts, and variables by @xedin in #596 - [Lint] Add a rule to replace
.forEach
with a for-in loop by @xedin in #603 - Replace
with
calls with in-place mutation; clean up helpers. by @allevato in #609 - Actually implement
NoPlaygroundLiterals
rule. by @allevato in #613 - Adjust for "remark" diagnostic severity by @DougGregor in #605
- Move
Configuration
into theSwiftFormat
module. by @allevato in #614 - Fix invalid links in README by @woxtu in #594
- Default to all targets when plugin
--target
parameter missing. Fix #483 by @BrianHenryIE in #608 - Remove unnecessary casting by @Matejkob in #618
- Output a warning for unknown configuration rules in
.swift-format
by @natikgadzhi in #612 - Generate rule docs automatically by @natikgadzhi in #615
New Contributors
- @stackotter made their first contribution in #501
- @CippoX made their first contribution in #510
- @StevenWong12 made their first contribution in #536
- @kimberninger made their first contribution in ht...
508.0.1
508.0.0
This release is compatible with Swift 5.8.
Significant changes since the last release:
- The
spacesAroundRangeFormationOperators
configuration option has been added to force a space around range formation operators like...
and..<
. - A new rule,
NoAssignmentInExpressions
, has been added that emits a linter finding if an assignment expression is found in another expression context (for example,return x = y
). - Format and Lint plug-ins have been added that can be used from Swift Package Manager and Xcode.
- Detection of "files that contain
XCTest
s" has been improved to include cases whereXCTest
is imported conditionally in a#if
block. - Primary associated type clauses in
protocol
declarations are formatted correctly. - When a closure literal contains both a leading attribute and a capture list (e.g.,
{ @MainActor [weak self] in ...
), a space is guaranteed between the attribute and capture list. Optional<T>
will not be automatically converted to the shorthandT?
in positions where it would cause a performance issue due to subtle Swift initialization characteristics, like in member variable declarations.
0.50800.0-SNAPSHOT-2022-12-29-a
This is a development snapshot of the 0.50800.0 release of swift-format.
0.50700.1
0.50700.0
This release is compatible with Swift 5.7.
Significant changes since the last release:
- The
AlwaysUseLowerCamelCase
rule no longer emits a warning foroverride
declarations. (0e705f4) - The
UseWhereClausesInForLoops
rule won't hoist anif
condition into awhere
clause if it also has anelse
block. (793d764) #if
postfix expressions now have improved formatting. (7216a18)- Files will not be overwritten if they are not changed during formatting, preserving their modification time and other metadata. (3b2b9b4)
0.50600.1
0.50600.0
This release is compatible with Swift 5.6.
Significant changes since the last release:
- Diagnostics have been refactored as "findings". Users of swift-format as an API (via the
SwiftFormatter
andSwiftLinter
classes) now receive warnings and errors via a newFinding
type that is independent ofSwiftSyntax
diagnostic types, for greater flexibility. (7aa5df5) - Diagnostics are now printed in color if standard error is connected to a terminal. This can be controlled with the
--color-diagnostics/--no-color-diagnostics
command line flags (to force color output when redirected to something other than a terminal, or to disable color output to a terminal). (4f90887) - Formatting of
throws
andasync
property effects has been fixed. (f646a1f, 55fc4e2) - The legacy
-m/--mode
flag has been removed. (defb00d)