Update SwiftSyntax to 04-10 snapshot (#4887)
https://github.com/apple/swift-syntax/releases/tag/509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a
This commit is contained in:
parent
409f117da9
commit
70a56a1420
|
@ -32,8 +32,8 @@
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apple/swift-syntax.git",
|
"location" : "https://github.com/apple/swift-syntax.git",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "07c08da983b2815a0acc8e3a477573e4c663b158",
|
"revision" : "2a9988f32c3439b1c850673cfccb085ddcde1395",
|
||||||
"version" : "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-03-17-a"
|
"version" : "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.2.1")),
|
.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-03-17-a"),
|
.package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a"),
|
||||||
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.34.1")),
|
.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/jpsim/Yams.git", from: "5.0.5"),
|
||||||
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
|
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
|
||||||
|
|
|
@ -231,7 +231,7 @@ extension FunctionDeclSyntax {
|
||||||
name += "("
|
name += "("
|
||||||
|
|
||||||
let params = signature.input.parameterList.compactMap { param in
|
let params = signature.input.parameterList.compactMap { param in
|
||||||
(param.firstName ?? param.secondName)?.text.appending(":")
|
param.firstName.text.appending(":")
|
||||||
}
|
}
|
||||||
|
|
||||||
name += params.joined()
|
name += params.joined()
|
||||||
|
|
|
@ -8,7 +8,7 @@ extension SyntaxClassification {
|
||||||
return true
|
return true
|
||||||
case .none, .keyword, .identifier, .typeIdentifier, .operatorIdentifier, .dollarIdentifier, .integerLiteral,
|
case .none, .keyword, .identifier, .typeIdentifier, .operatorIdentifier, .dollarIdentifier, .integerLiteral,
|
||||||
.floatingLiteral, .stringLiteral, .stringInterpolationAnchor, .poundDirectiveKeyword, .buildConfigId,
|
.floatingLiteral, .stringLiteral, .stringInterpolationAnchor, .poundDirectiveKeyword, .buildConfigId,
|
||||||
.attribute, .objectLiteral, .editorPlaceholder:
|
.attribute, .objectLiteral, .editorPlaceholder, .regexLiteral:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,8 +82,8 @@ enum LegacyFunctionRuleHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
return expr
|
return expr
|
||||||
.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
.with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, node.trailingTrivia)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,13 +47,13 @@ private extension BlockBasedKVORule {
|
||||||
case let parameterList = node.signature.input.parameterList,
|
case let parameterList = node.signature.input.parameterList,
|
||||||
parameterList.count == 4,
|
parameterList.count == 4,
|
||||||
node.identifier.text == "observeValue",
|
node.identifier.text == "observeValue",
|
||||||
parameterList.compactMap(\.firstName?.text) == ["forKeyPath", "of", "change", "context"]
|
parameterList.map(\.firstName.text) == ["forKeyPath", "of", "change", "context"]
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let types = parameterList
|
let types = parameterList
|
||||||
.compactMap { $0.type?.trimmedDescription.replacingOccurrences(of: " ", with: "") }
|
.map { $0.type.trimmedDescription.replacingOccurrences(of: " ", with: "") }
|
||||||
let firstTypes = ["String?", "Any?", "[NSKeyValueChangeKey:Any]?", "UnsafeMutableRawPointer?"]
|
let firstTypes = ["String?", "Any?", "[NSKeyValueChangeKey:Any]?", "UnsafeMutableRawPointer?"]
|
||||||
let secondTypes = ["String?", "Any?", "Dictionary<NSKeyValueChangeKey,Any>?", "UnsafeMutableRawPointer?"]
|
let secondTypes = ["String?", "Any?", "Dictionary<NSKeyValueChangeKey,Any>?", "UnsafeMutableRawPointer?"]
|
||||||
if types == firstTypes || types == secondTypes {
|
if types == firstTypes || types == secondTypes {
|
||||||
|
|
|
@ -104,20 +104,20 @@ private extension FunctionSignatureSyntax {
|
||||||
|
|
||||||
private extension FunctionParameterSyntax {
|
private extension FunctionParameterSyntax {
|
||||||
var isClosure: Bool {
|
var isClosure: Bool {
|
||||||
if isEscaping || type?.as(FunctionTypeSyntax.self) != nil {
|
if isEscaping || type.is(FunctionTypeSyntax.self) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if let optionalType = type?.as(OptionalTypeSyntax.self),
|
if let optionalType = type.as(OptionalTypeSyntax.self),
|
||||||
let tuple = optionalType.wrappedType.as(TupleTypeSyntax.self) {
|
let tuple = optionalType.wrappedType.as(TupleTypeSyntax.self) {
|
||||||
return tuple.elements.onlyElement?.type.as(FunctionTypeSyntax.self) != nil
|
return tuple.elements.onlyElement?.type.as(FunctionTypeSyntax.self) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if let tuple = type?.as(TupleTypeSyntax.self) {
|
if let tuple = type.as(TupleTypeSyntax.self) {
|
||||||
return tuple.elements.onlyElement?.type.as(FunctionTypeSyntax.self) != nil
|
return tuple.elements.onlyElement?.type.as(FunctionTypeSyntax.self) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if let attrType = type?.as(AttributedTypeSyntax.self) {
|
if let attrType = type.as(AttributedTypeSyntax.self) {
|
||||||
return attrType.baseType.is(FunctionTypeSyntax.self)
|
return attrType.baseType.is(FunctionTypeSyntax.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ private extension FunctionParameterSyntax {
|
||||||
}
|
}
|
||||||
|
|
||||||
var isEscaping: Bool {
|
var isEscaping: Bool {
|
||||||
guard let attrType = type?.as(AttributedTypeSyntax.self) else {
|
guard let attrType = type.as(AttributedTypeSyntax.self) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ private extension LegacyConstantRule {
|
||||||
|
|
||||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||||
return ("\(raw: correction)" as ExprSyntax)
|
return ("\(raw: correction)" as ExprSyntax)
|
||||||
.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
.with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, node.trailingTrivia)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax {
|
override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax {
|
||||||
|
@ -78,8 +78,8 @@ private extension LegacyConstantRule {
|
||||||
|
|
||||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||||
return ("\(raw: calledExpression.identifier.text).pi" as ExprSyntax)
|
return ("\(raw: calledExpression.identifier.text).pi" as ExprSyntax)
|
||||||
.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
.with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, node.trailingTrivia)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,8 +80,8 @@ private extension PreferZeroOverExplicitInitRule {
|
||||||
.with(\.base, "\(raw: name)")
|
.with(\.base, "\(raw: name)")
|
||||||
return super.visit(
|
return super.visit(
|
||||||
newNode
|
newNode
|
||||||
.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
.with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, node.trailingTrivia)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,8 +252,8 @@ private extension ModifierListSyntax {
|
||||||
\.name,
|
\.name,
|
||||||
.keyword(
|
.keyword(
|
||||||
.private,
|
.private,
|
||||||
leadingTrivia: fileprivateModifier.leadingTrivia ?? .zero,
|
leadingTrivia: fileprivateModifier.leadingTrivia,
|
||||||
trailingTrivia: fileprivateModifier.trailingTrivia ?? .zero
|
trailingTrivia: fileprivateModifier.trailingTrivia
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -170,9 +170,9 @@ private extension RedundantOptionalInitializationRule {
|
||||||
return newBinding
|
return newBinding
|
||||||
}
|
}
|
||||||
if binding.trailingComma != nil {
|
if binding.trailingComma != nil {
|
||||||
return newBinding.with(\.typeAnnotation, binding.typeAnnotation?.with(\.trailingTrivia, .zero))
|
return newBinding.with(\.typeAnnotation, binding.typeAnnotation?.with(\.trailingTrivia, Trivia()))
|
||||||
}
|
}
|
||||||
return newBinding.with(\.trailingTrivia, binding.initializer?.trailingTrivia ?? .zero)
|
return newBinding.with(\.trailingTrivia, binding.initializer?.trailingTrivia ?? Trivia())
|
||||||
})
|
})
|
||||||
|
|
||||||
return super.visit(node.with(\.bindings, newBindings))
|
return super.visit(node.with(\.bindings, newBindings))
|
||||||
|
|
|
@ -122,7 +122,7 @@ private class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter {
|
||||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||||
let newNode = node
|
let newNode = node
|
||||||
.with(\.initializer, nil)
|
.with(\.initializer, nil)
|
||||||
.with(\.pattern, node.pattern.with(\.trailingTrivia, node.trailingTrivia ?? .zero))
|
.with(\.pattern, node.pattern.with(\.trailingTrivia, node.trailingTrivia))
|
||||||
return super.visit(newNode)
|
return super.visit(newNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,8 @@ private extension ToggleBoolRule {
|
||||||
)
|
)
|
||||||
.removingLast()
|
.removingLast()
|
||||||
.removingLast()
|
.removingLast()
|
||||||
.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
.with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, node.trailingTrivia)
|
||||||
|
|
||||||
return super.visit(newNode)
|
return super.visit(newNode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ private extension TrailingSemicolonRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||||
return .unknown("").with(\.trailingTrivia, node.trailingTrivia ?? .zero)
|
return .unknown("").with(\.trailingTrivia, node.trailingTrivia)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,8 @@ private extension AnyObjectProtocolRule {
|
||||||
\.typeName,
|
\.typeName,
|
||||||
TypeSyntax(
|
TypeSyntax(
|
||||||
SimpleTypeIdentifierSyntax(name: .identifier("AnyObject"), genericArgumentClause: nil)
|
SimpleTypeIdentifierSyntax(name: .identifier("AnyObject"), genericArgumentClause: nil)
|
||||||
.with(\.leadingTrivia, typeName.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, typeName.leadingTrivia)
|
||||||
.with(\.trailingTrivia, typeName.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, typeName.trailingTrivia)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -104,9 +104,9 @@ private extension ClosureSignatureSyntax {
|
||||||
func singleInputParamText() -> String? {
|
func singleInputParamText() -> String? {
|
||||||
if let list = input?.as(ClosureParamListSyntax.self), list.count == 1 {
|
if let list = input?.as(ClosureParamListSyntax.self), list.count == 1 {
|
||||||
return list.onlyElement?.name.text
|
return list.onlyElement?.name.text
|
||||||
} else if let clause = input?.as(ParameterClauseSyntax.self), clause.parameterList.count == 1,
|
} else if let clause = input?.as(ClosureParameterClauseSyntax.self), clause.parameterList.count == 1,
|
||||||
clause.parameterList.first?.secondName == nil {
|
clause.parameterList.first?.secondName == nil {
|
||||||
return clause.parameterList.first?.firstName?.text
|
return clause.parameterList.first?.firstName.text
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,13 @@ private extension LowerACLThanParentRule {
|
||||||
let newNode: DeclModifierSyntax
|
let newNode: DeclModifierSyntax
|
||||||
if node.name.tokenKind == .keyword(.open) {
|
if node.name.tokenKind == .keyword(.open) {
|
||||||
newNode = DeclModifierSyntax(
|
newNode = DeclModifierSyntax(
|
||||||
leadingTrivia: node.leadingTrivia ?? .zero,
|
leadingTrivia: node.leadingTrivia,
|
||||||
name: .keyword(.public),
|
name: .keyword(.public),
|
||||||
trailingTrivia: .space
|
trailingTrivia: .space
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
newNode = DeclModifierSyntax(
|
newNode = DeclModifierSyntax(
|
||||||
leadingTrivia: node.leadingTrivia ?? .zero,
|
leadingTrivia: node.leadingTrivia,
|
||||||
name: .identifier("")
|
name: .identifier("")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,9 @@ private extension FunctionDeclSyntax {
|
||||||
parameterList.count == 2,
|
parameterList.count == 2,
|
||||||
let lhs = parameterList.first,
|
let lhs = parameterList.first,
|
||||||
let rhs = parameterList.last,
|
let rhs = parameterList.last,
|
||||||
lhs.firstName?.text == "lhs",
|
lhs.firstName.text == "lhs",
|
||||||
rhs.firstName?.text == "rhs",
|
rhs.firstName.text == "rhs",
|
||||||
let lhsTypeDescription = lhs.type?.trimmedDescription,
|
lhs.type.trimmedDescription == rhs.type.trimmedDescription
|
||||||
let rhsTypeDescription = rhs.type?.trimmedDescription,
|
|
||||||
lhsTypeDescription == rhsTypeDescription
|
|
||||||
else {
|
else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,17 +224,17 @@ private class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter {
|
||||||
return (nil, declKeyword)
|
return (nil, declKeyword)
|
||||||
}
|
}
|
||||||
var filteredModifiers = [DeclModifierSyntax]()
|
var filteredModifiers = [DeclModifierSyntax]()
|
||||||
var leadingTrivia = Trivia.zero
|
var leadingTrivia = Trivia()
|
||||||
for modifier in modifiers {
|
for modifier in modifiers {
|
||||||
let accumulatedLeadingTrivia = leadingTrivia + (modifier.leadingTrivia ?? .zero)
|
let accumulatedLeadingTrivia = leadingTrivia + (modifier.leadingTrivia)
|
||||||
if modifier.name.tokenKind == .keyword(.private) {
|
if modifier.name.tokenKind == .keyword(.private) {
|
||||||
leadingTrivia = accumulatedLeadingTrivia
|
leadingTrivia = accumulatedLeadingTrivia
|
||||||
} else {
|
} else {
|
||||||
filteredModifiers.append(modifier.with(\.leadingTrivia, accumulatedLeadingTrivia))
|
filteredModifiers.append(modifier.with(\.leadingTrivia, accumulatedLeadingTrivia))
|
||||||
leadingTrivia = .zero
|
leadingTrivia = Trivia()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let declKeyword = declKeyword.with(\.leadingTrivia, leadingTrivia + (declKeyword.leadingTrivia ?? .zero))
|
let declKeyword = declKeyword.with(\.leadingTrivia, leadingTrivia + (declKeyword.leadingTrivia))
|
||||||
return (ModifierListSyntax(filteredModifiers), declKeyword)
|
return (ModifierListSyntax(filteredModifiers), declKeyword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,16 +69,13 @@ private extension UnusedClosureParameterRule {
|
||||||
.walk(tree: node.statements, handler: \.identifiers)
|
.walk(tree: node.statements, handler: \.identifiers)
|
||||||
|
|
||||||
guard let params = input.as(ClosureParamListSyntax.self) else {
|
guard let params = input.as(ClosureParamListSyntax.self) else {
|
||||||
guard let params = input.as(ParameterClauseSyntax.self) else {
|
guard let params = input.as(ClosureParameterClauseSyntax.self) else {
|
||||||
return super.visit(node)
|
return super.visit(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
var newParams = params
|
var newParams = params
|
||||||
for (index, param) in params.parameterList.enumerated() {
|
for (index, param) in params.parameterList.enumerated() {
|
||||||
guard let name = param.firstName else {
|
let name = param.firstName
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if name.tokenKind == .wildcard {
|
if name.tokenKind == .wildcard {
|
||||||
continue
|
continue
|
||||||
} else if referencedIdentifiers.contains(name.text.removingDollarsAndBackticks) {
|
} else if referencedIdentifiers.contains(name.text.removingDollarsAndBackticks) {
|
||||||
|
@ -148,17 +145,15 @@ private extension ClosureExprSyntax {
|
||||||
name: param.name.text.removingDollarsAndBackticks
|
name: param.name.text.removingDollarsAndBackticks
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if let params = signature?.input?.as(ParameterClauseSyntax.self)?.parameterList {
|
} else if let params = signature?.input?.as(ClosureParameterClauseSyntax.self)?.parameterList {
|
||||||
return params.compactMap { param in
|
return params.compactMap { param in
|
||||||
if param.firstName?.tokenKind == .wildcard {
|
if param.firstName.tokenKind == .wildcard {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return param.firstName.map { name in
|
return ClosureParam(
|
||||||
ClosureParam(
|
position: param.firstName.positionAfterSkippingLeadingTrivia,
|
||||||
position: name.positionAfterSkippingLeadingTrivia,
|
name: param.firstName.text.removingDollarsAndBackticks
|
||||||
name: name.text.removingDollarsAndBackticks
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -122,7 +122,7 @@ private extension UnusedControlFlowLabelRule {
|
||||||
return super.visit(node)
|
return super.visit(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
let newNode = node.statement.with(\.leadingTrivia, node.leadingTrivia ?? .zero)
|
let newNode = node.statement.with(\.leadingTrivia, node.leadingTrivia)
|
||||||
correctionPositions.append(violationPosition)
|
correctionPositions.append(violationPosition)
|
||||||
return visit(newNode).as(StmtSyntax.self) ?? newNode
|
return visit(newNode).as(StmtSyntax.self) ?? newNode
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,10 @@ private extension AttributesRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
let hasMultipleNewlines = node.children(viewMode: .sourceAccurate).enumerated().contains { index, element in
|
let hasMultipleNewlines = node.children(viewMode: .sourceAccurate).enumerated().contains { index, element in
|
||||||
if index > 0 && element.leadingTrivia?.hasMultipleNewlines == true {
|
if index > 0 && element.leadingTrivia.hasMultipleNewlines == true {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return element.trailingTrivia?.hasMultipleNewlines == true
|
return element.trailingTrivia.hasMultipleNewlines == true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ private extension ClosingBraceRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||||
return super.visit(node.with(\.trailingTrivia, .zero))
|
return super.visit(node.with(\.trailingTrivia, Trivia()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ private extension ClosureSignatureSyntax {
|
||||||
|
|
||||||
if let input = input?.as(ClosureParamListSyntax.self) {
|
if let input = input?.as(ClosureParamListSyntax.self) {
|
||||||
positions.append(contentsOf: input.map(\.positionAfterSkippingLeadingTrivia))
|
positions.append(contentsOf: input.map(\.positionAfterSkippingLeadingTrivia))
|
||||||
} else if let input = input?.as(ParameterClauseSyntax.self) {
|
} else if let input = input?.as(ClosureParameterClauseSyntax.self) {
|
||||||
positions.append(contentsOf: input.parameterList.map(\.positionAfterSkippingLeadingTrivia))
|
positions.append(contentsOf: input.parameterList.map(\.positionAfterSkippingLeadingTrivia))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,9 +245,9 @@ private class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter {
|
||||||
item: .stmt(StmtSyntax(returnStmt.with(\.expression, initExpression)))
|
item: .stmt(StmtSyntax(returnStmt.with(\.expression, initExpression)))
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let leadingTrivia = (varDecl.leadingTrivia?.withoutTrailingIndentation ?? .zero)
|
let leadingTrivia = varDecl.leadingTrivia.withoutTrailingIndentation +
|
||||||
+ (varDecl.trailingTrivia ?? .zero)
|
varDecl.trailingTrivia +
|
||||||
+ (returnStmt.leadingTrivia?.withFirstEmptyLineRemoved ?? .zero)
|
returnStmt.leadingTrivia.withFirstEmptyLineRemoved
|
||||||
newStmtList.append(
|
newStmtList.append(
|
||||||
CodeBlockItemSyntax(
|
CodeBlockItemSyntax(
|
||||||
item: .stmt(
|
item: .stmt(
|
||||||
|
|
|
@ -222,7 +222,7 @@ private extension FunctionCallExprSyntax {
|
||||||
|
|
||||||
if argumentList.allSatisfy({ $0.expression.is(DiscardAssignmentExprSyntax.self) }) {
|
if argumentList.allSatisfy({ $0.expression.is(DiscardAssignmentExprSyntax.self) }) {
|
||||||
let newCalledExpression = calledExpression
|
let newCalledExpression = calledExpression
|
||||||
.with(\.trailingTrivia, rightParen?.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, rightParen?.trailingTrivia ?? Trivia())
|
||||||
let newExpression = self
|
let newExpression = self
|
||||||
.with(\.calledExpression, ExprSyntax(newCalledExpression))
|
.with(\.calledExpression, ExprSyntax(newCalledExpression))
|
||||||
.with(\.leftParen, nil)
|
.with(\.leftParen, nil)
|
||||||
|
|
|
@ -94,7 +94,7 @@ private extension InclusiveLanguageRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func visitPost(_ node: FunctionParameterSyntax) {
|
override func visitPost(_ node: FunctionParameterSyntax) {
|
||||||
if let name = node.firstName, let violation = violation(for: name) {
|
if let violation = violation(for: node.firstName) {
|
||||||
violations.append(violation)
|
violations.append(violation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,9 +194,7 @@ private extension MultilineArgumentsBracketsRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func hasLeadingNewline(_ syntax: SyntaxProtocol) -> Bool {
|
private func hasLeadingNewline(_ syntax: SyntaxProtocol) -> Bool {
|
||||||
guard let leadingTrivia = syntax.leadingTrivia else { return false }
|
syntax.leadingTrivia.contains(where: \.isNewline)
|
||||||
|
|
||||||
return leadingTrivia.pieces.contains { $0.isNewline }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,13 +98,8 @@ private extension NoSpaceInMethodCallRule {
|
||||||
|
|
||||||
private extension FunctionCallExprSyntax {
|
private extension FunctionCallExprSyntax {
|
||||||
var hasNoSpaceInMethodCallViolation: Bool {
|
var hasNoSpaceInMethodCallViolation: Bool {
|
||||||
guard leftParen != nil,
|
leftParen != nil &&
|
||||||
!calledExpression.is(TupleExprSyntax.self),
|
!calledExpression.is(TupleExprSyntax.self) &&
|
||||||
let trailingTrivia = calledExpression.trailingTrivia,
|
calledExpression.trailingTrivia.isNotEmpty
|
||||||
trailingTrivia.isNotEmpty else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,8 +149,8 @@ private extension PreferSelfTypeOverTypeOfSelfRule {
|
||||||
|
|
||||||
let base = IdentifierExprSyntax(identifier: "Self")
|
let base = IdentifierExprSyntax(identifier: "Self")
|
||||||
let baseWithTrivia = base
|
let baseWithTrivia = base
|
||||||
.with(\.leadingTrivia, function.leadingTrivia ?? .zero)
|
.with(\.leadingTrivia, function.leadingTrivia)
|
||||||
.with(\.trailingTrivia, function.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, function.trailingTrivia)
|
||||||
return super.visit(node.with(\.base, ExprSyntax(baseWithTrivia)))
|
return super.visit(node.with(\.base, ExprSyntax(baseWithTrivia)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ private final class SelfBindingRuleRewriter: SyntaxRewriter, ViolationsSyntaxRew
|
||||||
identifier: .keyword(
|
identifier: .keyword(
|
||||||
.`self`,
|
.`self`,
|
||||||
leadingTrivia: .space,
|
leadingTrivia: .space,
|
||||||
trailingTrivia: identifierPattern.trailingTrivia ?? .space
|
trailingTrivia: identifierPattern.trailingTrivia
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -135,7 +135,7 @@ private extension TrailingCommaRule {
|
||||||
switch (lastElement.trailingComma, mandatoryComma) {
|
switch (lastElement.trailingComma, mandatoryComma) {
|
||||||
case (let commaToken?, false):
|
case (let commaToken?, false):
|
||||||
correctionPositions.append(commaToken.positionAfterSkippingLeadingTrivia)
|
correctionPositions.append(commaToken.positionAfterSkippingLeadingTrivia)
|
||||||
let newTrailingTrivia = (lastElement.valueExpression.trailingTrivia ?? .zero)
|
let newTrailingTrivia = (lastElement.valueExpression.trailingTrivia)
|
||||||
.appending(trivia: commaToken.leadingTrivia)
|
.appending(trivia: commaToken.leadingTrivia)
|
||||||
.appending(trivia: commaToken.trailingTrivia)
|
.appending(trivia: commaToken.trailingTrivia)
|
||||||
let newNode = node
|
let newNode = node
|
||||||
|
@ -154,7 +154,7 @@ private extension TrailingCommaRule {
|
||||||
with: lastElement
|
with: lastElement
|
||||||
.with(\.trailingTrivia, [])
|
.with(\.trailingTrivia, [])
|
||||||
.with(\.trailingComma, .commaToken())
|
.with(\.trailingComma, .commaToken())
|
||||||
.with(\.trailingTrivia, lastElement.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, lastElement.trailingTrivia)
|
||||||
)
|
)
|
||||||
return super.visit(newNode)
|
return super.visit(newNode)
|
||||||
case (_, true), (nil, false):
|
case (_, true), (nil, false):
|
||||||
|
@ -177,7 +177,7 @@ private extension TrailingCommaRule {
|
||||||
with: lastElement
|
with: lastElement
|
||||||
.with(\.trailingComma, nil)
|
.with(\.trailingComma, nil)
|
||||||
.with(\.trailingTrivia,
|
.with(\.trailingTrivia,
|
||||||
(lastElement.expression.trailingTrivia ?? .zero)
|
(lastElement.expression.trailingTrivia)
|
||||||
.appending(trivia: commaToken.leadingTrivia)
|
.appending(trivia: commaToken.leadingTrivia)
|
||||||
.appending(trivia: commaToken.trailingTrivia)
|
.appending(trivia: commaToken.trailingTrivia)
|
||||||
)
|
)
|
||||||
|
@ -190,7 +190,7 @@ private extension TrailingCommaRule {
|
||||||
with: lastElement
|
with: lastElement
|
||||||
.with(\.expression, lastElement.expression.with(\.trailingTrivia, []))
|
.with(\.expression, lastElement.expression.with(\.trailingTrivia, []))
|
||||||
.with(\.trailingComma, .commaToken())
|
.with(\.trailingComma, .commaToken())
|
||||||
.with(\.trailingTrivia, lastElement.expression.trailingTrivia ?? .zero)
|
.with(\.trailingTrivia, lastElement.expression.trailingTrivia)
|
||||||
)
|
)
|
||||||
return super.visit(newNode)
|
return super.visit(newNode)
|
||||||
case (_, true), (nil, false):
|
case (_, true), (nil, false):
|
||||||
|
|
|
@ -89,9 +89,9 @@ struct UnneededParenthesesInClosureArgumentRule: ConfigurationProviderRule,
|
||||||
|
|
||||||
private final class Visitor: ViolationsSyntaxVisitor {
|
private final class Visitor: ViolationsSyntaxVisitor {
|
||||||
override func visitPost(_ node: ClosureSignatureSyntax) {
|
override func visitPost(_ node: ClosureSignatureSyntax) {
|
||||||
guard let clause = node.input?.as(ParameterClauseSyntax.self),
|
guard let clause = node.input?.as(ClosureParameterClauseSyntax.self),
|
||||||
!clause.parameterList.contains(where: { $0.type != nil }),
|
clause.parameterList.isNotEmpty,
|
||||||
clause.parameterList.isNotEmpty else {
|
clause.parameterList.allSatisfy({ $0.type == nil }) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,19 +111,16 @@ private final class Rewriter: SyntaxRewriter, ViolationsSyntaxRewriter {
|
||||||
|
|
||||||
override func visit(_ node: ClosureSignatureSyntax) -> ClosureSignatureSyntax {
|
override func visit(_ node: ClosureSignatureSyntax) -> ClosureSignatureSyntax {
|
||||||
guard
|
guard
|
||||||
let clause = node.input?.as(ParameterClauseSyntax.self),
|
let clause = node.input?.as(ClosureParameterClauseSyntax.self),
|
||||||
!clause.parameterList.contains(where: { $0.type != nil }),
|
|
||||||
clause.parameterList.isNotEmpty,
|
clause.parameterList.isNotEmpty,
|
||||||
|
clause.parameterList.allSatisfy({ $0.type == nil }),
|
||||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter)
|
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter)
|
||||||
else {
|
else {
|
||||||
return super.visit(node)
|
return super.visit(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
let items = clause.parameterList.enumerated().compactMap { idx, param -> ClosureParamSyntax? in
|
let items = clause.parameterList.enumerated().compactMap { idx, param -> ClosureParamSyntax? in
|
||||||
guard let name = param.firstName else {
|
let name = param.firstName
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let isLast = idx == clause.parameterList.count - 1
|
let isLast = idx == clause.parameterList.count - 1
|
||||||
return ClosureParamSyntax(
|
return ClosureParamSyntax(
|
||||||
name: name,
|
name: name,
|
||||||
|
|
|
@ -20,10 +20,10 @@ def swiftlint_repos(bzlmod = False):
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "com_github_apple_swift_syntax",
|
name = "com_github_apple_swift_syntax",
|
||||||
sha256 = "0698b10d5784bc91fc60cd740f8c16dbe7debcea67759fdf293bb1c8bdb6eedc", # SwiftSyntax sha256
|
sha256 = "3b9380abc9a3d15fc718d87f1c278d978078d777bb03e3861b904aad6ef6bb54", # SwiftSyntax sha256
|
||||||
build_file = "@SwiftLint//bazel:SwiftSyntax.BUILD",
|
build_file = "@SwiftLint//bazel:SwiftSyntax.BUILD",
|
||||||
strip_prefix = "swift-syntax-509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-03-17-a",
|
strip_prefix = "swift-syntax-509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a",
|
||||||
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-03-17-a.tar.gz",
|
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a.tar.gz",
|
||||||
)
|
)
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
|
|
Loading…
Reference in New Issue