From ac3cc940a71e2666caadd6e638641dd02e4887fa Mon Sep 17 00:00:00 2001 From: mh-mobile Date: Sun, 24 Mar 2024 15:59:25 +0900 Subject: [PATCH 1/9] Update README to specify version 510.1.0 for building from source --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db92fa2a2..6b29d73eb 100644 --- a/README.md +++ b/README.md @@ -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" From a0bbe05031d85b78fe2433719f0ba25e8aef0123 Mon Sep 17 00:00:00 2001 From: Mizuo Nagayama <33952656+ozumin@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:38:28 +0900 Subject: [PATCH 2/9] fix comment for multiElementCollectionTrailingCommas --- Sources/SwiftFormat/API/Configuration.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftFormat/API/Configuration.swift b/Sources/SwiftFormat/API/Configuration.swift index ec7d97679..ab8a3e952 100644 --- a/Sources/SwiftFormat/API/Configuration.swift +++ b/Sources/SwiftFormat/API/Configuration.swift @@ -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, From 8c4a487f11a89cb2a3e9d0ec1fe9ad5d337b848b Mon Sep 17 00:00:00 2001 From: Mizuo Nagayama <33952656+ozumin@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:50:22 +0900 Subject: [PATCH 3/9] fix method name in CommaTests.swift --- Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift b/Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift index 24bd0238e..4264370c8 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/CommaTests.swift @@ -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,] @@ -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,] From 629372aff54e96ad744f583a927edb5468196bba Mon Sep 17 00:00:00 2001 From: Takumi Muraishi Date: Wed, 27 Mar 2024 22:15:24 +0900 Subject: [PATCH 4/9] fix typo in Configuration+Testing.swift --- Sources/_SwiftFormatTestSupport/Configuration+Testing.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/_SwiftFormatTestSupport/Configuration+Testing.swift b/Sources/_SwiftFormatTestSupport/Configuration+Testing.swift index e9ab39c34..8d095767b 100644 --- a/Sources/_SwiftFormatTestSupport/Configuration+Testing.swift +++ b/Sources/_SwiftFormatTestSupport/Configuration+Testing.swift @@ -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() From 1967bf7fe7bd76138bb3fe0d26ed584d10e02a93 Mon Sep 17 00:00:00 2001 From: Takumi Muraishi Date: Wed, 27 Mar 2024 22:15:55 +0900 Subject: [PATCH 5/9] fix typo in FileIterator.swift --- Sources/swift-format/Utilities/FileIterator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/swift-format/Utilities/FileIterator.swift b/Sources/swift-format/Utilities/FileIterator.swift index 6f88cc909..a3b2a6984 100644 --- a/Sources/swift-format/Utilities/FileIterator.swift +++ b/Sources/swift-format/Utilities/FileIterator.swift @@ -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 = From d4bbe76a186c437a0a74667dfb053c2d0424d541 Mon Sep 17 00:00:00 2001 From: Takumi Muraishi Date: Wed, 27 Mar 2024 22:28:49 +0900 Subject: [PATCH 6/9] fix typo in Trivia+Convenience.swift --- Sources/SwiftFormat/Core/Trivia+Convenience.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftFormat/Core/Trivia+Convenience.swift b/Sources/SwiftFormat/Core/Trivia+Convenience.swift index 612cd4236..c1906ab6c 100644 --- a/Sources/SwiftFormat/Core/Trivia+Convenience.swift +++ b/Sources/SwiftFormat/Core/Trivia+Convenience.swift @@ -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( From af841655447f4fe16ec95c347d16ef89e49733d9 Mon Sep 17 00:00:00 2001 From: Takumi Muraishi Date: Thu, 28 Mar 2024 15:10:52 +0900 Subject: [PATCH 7/9] fix annotation --- .../Rules/AlwaysUseLiteralForEmptyCollectionInit.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftFormat/Rules/AlwaysUseLiteralForEmptyCollectionInit.swift b/Sources/SwiftFormat/Rules/AlwaysUseLiteralForEmptyCollectionInit.swift index b73e0ba49..973e22771 100644 --- a/Sources/SwiftFormat/Rules/AlwaysUseLiteralForEmptyCollectionInit.swift +++ b/Sources/SwiftFormat/Rules/AlwaysUseLiteralForEmptyCollectionInit.swift @@ -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: ': []` + // Add explicit type annotation: ': []` replacement.typeAnnotation = .init(type: type.with(\.leadingTrivia, .space) .with(\.trailingTrivia, .space)) } @@ -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: ': []` + // Add explicit type annotation: ': []` replacement.typeAnnotation = .init(type: type.with(\.leadingTrivia, .space) .with(\.trailingTrivia, .space)) } From b04a373ff995848101eb51605f04eac144ff7c86 Mon Sep 17 00:00:00 2001 From: Daniel Duan Date: Tue, 16 Apr 2024 13:32:42 -0700 Subject: [PATCH 8/9] Fix @_originallyDefinedIn argument spacing Pretty-print `@_originallyDefinedIn` with the correct spacing. --- .../PrettyPrint/TokenStreamCreator.swift | 6 ++++++ .../PrettyPrint/AttributeTests.swift | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index 070de11a5..5d0f003f3 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -1799,6 +1799,12 @@ 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: AvailabilityLabeledArgumentSyntax) -> SyntaxVisitorContinueKind { before(node.label, tokens: .open) diff --git a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift index 06aa46c8f..1289dad96 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift @@ -26,6 +26,23 @@ 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 testAttributeBinPackedWrapping() { let input = """ From 36ba8dcc899b92833c838ff7240a753baa250dd0 Mon Sep 17 00:00:00 2001 From: Daniel Duan Date: Tue, 16 Apr 2024 14:09:29 -0700 Subject: [PATCH 9/9] Fix incorrect spacing when pretty-printing @_documentation With attribute such as `@_documentation(visibility: private)`, swift-format incorrectly prints no spacing between `visibility` and `private`. --- .../PrettyPrint/TokenStreamCreator.swift | 5 +++++ .../PrettyPrint/AttributeTests.swift | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index 5d0f003f3..1023d886f 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -1802,6 +1802,11 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { 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 } diff --git a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift index 1289dad96..3031fc31b 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift @@ -43,6 +43,23 @@ final class AttributeTests: PrettyPrintTestCase { 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 = """