Update SwiftSyntax to 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a (#5058)
Diff: https://github.com/apple/swift-syntax/compare/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-02-a...509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a
This commit is contained in:
parent
7462187191
commit
e5cf99088b
|
@ -41,8 +41,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-syntax.git",
|
||||
"state" : {
|
||||
"revision" : "27cd6190ce0628847a3f8050794d6e627ad79c08",
|
||||
"version" : "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-02-a"
|
||||
"revision" : "165fc6d22394c1168ff76ab5d951245971ef07e5",
|
||||
"version" : "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.2.1")),
|
||||
.package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-02-a"),
|
||||
.package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a"),
|
||||
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.34.1")),
|
||||
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.5"),
|
||||
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
|
||||
|
|
|
@ -48,12 +48,7 @@ private extension AnonymousArgumentInMultilineClosureRule {
|
|||
override func visit(_ node: ClosureExprSyntax) -> SyntaxVisitorContinueKind {
|
||||
let startLocation = locationConverter.location(for: node.leftBrace.positionAfterSkippingLeadingTrivia)
|
||||
let endLocation = locationConverter.location(for: node.rightBrace.endPositionBeforeTrailingTrivia)
|
||||
|
||||
guard let startLine = startLocation.line, let endLine = endLocation.line, startLine != endLine else {
|
||||
return .skipChildren
|
||||
}
|
||||
|
||||
return .visitChildren
|
||||
return startLocation.line == endLocation.line ? .skipChildren : .visitChildren
|
||||
}
|
||||
|
||||
override func visitPost(_ node: IdentifierExprSyntax) {
|
||||
|
|
|
@ -109,19 +109,15 @@ private extension ClosureParameterPositionRule {
|
|||
}
|
||||
|
||||
override func visitPost(_ node: ClosureExprSyntax) {
|
||||
guard let signature = node.signature,
|
||||
case let leftBracePosition = node.leftBrace.positionAfterSkippingLeadingTrivia,
|
||||
let startLine = locationConverter.location(for: leftBracePosition).line else {
|
||||
guard let signature = node.signature else {
|
||||
return
|
||||
}
|
||||
|
||||
let localViolations = signature.positionsToCheck
|
||||
.filter { position in
|
||||
guard let line = locationConverter.location(for: position).line else {
|
||||
return false
|
||||
}
|
||||
let leftBracePosition = node.leftBrace.positionAfterSkippingLeadingTrivia
|
||||
let startLine = locationConverter.location(for: leftBracePosition).line
|
||||
|
||||
return line != startLine
|
||||
let localViolations = signature.positionsToCheck.filter { position in
|
||||
return locationConverter.location(for: position).line != startLine
|
||||
}
|
||||
|
||||
violations.append(contentsOf: localViolations)
|
||||
|
|
|
@ -153,8 +153,8 @@ private extension ClosureExprSyntax {
|
|||
func shouldCheckForClosureSpacingRule(locationConverter: SourceLocationConverter) -> Bool {
|
||||
guard parent?.is(PostfixUnaryExprSyntax.self) == false, // Workaround for Regex literals
|
||||
(rightBrace.position.utf8Offset - leftBrace.position.utf8Offset) > 1, // Allow '{}'
|
||||
let startLine = startLocation(converter: locationConverter).line,
|
||||
let endLine = endLocation(converter: locationConverter).line,
|
||||
case let startLine = startLocation(converter: locationConverter).line,
|
||||
case let endLine = endLocation(converter: locationConverter).line,
|
||||
startLine == endLine // Only check single-line closures
|
||||
else {
|
||||
return false
|
||||
|
|
|
@ -55,12 +55,11 @@ private extension CollectionAlignmentRule {
|
|||
return zip(remainingKeyLocations.indices, remainingKeyLocations)
|
||||
.compactMap { index, location -> AbsolutePosition? in
|
||||
let previousLocation = keyLocations[index - 1]
|
||||
guard let previousLine = previousLocation.line,
|
||||
let locationLine = location.line,
|
||||
let firstKeyColumn = firstKeyLocation.column,
|
||||
let locationColumn = location.column,
|
||||
previousLine < locationLine,
|
||||
firstKeyColumn != locationColumn else {
|
||||
let previousLine = previousLocation.line
|
||||
let locationLine = location.line
|
||||
let firstKeyColumn = firstKeyLocation.column
|
||||
let locationColumn = location.column
|
||||
guard previousLine < locationLine, firstKeyColumn != locationColumn else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -37,12 +37,12 @@ private extension MultilineArgumentsRule {
|
|||
}
|
||||
|
||||
override func visitPost(_ node: FunctionCallExprSyntax) {
|
||||
guard node.argumentList.count > 1,
|
||||
case let functionCallPosition = node.calledExpression.positionAfterSkippingLeadingTrivia,
|
||||
let functionCallLine = locationConverter.location(for: functionCallPosition).line else {
|
||||
guard node.argumentList.count > 1 else {
|
||||
return
|
||||
}
|
||||
|
||||
let functionCallPosition = node.calledExpression.positionAfterSkippingLeadingTrivia
|
||||
let functionCallLine = locationConverter.location(for: functionCallPosition).line
|
||||
let wrappedArguments: [Argument] = node.argumentList
|
||||
.enumerated()
|
||||
.compactMap { idx, argument in
|
||||
|
@ -116,13 +116,8 @@ private struct Argument {
|
|||
let expression: ExprSyntax
|
||||
|
||||
init?(element: TupleExprElementSyntax, locationConverter: SourceLocationConverter, index: Int) {
|
||||
let offset = element.positionAfterSkippingLeadingTrivia
|
||||
guard let line = locationConverter.location(for: offset).line else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.offset = offset
|
||||
self.line = line
|
||||
self.offset = element.positionAfterSkippingLeadingTrivia
|
||||
self.line = locationConverter.location(for: offset).line
|
||||
self.index = index
|
||||
self.expression = element.expression
|
||||
}
|
||||
|
|
|
@ -50,10 +50,7 @@ private extension MultilineParametersRule {
|
|||
var linesWithParameters = Set<Int>()
|
||||
|
||||
for position in parameterPositions {
|
||||
guard let line = locationConverter.location(for: position).line else {
|
||||
continue
|
||||
}
|
||||
|
||||
let line = locationConverter.location(for: position).line
|
||||
linesWithParameters.insert(line)
|
||||
numberOfParameters += 1
|
||||
}
|
||||
|
|
|
@ -56,20 +56,18 @@ extension SwitchCaseAlignmentRule {
|
|||
|
||||
override func visitPost(_ node: SwitchExprSyntax) {
|
||||
let switchPosition = node.switchKeyword.positionAfterSkippingLeadingTrivia
|
||||
guard
|
||||
let switchColumn = locationConverter.location(for: switchPosition).column,
|
||||
node.cases.isNotEmpty,
|
||||
let firstCasePosition = node.cases.first?.positionAfterSkippingLeadingTrivia,
|
||||
let firstCaseColumn = locationConverter.location(for: firstCasePosition).column
|
||||
let switchColumn = locationConverter.location(for: switchPosition).column
|
||||
guard node.cases.isNotEmpty,
|
||||
let firstCasePosition = node.cases.first?.positionAfterSkippingLeadingTrivia
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let firstCaseColumn = locationConverter.location(for: firstCasePosition).column
|
||||
|
||||
for `case` in node.cases where `case`.is(SwitchCaseSyntax.self) {
|
||||
let casePosition = `case`.positionAfterSkippingLeadingTrivia
|
||||
guard let caseColumn = locationConverter.location(for: casePosition).column else {
|
||||
continue
|
||||
}
|
||||
let caseColumn = locationConverter.location(for: casePosition).column
|
||||
|
||||
let hasViolation = (indentedCases && caseColumn <= switchColumn) ||
|
||||
(!indentedCases && caseColumn != switchColumn) ||
|
||||
|
|
|
@ -75,14 +75,12 @@ private extension SwitchCaseOnNewlineRule {
|
|||
}
|
||||
|
||||
override func visitPost(_ node: SwitchCaseSyntax) {
|
||||
guard let caseEndLine = locationConverter.location(for: node.label.endPositionBeforeTrailingTrivia).line,
|
||||
case let statementsPosition = node.statements.positionAfterSkippingLeadingTrivia,
|
||||
let statementStartLine = locationConverter.location(for: statementsPosition).line,
|
||||
statementStartLine == caseEndLine else {
|
||||
return
|
||||
}
|
||||
|
||||
let caseEndLine = locationConverter.location(for: node.label.endPositionBeforeTrailingTrivia).line
|
||||
let statementsPosition = node.statements.positionAfterSkippingLeadingTrivia
|
||||
let statementStartLine = locationConverter.location(for: statementsPosition).line
|
||||
if statementStartLine == caseEndLine {
|
||||
violations.append(node.positionAfterSkippingLeadingTrivia)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,7 @@ private extension VerticalParameterAlignmentRule {
|
|||
let paramLocations = params.compactMap { param -> (position: AbsolutePosition, line: Int, column: Int)? in
|
||||
let position = param.positionAfterSkippingLeadingTrivia
|
||||
let location = locationConverter.location(for: position)
|
||||
guard let line = location.line, let column = location.column else {
|
||||
return nil
|
||||
}
|
||||
return (position, line, column)
|
||||
return (position, location.line, location.column)
|
||||
}
|
||||
|
||||
guard let firstParamLoc = paramLocations.first else { return [] }
|
||||
|
|
|
@ -34,9 +34,9 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: EnumDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.enumKeyword }
|
||||
leftBrace: node.memberBlock.leftBrace,
|
||||
rightBrace: node.memberBlock.rightBrace,
|
||||
violationNode: node.enumKeyword
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: ClassDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.classKeyword }
|
||||
leftBrace: node.memberBlock.leftBrace,
|
||||
rightBrace: node.memberBlock.rightBrace,
|
||||
violationNode: node.classKeyword
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: StructDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.structKeyword }
|
||||
leftBrace: node.memberBlock.leftBrace,
|
||||
rightBrace: node.memberBlock.rightBrace,
|
||||
violationNode: node.structKeyword
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +64,9 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: ActorDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.actorKeyword }
|
||||
leftBrace: node.memberBlock.leftBrace,
|
||||
rightBrace: node.memberBlock.rightBrace,
|
||||
violationNode: node.actorKeyword
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -74,45 +74,40 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: ClosureExprSyntax) {
|
||||
if kind == .closure {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.leftBrace },
|
||||
getRightBrace: { node.rightBrace },
|
||||
getViolationNode: { node.leftBrace }
|
||||
leftBrace: node.leftBrace,
|
||||
rightBrace: node.rightBrace,
|
||||
violationNode: node.leftBrace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override func visitPost(_ node: FunctionDeclSyntax) {
|
||||
if kind == .function {
|
||||
if kind == .function, let body = node.body {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.body?.leftBrace },
|
||||
getRightBrace: { node.body?.rightBrace },
|
||||
getViolationNode: { node.identifier }
|
||||
leftBrace: body.leftBrace,
|
||||
rightBrace: body.rightBrace,
|
||||
violationNode: node.identifier
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override func visitPost(_ node: InitializerDeclSyntax) {
|
||||
if kind == .function {
|
||||
if kind == .function, let body = node.body {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.body?.leftBrace },
|
||||
getRightBrace: { node.body?.rightBrace },
|
||||
getViolationNode: { node.initKeyword }
|
||||
leftBrace: body.leftBrace,
|
||||
rightBrace: body.rightBrace,
|
||||
violationNode: node.initKeyword
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func registerViolations(
|
||||
getLeftBrace: () -> TokenSyntax?, getRightBrace: () -> TokenSyntax?, getViolationNode: () -> some SyntaxProtocol
|
||||
leftBrace: TokenSyntax, rightBrace: TokenSyntax, violationNode: SyntaxProtocol
|
||||
) {
|
||||
guard
|
||||
let leftBracePosition = getLeftBrace()?.positionAfterSkippingLeadingTrivia,
|
||||
let leftBraceLine = locationConverter.location(for: leftBracePosition).line,
|
||||
let rightBracePosition = getRightBrace()?.positionAfterSkippingLeadingTrivia,
|
||||
let leftBracePosition = leftBrace.positionAfterSkippingLeadingTrivia
|
||||
let leftBraceLine = locationConverter.location(for: leftBracePosition).line
|
||||
let rightBracePosition = rightBrace.positionAfterSkippingLeadingTrivia
|
||||
let rightBraceLine = locationConverter.location(for: rightBracePosition).line
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let lineCount = file.bodyLineCountIgnoringCommentsAndWhitespace(leftBraceLine: leftBraceLine,
|
||||
rightBraceLine: rightBraceLine)
|
||||
let severity: ViolationSeverity, upperBound: Int
|
||||
|
@ -132,7 +127,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
|
|||
"""
|
||||
|
||||
let violation = ReasonedRuleViolation(
|
||||
position: getViolationNode().positionAfterSkippingLeadingTrivia,
|
||||
position: violationNode.positionAfterSkippingLeadingTrivia,
|
||||
reason: reason,
|
||||
severity: severity
|
||||
)
|
||||
|
|
|
@ -8,8 +8,8 @@ public extension SourceRange {
|
|||
///
|
||||
/// - returns: Whether the specified position is contained within this range.
|
||||
func contains(_ position: AbsolutePosition, locationConverter: SourceLocationConverter) -> Bool {
|
||||
let startPosition = locationConverter.position(ofLine: start.line ?? 1, column: start.column ?? 1)
|
||||
let endPosition = locationConverter.position(ofLine: end.line ?? 1, column: end.column ?? 1)
|
||||
let startPosition = locationConverter.position(ofLine: start.line, column: start.column)
|
||||
let endPosition = locationConverter.position(ofLine: end.line, column: end.column)
|
||||
return startPosition <= position && position <= endPosition
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,10 +47,11 @@ public extension SwiftLintFile {
|
|||
let sourceRange = token
|
||||
.trimmed
|
||||
.sourceRange(converter: locationConverter)
|
||||
let startLine = sourceRange.start.line!
|
||||
let endLine = sourceRange.end.line!
|
||||
let startLine = sourceRange.start.line
|
||||
let endLine = sourceRange.end.line
|
||||
linesWithTokens.formUnion(startLine...endLine)
|
||||
} else if let line = locationConverter.location(for: token.positionAfterSkippingLeadingTrivia).line {
|
||||
} else {
|
||||
let line = locationConverter.location(for: token.positionAfterSkippingLeadingTrivia).line
|
||||
linesWithTokens.insert(line)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,16 +31,14 @@ private extension Trivia {
|
|||
triviaOffset += trivia.sourceLength
|
||||
switch trivia {
|
||||
case .lineComment(let comment), .blockComment(let comment):
|
||||
if
|
||||
let lower = comment.range(of: "swiftlint:")?.lowerBound,
|
||||
case let actionString = String(comment[lower...]),
|
||||
case let end = locationConverter.location(for: offset + triviaOffset),
|
||||
let line = end.line,
|
||||
let column = end.column
|
||||
{
|
||||
let command = Command(actionString: actionString, line: line, character: column)
|
||||
results.append(command)
|
||||
guard let lower = comment.range(of: "swiftlint:")?.lowerBound else {
|
||||
break
|
||||
}
|
||||
|
||||
let actionString = String(comment[lower...])
|
||||
let end = locationConverter.location(for: offset + triviaOffset)
|
||||
let command = Command(actionString: actionString, line: end.line, character: end.column)
|
||||
results.append(command)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -20,9 +20,9 @@ def swiftlint_repos(bzlmod = False):
|
|||
|
||||
http_archive(
|
||||
name = "SwiftSyntax",
|
||||
sha256 = "8d21552ba8e28646ba11081d790d38d0986bd9920eaa67d8f9910402390f1e6e",
|
||||
strip_prefix = "swift-syntax-509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-02-a",
|
||||
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-05-02-a.tar.gz",
|
||||
sha256 = "7a3795ce1c94add3aeffafc84d0c94453655928dfe02ad8aefebdf24902c98a0",
|
||||
strip_prefix = "swift-syntax-509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a",
|
||||
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
|
|
Loading…
Reference in New Issue