Skip to content

Merge main into release/6.0 #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Run `brew install swift-format` to install the latest version.
Install `swift-format` using the following commands:

```sh
VERSION=509.0.0 # replace this with the version you need
VERSION=510.1.0 # replace this with the version you need
git clone https://github.com/apple/swift-format.git
cd swift-format
git checkout "tags/$VERSION"
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFormat/API/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public struct Configuration: Codable, Equatable {
///
/// When `true` (default), the correct form is:
/// ```swift
/// let MyCollection = [1, 2,]
/// let MyCollection = [1, 2]
/// ...
/// let MyCollection = [
/// "a": 1,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFormat/Core/Trivia+Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension Trivia {
})
}

/// Returns `true` if this trivia contains any backslahes (used for multiline string newline
/// Returns `true` if this trivia contains any backslashes (used for multiline string newline
/// suppression).
var containsBackslashes: Bool {
return contains(
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,17 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
return .visitChildren
}

override func visit(_ node: OriginallyDefinedInAttributeArgumentsSyntax) -> SyntaxVisitorContinueKind {
after(node.colon.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
after(node.comma.lastToken(viewMode: .sourceAccurate), tokens: .break(.same, size: 1))
return .visitChildren
}

override func visit(_ node: DocumentationAttributeArgumentSyntax) -> SyntaxVisitorContinueKind {
after(node.colon, tokens: .break(.same, size: 1))
return .visitChildren
}

override func visit(_ node: AvailabilityLabeledArgumentSyntax) -> SyntaxVisitorContinueKind {
before(node.label, tokens: .open)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class AlwaysUseLiteralForEmptyCollectionInit : SyntaxFormatRule {
if replacement.typeAnnotation == nil {
// Drop trailing trivia after pattern because ':' has to appear connected to it.
replacement.pattern = node.pattern.with(\.trailingTrivia, [])
// Add explicit type annotiation: ': [<Type>]`
// Add explicit type annotation: ': [<Type>]`
replacement.typeAnnotation = .init(type: type.with(\.leadingTrivia, .space)
.with(\.trailingTrivia, .space))
}
Expand All @@ -109,7 +109,7 @@ public final class AlwaysUseLiteralForEmptyCollectionInit : SyntaxFormatRule {
if replacement.typeAnnotation == nil {
// Drop trailing trivia after pattern because ':' has to appear connected to it.
replacement.pattern = node.pattern.with(\.trailingTrivia, [])
// Add explicit type annotiation: ': [<Type>]`
// Add explicit type annotation: ': [<Type>]`
replacement.typeAnnotation = .init(type: type.with(\.leadingTrivia, .space)
.with(\.trailingTrivia, .space))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension Configuration {
/// different module than where `Configuration` is defined, we can't make this an initializer that
/// would enforce that every field of `Configuration` is initialized here (we're forced to
/// delegate to another initializer first, which defeats the purpose). So, users adding new
/// configuration settings shouls be sure to supply a default here for testing, otherwise they
/// configuration settings should be sure to supply a default here for testing, otherwise they
/// will be implicitly relying on the real default.
public static var forTesting: Configuration {
var config = Configuration()
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-format/Utilities/FileIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public struct FileIterator: Sequence, IteratorProtocol {
case .typeRegular:
// We attempt to relativize the URLs based on the current working directory, not the
// directory being iterated over, so that they can be displayed better in diagnostics. Thus,
// if the user passes paths that are relative to the current working diectory, they will
// if the user passes paths that are relative to the current working directory, they will
// be displayed as relative paths. Otherwise, they will still be displayed as absolute
// paths.
let relativePath =
Expand Down
34 changes: 34 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@ final class AttributeTests: PrettyPrintTestCase {
assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
}

func testAttributeParamSpacingInOriginallyDefinedIn() {
let input =
"""
@_originallyDefinedIn( module :"SwiftUI" , iOS 10.0 )
func f() {}
"""

let expected =
"""
@_originallyDefinedIn(module: "SwiftUI", iOS 10.0)
func f() {}

"""

assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
}

func testAttributeParamSpacingInDocVisibility() {
let input =
"""
@_documentation( visibility :private )
func f() {}
"""

let expected =
"""
@_documentation(visibility: private)
func f() {}

"""

assertPrettyPrintEqual(input: input, expected: expected, linelength: 60)
}

func testAttributeBinPackedWrapping() {
let input =
"""
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final class CommaTests: PrettyPrintTestCase {
assertPrettyPrintEqual(input: input, expected: expected, linelength: 20, configuration: configuration)
}

func testArraySingleLineCommasPresentDisabled() {
func testArraySingleLineCommasPresentEnabled() {
let input =
"""
let MyCollection = [1, 2, 3,]
Expand All @@ -124,7 +124,7 @@ final class CommaTests: PrettyPrintTestCase {
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40, configuration: configuration)
}

func testArraySingleLineCommasPresentEnabled() {
func testArraySingleLineCommasPresentDisabled() {
let input =
"""
let MyCollection = [1, 2, 3,]
Expand Down