Skip to content

Commit

Permalink
Update SwiftSyntax to 60c7037 (realm#4454)
Browse files Browse the repository at this point in the history
This has changes to how comments are associated to nodes.

See swiftlang/swift-syntax#985
  • Loading branch information
jpsim authored Oct 23, 2022
1 parent 25a04e8 commit 401d0f7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"repositoryURL": "https://github.com/apple/swift-syntax.git",
"state": {
"branch": null,
"revision": "0519e76999c9e548e58222e45a22f177c886d8c0",
"revision": "60c7037405b3e0ecc4d42805bc46dbcbb947afc0",
"version": null
}
},
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 5 additions & 1 deletion Source/SwiftLintFramework/Rules/Style/ColonRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions Source/SwiftLintFramework/Rules/Style/ColonRuleExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
""")
]

Expand Down
16 changes: 11 additions & 5 deletions Source/SwiftLintFramework/Rules/Style/CommaRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("<expectation> (use beNil() to match nils)")
case appends(ExpectationMessage, /* Appended Message */ String)
}
""", excludeFromDocumentation: true)
],
triggeringExamples: [
Example("func abc(a: String↓ ,b: String) { }"),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions bazel/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 401d0f7

Please sign in to comment.