diff --git a/.swift-format b/.swift-format index edc7d7be8aa..7f5edf8f69e 100644 --- a/.swift-format +++ b/.swift-format @@ -12,7 +12,7 @@ "AmbiguousTrailingClosureOverload": false, "NoBlockComments": false, "OrderedImports": true, - "UseLetInEveryBoundCaseVariable": false, + "UseLetInEveryBoundCaseVariable": true, "UseSynthesizedInitializer": true } } diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift index b98a8024348..bfb6fb2698c 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/ParserTokenSpecSetFile.swift @@ -39,7 +39,7 @@ let parserTokenSpecSetFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { for layoutNode in SYNTAX_NODES.compactMap(\.layoutNode) { for child in layoutNode.children { - if case let .token(choices, _, _) = child.kind, choices.count > 1 { + if case .token(let choices, _, _) = child.kind, choices.count > 1 { try! ExtensionDeclSyntax("extension \(layoutNode.kind.syntaxType)") { try EnumDeclSyntax( """ diff --git a/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift b/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift index 01510a12726..1eb55906d67 100644 --- a/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/Accessor/EnvironmentValueMacro.swift @@ -20,7 +20,7 @@ public struct EnvironmentValueMacro: AccessorMacro { in context: some MacroExpansionContext ) throws -> [AccessorDeclSyntax] { guard - case let .argumentList(arguments) = node.arguments, + case .argumentList(let arguments) = node.arguments, let argument = arguments.first else { return [] } diff --git a/Examples/Sources/MacroExamples/Implementation/ComplexMacros/OptionSetMacro.swift b/Examples/Sources/MacroExamples/Implementation/ComplexMacros/OptionSetMacro.swift index 5b7eed9de30..9b7f55f1812 100644 --- a/Examples/Sources/MacroExamples/Implementation/ComplexMacros/OptionSetMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/ComplexMacros/OptionSetMacro.swift @@ -84,13 +84,13 @@ public struct OptionSetMacro { ) -> (StructDeclSyntax, EnumDeclSyntax, TypeSyntax)? { // Determine the name of the options enum. let optionsEnumName: String - if case let .argumentList(arguments) = attribute.arguments, + if case .argumentList(let arguments) = attribute.arguments, let optionEnumNameArg = arguments.first(labeled: optionsEnumNameArgumentLabel) { // We have a options name; make sure it is a string literal. guard let stringLiteral = optionEnumNameArg.expression.as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(optionsEnumNameString)? = stringLiteral.segments.first + case .stringSegment(let optionsEnumNameString)? = stringLiteral.segments.first else { if emitDiagnostics { context.diagnose( diff --git a/Examples/Sources/MacroExamples/Implementation/Expression/WarningMacro.swift b/Examples/Sources/MacroExamples/Implementation/Expression/WarningMacro.swift index 9f2163c04a1..2b42ebe046e 100644 --- a/Examples/Sources/MacroExamples/Implementation/Expression/WarningMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/Expression/WarningMacro.swift @@ -25,7 +25,7 @@ public enum WarningMacro: ExpressionMacro { let stringLiteral = firstElement.expression .as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(messageString)? = stringLiteral.segments.first + case .stringSegment(let messageString)? = stringLiteral.segments.first else { throw CustomError.message("#myWarning macro requires a string literal") } diff --git a/Examples/Sources/MacroExamples/Implementation/MemberAttribute/WrapStoredPropertiesMacro.swift b/Examples/Sources/MacroExamples/Implementation/MemberAttribute/WrapStoredPropertiesMacro.swift index edb48902216..fd5cf3d9bb9 100644 --- a/Examples/Sources/MacroExamples/Implementation/MemberAttribute/WrapStoredPropertiesMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/MemberAttribute/WrapStoredPropertiesMacro.swift @@ -36,12 +36,12 @@ public struct WrapStoredPropertiesMacro: MemberAttributeMacro { return [] } - guard case let .argumentList(arguments) = node.arguments, + guard case .argumentList(let arguments) = node.arguments, let firstElement = arguments.first, let stringLiteral = firstElement.expression .as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(wrapperName)? = stringLiteral.segments.first + case .stringSegment(let wrapperName)? = stringLiteral.segments.first else { throw CustomError.message("macro requires a string literal containing the name of an attribute") } diff --git a/Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift b/Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift index 4e25660cff8..58fc6606d9c 100644 --- a/Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/Peer/AddAsyncMacro.swift @@ -89,7 +89,7 @@ public struct AddAsyncMacro: PeerMacro { // Drop the @addAsync attribute from the new declaration. let newAttributeList = funcDecl.attributes.filter { - guard case let .attribute(attribute) = $0, + guard case .attribute(let attribute) = $0, let attributeType = attribute.attributeName.as(IdentifierTypeSyntax.self), let nodeType = node.attributeName.as(IdentifierTypeSyntax.self) else { diff --git a/Examples/Sources/MacroExamples/Implementation/Peer/AddCompletionHandlerMacro.swift b/Examples/Sources/MacroExamples/Implementation/Peer/AddCompletionHandlerMacro.swift index 971a9c7a343..d223e270041 100644 --- a/Examples/Sources/MacroExamples/Implementation/Peer/AddCompletionHandlerMacro.swift +++ b/Examples/Sources/MacroExamples/Implementation/Peer/AddCompletionHandlerMacro.swift @@ -128,7 +128,7 @@ public struct AddCompletionHandlerMacro: PeerMacro { // Drop the @addCompletionHandler attribute from the new declaration. let newAttributeList = funcDecl.attributes.filter { - guard case let .attribute(attribute) = $0, + guard case .attribute(let attribute) = $0, let attributeType = attribute.attributeName.as(IdentifierTypeSyntax.self), let nodeType = node.attributeName.as(IdentifierTypeSyntax.self) else { diff --git a/Sources/SwiftCompilerPluginMessageHandling/JSON/CodingUtilities.swift b/Sources/SwiftCompilerPluginMessageHandling/JSON/CodingUtilities.swift index b423f7caea4..4f505c789e0 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/JSON/CodingUtilities.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/JSON/CodingUtilities.swift @@ -26,9 +26,9 @@ internal enum _CodingPathNode { switch self { case .root: return [] - case let .node(key, parent): + case .node(let key, let parent): return parent.path + [key] - case let .indexNode(index, parent): + case .indexNode(let index, let parent): return parent.path + [_CodingKey(index: index)] } } @@ -87,17 +87,17 @@ internal enum _CodingKey: CodingKey { var stringValue: String { switch self { - case let .string(str): return str - case let .int(int): return "\(int)" - case let .index(index): return "Index \(index)" + case .string(let str): return str + case .int(let int): return "\(int)" + case .index(let index): return "Index \(index)" } } var intValue: Int? { switch self { case .string: return nil - case let .int(int): return int - case let .index(index): return index + case .int(let int): return int + case .index(let index): return index } } } diff --git a/Sources/SwiftCompilerPluginMessageHandling/LRUCache.swift b/Sources/SwiftCompilerPluginMessageHandling/LRUCache.swift index aa67204fd5a..7f65620067d 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/LRUCache.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/LRUCache.swift @@ -56,17 +56,17 @@ public class LRUCache { set { switch (table[key], newValue) { - case let (nil, newValue?): // create. + case (nil, let newValue?): // create. self.ensureCapacityForNewValue() let node = _Node(key: key, value: newValue) addToHead(node: node) table[key] = node - case let (node?, newValue?): // update. + case (let node?, let newValue?): // update. moveToHead(node: node) node.value = newValue - case let (node?, nil): // delete. + case (let node?, nil): // delete. remove(node: node) table[key] = nil diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index f04b0d938cd..2097ac818dd 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -293,7 +293,7 @@ extension Parser { } switch kind { - case let .optional(unexpectedBeforeBindingKeyword, bindingSpecifier, pattern): + case .optional(let unexpectedBeforeBindingKeyword, let bindingSpecifier, let pattern): return .optionalBinding( RawOptionalBindingConditionSyntax( unexpectedBeforeBindingKeyword, @@ -304,7 +304,7 @@ extension Parser { arena: self.arena ) ) - case let .pattern(caseKeyword, pattern): + case .pattern(let caseKeyword, let pattern): return .matchingPattern( RawMatchingPatternConditionSyntax( caseKeyword: caseKeyword, diff --git a/Sources/SwiftRefactor/ConvertComputedPropertyToStored.swift b/Sources/SwiftRefactor/ConvertComputedPropertyToStored.swift index 64d73884a41..7ff57e5466a 100644 --- a/Sources/SwiftRefactor/ConvertComputedPropertyToStored.swift +++ b/Sources/SwiftRefactor/ConvertComputedPropertyToStored.swift @@ -19,7 +19,7 @@ import SwiftSyntax public struct ConvertComputedPropertyToStored: SyntaxRefactoringProvider { public static func refactor(syntax: VariableDeclSyntax, in context: ()) -> VariableDeclSyntax? { guard syntax.bindings.count == 1, let binding = syntax.bindings.first, - let accessorBlock = binding.accessorBlock, case let .getter(body) = accessorBlock.accessors, !body.isEmpty + let accessorBlock = binding.accessorBlock, case .getter(let body) = accessorBlock.accessors, !body.isEmpty else { return nil } diff --git a/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift b/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift index 7ebd8c60634..f071d91a99c 100644 --- a/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift +++ b/Sources/SwiftRefactor/ExpandEditorPlaceholder.swift @@ -94,9 +94,9 @@ struct ExpandSingleEditorPlaceholder: EditRefactoringProvider { let expanded: String switch placeholder { - case let .basic(text): + case .basic(let text): expanded = String(text) - case let .typed(text, type): + case .typed(let text, let type): if let functionType = type.as(FunctionTypeSyntax.self) { let basicFormat = BasicFormat( indentationWidth: context.indentationWidth, @@ -326,7 +326,7 @@ extension FunctionCallExprSyntax { guard let expr = arg.expression.as(DeclReferenceExprSyntax.self), expr.baseName.isEditorPlaceholder, let data = EditorPlaceholderData(token: expr.baseName), - case let .typed(_, type) = data, + case .typed(_, let type) = data, type.is(FunctionTypeSyntax.self) else { break diff --git a/Sources/SwiftSyntax/Documentation.docc/Resources/Formatter.step10.swift b/Sources/SwiftSyntax/Documentation.docc/Resources/Formatter.step10.swift index b4227242532..ea2ccf7fc48 100644 --- a/Sources/SwiftSyntax/Documentation.docc/Resources/Formatter.step10.swift +++ b/Sources/SwiftSyntax/Documentation.docc/Resources/Formatter.step10.swift @@ -38,8 +38,8 @@ import SwiftSyntax items[.. SourceLength { var lineLength = prefix switch self { - case let .spaces(count), - let .tabs(count), - let .verticalTabs(count), - let .formfeeds(count), - let .backslashes(count), - let .pounds(count): + case .spaces(let count), + .tabs(let count), + .verticalTabs(let count), + .formfeeds(let count), + .backslashes(let count), + .pounds(let count): lineLength += SourceLength(utf8Length: count) - case let .newlines(count), - let .carriageReturns(count): + case .newlines(let count), + .carriageReturns(let count): let newLineLength = SourceLength(utf8Length: 1) body(lineLength + newLineLength) for _ in 1.. ExprSyntax { // Dig out the argument list. let argumentList: LabeledExprListSyntax? - if case let .argumentList(argList) = node.arguments { + if case .argumentList(let argList) = node.arguments { argumentList = argList } else { argumentList = nil diff --git a/Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift b/Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift index 7c51fbcbe89..58268e170a1 100644 --- a/Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift +++ b/Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift @@ -993,7 +993,7 @@ extension MacroApplication { } return attributedNode.attributes.compactMap { - guard case let .attribute(attribute) = $0, + guard case .attribute(let attribute) = $0, let attributeName = attribute.attributeName.as(IdentifierTypeSyntax.self)?.name.text, let macroSpec = macroSystem.lookup(attributeName) else { diff --git a/Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift b/Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift index 60aa6e8f9c3..6dfb8eb2d29 100644 --- a/Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift +++ b/Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift @@ -161,9 +161,9 @@ public enum SubtreeError: Error, CustomStringConvertible { public var description: String { switch self { - case let .invalidMarker(name): + case .invalidMarker(let name): return "Could not find marker with name '\(name)'" - case let .invalidSubtree(tree, afterUTF8Offset, type): + case .invalidSubtree(let tree, let afterUTF8Offset, let type): return "Could not find subtree after UTF8 offset \(afterUTF8Offset) with type \(type) in:\n\(tree.debugDescription)" } diff --git a/Tests/SwiftOperatorsTest/OperatorTableTests.swift b/Tests/SwiftOperatorsTest/OperatorTableTests.swift index e4c81c4605b..12794e1ce16 100644 --- a/Tests/SwiftOperatorsTest/OperatorTableTests.swift +++ b/Tests/SwiftOperatorsTest/OperatorTableTests.swift @@ -214,7 +214,7 @@ class OperatorPrecedenceTests: XCTestCase { } XCTAssertEqual(errors.count, 2) - guard case let .operatorAlreadyExists(existing, new) = errors[0] else { + guard case .operatorAlreadyExists(let existing, let new) = errors[0] else { XCTFail("expected an 'operator already exists' error") return } @@ -223,7 +223,7 @@ class OperatorPrecedenceTests: XCTestCase { _ = existing _ = new - guard case let .groupAlreadyExists(existingGroup, newGroup) = errors[1] else { + guard case .groupAlreadyExists(let existingGroup, let newGroup) = errors[1] else { XCTFail("expected a 'group already exists' error") return } @@ -254,7 +254,7 @@ class OperatorPrecedenceTests: XCTestCase { } XCTAssertEqual(errors.count, 2) - guard case let .operatorAlreadyExists(existing, new) = errors[0] else { + guard case .operatorAlreadyExists(let existing, let new) = errors[0] else { XCTFail("expected an 'operator already exists' error") return } @@ -305,7 +305,7 @@ class OperatorPrecedenceTests: XCTestCase { } XCTAssertEqual(errors.count, 2) - guard case let .missingGroup(groupName, location) = errors[0] else { + guard case .missingGroup(let groupName, let location) = errors[0] else { XCTFail("expected a 'missing group' error") return } @@ -324,7 +324,7 @@ class OperatorPrecedenceTests: XCTestCase { } XCTAssertEqual(errors.count, 1) - guard case let .missingOperator(operatorName, location) = errors[0] else { + guard case .missingOperator(let operatorName, let location) = errors[0] else { XCTFail("expected a 'missing operator' error") return } @@ -344,7 +344,7 @@ class OperatorPrecedenceTests: XCTestCase { XCTAssertEqual(errors.count, 1) guard - case let .incomparableOperators(_, leftGroup, _, rightGroup) = + case .incomparableOperators(_, let leftGroup, _, let rightGroup) = errors[0] else { XCTFail("expected an 'incomparable operator' error") @@ -369,7 +369,7 @@ class OperatorPrecedenceTests: XCTestCase { XCTAssertEqual(errors.count, 1) guard - case let .incomparableOperators(_, leftGroup, _, rightGroup) = + case .incomparableOperators(_, let leftGroup, _, let rightGroup) = errors[0] else { XCTFail("expected an 'incomparable operator' error") diff --git a/Tests/SwiftSyntaxMacroExpansionTest/DeclarationMacroTests.swift b/Tests/SwiftSyntaxMacroExpansionTest/DeclarationMacroTests.swift index 20ac099d3c6..e5640db7f22 100644 --- a/Tests/SwiftSyntaxMacroExpansionTest/DeclarationMacroTests.swift +++ b/Tests/SwiftSyntaxMacroExpansionTest/DeclarationMacroTests.swift @@ -55,7 +55,7 @@ final class DeclarationMacroTests: XCTestCase { let stringLiteral = firstElement.expression .as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(messageString) = stringLiteral.segments.first + case .stringSegment(let messageString) = stringLiteral.segments.first else { throw SwiftSyntaxMacros.MacroExpansionErrorMessage("#error macro requires a string literal") } @@ -118,7 +118,7 @@ final class DeclarationMacroTests: XCTestCase { ) throws -> [DeclSyntax] { guard let stringLiteral = node.arguments.first?.expression.as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(prefix) = stringLiteral.segments.first + case .stringSegment(let prefix) = stringLiteral.segments.first else { throw SwiftSyntaxMacros.MacroExpansionErrorMessage( "#bitwidthNumberedStructs macro requires a string literal" diff --git a/Tests/SwiftSyntaxMacroExpansionTest/MacroReplacementTests.swift b/Tests/SwiftSyntaxMacroExpansionTest/MacroReplacementTests.swift index a564a2c3284..269697c594b 100644 --- a/Tests/SwiftSyntaxMacroExpansionTest/MacroReplacementTests.swift +++ b/Tests/SwiftSyntaxMacroExpansionTest/MacroReplacementTests.swift @@ -25,7 +25,7 @@ final class MacroReplacementTests: XCTestCase { """ let definition = try macro.cast(MacroDeclSyntax.self).checkDefinition() - guard case let .expansion(_, replacements, _) = definition else { + guard case .expansion(_, let replacements, _) = definition else { XCTFail("not an expansion definition") fatalError() } @@ -96,7 +96,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") fatalError() } @@ -128,7 +128,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } @@ -171,7 +171,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } @@ -213,7 +213,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } @@ -247,7 +247,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } @@ -281,7 +281,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } @@ -315,7 +315,7 @@ final class MacroReplacementTests: XCTestCase { let macroDecl = macro.cast(MacroDeclSyntax.self) let definition = try macroDecl.checkDefinition() - guard case let .expansion(expansion, replacements, genericReplacements) = definition else { + guard case .expansion(let expansion, let replacements, let genericReplacements) = definition else { XCTFail("not a normal expansion") return } diff --git a/Tests/SwiftSyntaxMacroExpansionTest/MultiRoleMacroTests.swift b/Tests/SwiftSyntaxMacroExpansionTest/MultiRoleMacroTests.swift index 0ee7458a90d..c785ab6413f 100644 --- a/Tests/SwiftSyntaxMacroExpansionTest/MultiRoleMacroTests.swift +++ b/Tests/SwiftSyntaxMacroExpansionTest/MultiRoleMacroTests.swift @@ -81,7 +81,7 @@ final class MultiRoleMacroTests: XCTestCase { guard case .argumentList(let arguments) = node.arguments, let stringLiteral = arguments.first?.expression.as(StringLiteralExprSyntax.self), stringLiteral.segments.count == 1, - case let .stringSegment(wrapperTypeNameSegment)? = stringLiteral.segments.first + case .stringSegment(let wrapperTypeNameSegment)? = stringLiteral.segments.first else { return [] } diff --git a/Tests/SwiftSyntaxMacroExpansionTest/PeerMacroTests.swift b/Tests/SwiftSyntaxMacroExpansionTest/PeerMacroTests.swift index 0a9eaebcf6c..2faeb61aca4 100644 --- a/Tests/SwiftSyntaxMacroExpansionTest/PeerMacroTests.swift +++ b/Tests/SwiftSyntaxMacroExpansionTest/PeerMacroTests.swift @@ -115,7 +115,7 @@ final class PeerMacroTests: XCTestCase { // Drop the @addCompletionHandler attribute from the new declaration. let newAttributeList = funcDecl.attributes.filter { - guard case let .attribute(attribute) = $0 else { + guard case .attribute(let attribute) = $0 else { return true } return attribute.attributeName.as(IdentifierTypeSyntax.self)?.name == "addCompletionHandler"