From 401d0f79297ceaf6a162c5796af7f97073880f75 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Sun, 23 Oct 2022 11:15:27 -0400 Subject: [PATCH] Update SwiftSyntax to `60c7037` (#4454) This has changes to how comments are associated to nodes. See https://github.com/apple/swift-syntax/pull/985 --- Package.resolved | 2 +- Package.swift | 2 +- .../Rules/Style/ColonRule.swift | 6 +++++- .../Rules/Style/ColonRuleExamples.swift | 9 +++++++++ .../Rules/Style/CommaRule.swift | 16 +++++++++++----- .../Style/OperatorUsageWhitespaceRule.swift | 7 +++++-- bazel/repos.bzl | 6 +++--- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Package.resolved b/Package.resolved index e302d010dc..8492b9b0b0 100644 --- a/Package.resolved +++ b/Package.resolved @@ -33,7 +33,7 @@ "repositoryURL": "https://github.com/apple/swift-syntax.git", "state": { "branch": null, - "revision": "0519e76999c9e548e58222e45a22f177c886d8c0", + "revision": "60c7037405b3e0ecc4d42805bc46dbcbb947afc0", "version": null } }, diff --git a/Package.swift b/Package.swift index 238ae40124..460e7e27b2 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,7 @@ let package = Package( ], dependencies: [ .package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.1.3")), - .package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .revision("0519e76999c9e548e58222e45a22f177c886d8c0")), + .package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", .revision("60c7037405b3e0ecc4d42805bc46dbcbb947afc0")), .package(url: "https://github.com/jpsim/SourceKitten.git", .revision("a9e6df65d8e31e0fa6e8a05ffe40ecd54a645871")), .package(url: "https://github.com/jpsim/Yams.git", from: "5.0.1"), .package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"), diff --git a/Source/SwiftLintFramework/Rules/Style/ColonRule.swift b/Source/SwiftLintFramework/Rules/Style/ColonRule.swift index e38f060c37..e2860336e5 100644 --- a/Source/SwiftLintFramework/Rules/Style/ColonRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/ColonRule.swift @@ -54,11 +54,15 @@ public struct ColonRule: SubstitutionCorrectableRule, ConfigurationProviderRule, return nil } - if previous.trailingTrivia.isNotEmpty && !current.leadingTrivia.containsBlockComments() { + if previous.trailingTrivia.isNotEmpty && !previous.trailingTrivia.containsBlockComments() { let start = ByteCount(previous.endPositionBeforeTrailingTrivia) let end = ByteCount(current.endPosition) return ByteRange(location: start, length: end - start) } else if current.trailingTrivia != [.spaces(1)] && !next.leadingTrivia.containsNewlines() { + if case .spaces(1) = current.trailingTrivia.first { + return nil + } + let flexibleRightSpacing = configuration.flexibleRightSpacing || caseStatementPositions.contains(current.position) if flexibleRightSpacing && current.trailingTrivia.isNotEmpty { diff --git a/Source/SwiftLintFramework/Rules/Style/ColonRuleExamples.swift b/Source/SwiftLintFramework/Rules/Style/ColonRuleExamples.swift index 4c3243a221..c8c2384e28 100644 --- a/Source/SwiftLintFramework/Rules/Style/ColonRuleExamples.swift +++ b/Source/SwiftLintFramework/Rules/Style/ColonRuleExamples.swift @@ -65,6 +65,15 @@ internal struct ColonRuleExamples { associativity: left } infix operator |> : PipelinePrecedence + """), + Example(""" + switch scalar { + case 0x000A...0x000D /* LF ... CR */: return true + case 0x0085 /* NEXT LINE (NEL) */: return true + case 0x2028 /* LINE SEPARATOR */: return true + case 0x2029 /* PARAGRAPH SEPARATOR */: return true + default: return false + } """) ] diff --git a/Source/SwiftLintFramework/Rules/Style/CommaRule.swift b/Source/SwiftLintFramework/Rules/Style/CommaRule.swift index 75c2d17110..bb9623e45c 100644 --- a/Source/SwiftLintFramework/Rules/Style/CommaRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/CommaRule.swift @@ -20,9 +20,15 @@ public struct CommaRule: CorrectableRule, ConfigurationProviderRule, SourceKitFr Example("func abc(\n a: String,\n bcd: String\n) {\n}\n"), Example("#imageLiteral(resourceName: \"foo,bar,baz\")"), Example(""" - kvcStringBuffer.advanced(by: rootKVCLength) - .storeBytes(of: 0x2E /* '.' */, as: CChar.self) - """) + kvcStringBuffer.advanced(by: rootKVCLength) + .storeBytes(of: 0x2E /* '.' */, as: CChar.self) + """), + Example(""" + public indirect enum ExpectationMessage { + /// appends after an existing message (" (use beNil() to match nils)") + case appends(ExpectationMessage, /* Appended Message */ String) + } + """, excludeFromDocumentation: true) ], triggeringExamples: [ Example("func abc(a: String↓ ,b: String) { }"), @@ -97,12 +103,12 @@ public struct CommaRule: CorrectableRule, ConfigurationProviderRule, SourceKitFr .compactMap { previous, current, next -> (ByteRange, shouldAddSpace: Bool)? in if current.tokenKind != .comma { return nil - } else if !previous.trailingTrivia.isEmpty && !current.leadingTrivia.containsBlockComments() { + } else if !previous.trailingTrivia.isEmpty && !previous.trailingTrivia.containsBlockComments() { let start = ByteCount(previous.endPositionBeforeTrailingTrivia) let end = ByteCount(current.endPosition) let nextIsNewline = next.leadingTrivia.containsNewlines() return (ByteRange(location: start, length: end - start), shouldAddSpace: !nextIsNewline) - } else if current.trailingTrivia != [.spaces(1)] && !next.leadingTrivia.containsNewlines() { + } else if !current.trailingTrivia.starts(with: [.spaces(1)]), !next.leadingTrivia.containsNewlines() { return (ByteRange(location: ByteCount(current.position), length: 1), shouldAddSpace: true) } else { return nil diff --git a/Source/SwiftLintFramework/Rules/Style/OperatorUsageWhitespaceRule.swift b/Source/SwiftLintFramework/Rules/Style/OperatorUsageWhitespaceRule.swift index 683310960c..9d7648ce47 100644 --- a/Source/SwiftLintFramework/Rules/Style/OperatorUsageWhitespaceRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/OperatorUsageWhitespaceRule.swift @@ -188,11 +188,14 @@ private class OperatorUsageWhitespaceVisitor: SyntaxVisitor { return nil } - let tooMuchSpacingBefore = previousToken.trailingTrivia.containsTooMuchWhitespacing - let tooMuchSpacingAfter = operatorToken.trailingTrivia.containsTooMuchWhitespacing + let tooMuchSpacingBefore = previousToken.trailingTrivia.containsTooMuchWhitespacing && + !operatorToken.leadingTrivia.containsNewlines() + let tooMuchSpacingAfter = operatorToken.trailingTrivia.containsTooMuchWhitespacing && + !operatorToken.trailingTrivia.containsNewlines() let tooMuchSpacing = (tooMuchSpacingBefore || tooMuchSpacingAfter) && !operatorToken.leadingTrivia.containsComments && + !operatorToken.trailingTrivia.containsComments && !nextToken.leadingTrivia.containsComments guard noSpacing || tooMuchSpacing else { diff --git a/bazel/repos.bzl b/bazel/repos.bzl index b56f3eda7e..4c1ef8fcb0 100644 --- a/bazel/repos.bzl +++ b/bazel/repos.bzl @@ -20,10 +20,10 @@ def swiftlint_repos(): http_archive( name = "com_github_apple_swift_syntax", - sha256 = "331d411773efcd924e3e91f0f9899715c2259bedd29277693baa5263ee588220", + sha256 = "a4b0527ff3d0f4d002c85b246fde52552d2cfbbfa2329a298a2ee44aa66ded9a", build_file = "@SwiftLint//bazel:SwiftSyntax.BUILD", - strip_prefix = "swift-syntax-0519e76999c9e548e58222e45a22f177c886d8c0", - url = "https://github.com/apple/swift-syntax/archive/0519e76999c9e548e58222e45a22f177c886d8c0.tar.gz", + strip_prefix = "swift-syntax-60c7037405b3e0ecc4d42805bc46dbcbb947afc0", + url = "https://github.com/apple/swift-syntax/archive/60c7037405b3e0ecc4d42805bc46dbcbb947afc0.tar.gz", ) http_archive(