Skip to content

Commit

Permalink
Enable UseLetInEveryBoundCaseVariable and update binding patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
allevato committed Oct 2, 2024
1 parent 0db13de commit 8335b63
Show file tree
Hide file tree
Showing 26 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"AmbiguousTrailingClosureOverload": false,
"NoBlockComments": true,
"OrderedImports": true,
"UseLetInEveryBoundCaseVariable": false,
"UseLetInEveryBoundCaseVariable": true,
"UseSynthesizedInitializer": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
}
Expand Down Expand Up @@ -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
}
}
}
6 changes: 3 additions & 3 deletions Sources/SwiftCompilerPluginMessageHandling/LRUCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ public class LRUCache<Key: Hashable, Value> {

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

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Statements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftRefactor/ExpandEditorPlaceholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import SwiftSyntax
items[..<pivotPoint]
.sort { lhs, rhs in
guard
case let .import(lhsImport, _) = lhs,
case let .import(rhsImport, _) = rhs
case .import(let lhsImport, _) = lhs,
case .import(let rhsImport, _) = rhs
else {
fatalError("Partition must only contain import items!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import SwiftSyntax
items[..<pivotPoint]
.sort { lhs, rhs in
guard
case let .import(lhsImport, _) = lhs,
case let .import(rhsImport, _) = rhs
case .import(let lhsImport, _) = lhs,
case .import(let rhsImport, _) = rhs
else {
fatalError("Partition must only contain import items!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import SwiftSyntax
items[..<pivotPoint]
.sort { lhs, rhs in
guard
case let .import(lhsImport, _) = lhs,
case let .import(rhsImport, _) = rhs
case .import(let lhsImport, _) = lhs,
case .import(let rhsImport, _) = rhs
else {
fatalError("Partition must only contain import items!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import SwiftSyntax
items[..<pivotPoint]
.sort { lhs, rhs in
guard
case let .import(lhsImport, _) = lhs,
case let .import(rhsImport, _) = rhs
case .import(let lhsImport, _) = lhs,
case .import(let rhsImport, _) = rhs
else {
fatalError("Partition must only contain import items!")
}
Expand Down
28 changes: 14 additions & 14 deletions Sources/SwiftSyntax/SourceLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,36 +571,36 @@ fileprivate extension RawTriviaPiece {
) -> 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..<count {
body(newLineLength)
}
lineLength = .zero
case let .carriageReturnLineFeeds(count):
case .carriageReturnLineFeeds(let count):
let carriageReturnLineLength = SourceLength(utf8Length: 2)
body(lineLength + carriageReturnLineLength)
for _ in 1..<count {
body(carriageReturnLineLength)
}
lineLength = .zero
case let .lineComment(text),
let .docLineComment(text):
case .lineComment(let text),
.docLineComment(let text):
// Line comments are not supposed to contain newlines.
precondition(!text.containsSwiftNewline(), "line comment created that contained a new-line character")
lineLength += SourceLength(utf8Length: text.count)
case let .blockComment(text),
let .docBlockComment(text),
let .unexpectedText(text):
case .blockComment(let text),
.docBlockComment(let text),
.unexpectedText(let text):
lineLength = text.forEachLineLength(prefix: lineLength, body: body)
}
return lineLength
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxMacroExpansion/MacroReplacement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ extension MacroDeclSyntax {
) -> 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
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/SwiftOperatorsTest/OperatorTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 8335b63

Please sign in to comment.