Skip to content

509.0.0

Compare
Choose a tag to compare
@allevato allevato released this 15 Sep 11:29
· 4 commits to release/5.9 since this release
83248b4

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 into let 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 unnecessary return keywords from single-expression function/closure/subscript/accessor bodies. This rule is opt-in (disabled by default).
  • ReplaceForEachWithForLoop: emits lint findings when the forEach method is called with a closure literal at the end of a member access chain, indicating that it should be replaced by a for loop instead. Enabled by default.
  • TypeNamesShouldBeCapitalized: emits lint findings when a type is declared with a name that is not UpperCamelCase. Enabled by default.

New configuration settings

  • multiElementCollectionTrailingCommas (boolean): When set to false, 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 to true (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 inside XCTAssertNoThrow.
  • 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, and ValidateDocumentationComments.
  • Diagnostic messages throughout swift-format have been cleaned up and improved.
  • The UseShorthandTypeNames rule properly parenthesizes optional some/any types; for example, Optional<any P> becomes (any P)?, not any 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.