diff --git a/Package.resolved b/Package.resolved index baa9895fe5..9dfa91c3b1 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax.git", "state" : { - "revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25", - "version" : "600.0.0" + "revision" : "8ceb17262cf9a7c89ffaf2d1d62c32cee76151aa", + "version" : "601.0.0-prerelease-2025-02-12" } }, { diff --git a/Package.swift b/Package.swift index 57ab9dcf70..2f3a4393d2 100644 --- a/Package.swift +++ b/Package.swift @@ -33,7 +33,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.1"), - .package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "600.0.0"), + .package(url: "https://github.com/swiftlang/swift-syntax.git", exact: "601.0.0-prerelease-2025-02-12"), .package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMinor(from: "0.35.0")), .package(url: "https://github.com/jpsim/Yams.git", from: "5.0.6"), .package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"), diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DuplicateImportsRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DuplicateImportsRule.swift index b9b1bf33c7..945fa2e958 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DuplicateImportsRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/DuplicateImportsRule.swift @@ -66,11 +66,13 @@ private final class ImportPathVisitor: SyntaxVisitor { } } +private typealias ByteSourceRange = Range + private final class IfConfigClauseVisitor: SyntaxVisitor { var ifConfigRanges = [ByteSourceRange]() override func visitPost(_ node: IfConfigClauseSyntax) { - ifConfigRanges.append(node.totalByteRange) + ifConfigRanges.append(node.range) } } @@ -79,8 +81,8 @@ private struct ImportPathUsage: Hashable { let value: ByteSourceRange func hash(into hasher: inout Hasher) { - hasher.combine(value.offset) - hasher.combine(value.length) + hasher.combine(value.lowerBound.utf8Offset) + hasher.combine(value.length.utf8Length) } } @@ -103,8 +105,8 @@ private extension SwiftLintFile { .walk(file: self, handler: \.ifConfigRanges) func ranges(for position: AbsolutePosition) -> [ByteSourceRange] { - let positionRange = ByteSourceRange(offset: position.utf8Offset, length: 0) - return ifConfigRanges.filter { $0.intersectsOrTouches(positionRange) } + let positionRange = position..<(position + SourceLength(utf8Length: 1)) + return ifConfigRanges.filter { $0.overlapsOrTouches(positionRange) } } var violationPositions = Set() diff --git a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/SyntacticSugarRule.swift b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/SyntacticSugarRule.swift index 2ae8d41499..4c4404afbe 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Idiomatic/SyntacticSugarRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Idiomatic/SyntacticSugarRule.swift @@ -151,10 +151,10 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor { override func visitPost(_ node: SameTypeRequirementSyntax) { // @_specialize(where S == ↓Array) - if let violation = violation(in: node.leftType) { + if let violation = violation(in: node.leftType.as(TypeSyntax.self)) { violations.append(violation) } - if let violation = violation(in: node.rightType) { + if let violation = violation(in: node.rightType.as(TypeSyntax.self)) { violations.append(violation) } } @@ -180,7 +180,7 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor { // If there's no type, check all inner generics like in the case of 'Box>' node.genericArgumentClause.arguments .lazy - .compactMap { self.violation(in: $0.argument) } + .compactMap { self.violation(in: $0.argument.as(TypeSyntax.self)) } .first .map { violations.append($0) } } @@ -203,7 +203,7 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor { // If there's no type, check all inner generics like in the case of 'Box>' guard let genericArguments = simpleType.genericArgumentClause else { return nil } - let innerTypes = genericArguments.arguments.compactMap { violation(in: $0.argument) } + let innerTypes = genericArguments.arguments.compactMap { violation(in: $0.argument.as(TypeSyntax.self)) } return innerTypes.first } @@ -238,8 +238,10 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor { correctionType = .dictionary(commaStart: lastArgumentEnd, commaEnd: comma.endPosition) } - let firstInnerViolation = violation(in: firstGenericType.argument) - let secondInnerViolation = generic.arguments.count > 1 ? violation(in: lastGenericType.argument) : nil + let firstInnerViolation = violation(in: firstGenericType.argument.as(TypeSyntax.self)) + let secondInnerViolation = generic.arguments.count > 1 + ? violation(in: lastGenericType.argument.as(TypeSyntax.self)) + : nil return SyntacticSugarRuleViolation( position: node.positionAfterSkippingLeadingTrivia, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/LocalDocCommentRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/LocalDocCommentRule.swift index bf9dc3b8ca..94a3090234 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/LocalDocCommentRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/LocalDocCommentRule.swift @@ -51,7 +51,7 @@ struct LocalDocCommentRule: SwiftSyntaxRule, OptInRule { private extension LocalDocCommentRule { final class Visitor: ViolationsSyntaxVisitor { - private let docCommentRanges: [ByteSourceRange] + private let docCommentRanges: [Range] init(configuration: ConfigurationType, file: SwiftLintFile, @@ -67,9 +67,9 @@ private extension LocalDocCommentRule { return } - let violatingRange = docCommentRanges.first { $0.intersects(body.totalByteRange) } + let violatingRange = docCommentRanges.first { $0.overlaps(body.range) } if let violatingRange { - violations.append(AbsolutePosition(utf8Offset: violatingRange.offset)) + violations.append(AbsolutePosition(utf8Offset: violatingRange.lowerBound.utf8Offset)) } } } diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ClosureParameterPositionRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ClosureParameterPositionRule.swift index 4acb0078b5..4092b327ef 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ClosureParameterPositionRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ClosureParameterPositionRule.swift @@ -132,7 +132,7 @@ private extension ClosureSignatureSyntax { var positionsToCheck: [AbsolutePosition] { var positions: [AbsolutePosition] = [] if let captureItems = capture?.items { - positions.append(contentsOf: captureItems.map(\.expression.positionAfterSkippingLeadingTrivia)) + positions.append(contentsOf: captureItems.map(\.name.positionAfterSkippingLeadingTrivia)) } if let input = parameterClause?.as(ClosureShorthandParameterListSyntax.self) { diff --git a/Source/SwiftLintCore/Extensions/SwiftSyntax+SwiftLint.swift b/Source/SwiftLintCore/Extensions/SwiftSyntax+SwiftLint.swift index 521c6fcbc6..a83bb01a67 100644 --- a/Source/SwiftLintCore/Extensions/SwiftSyntax+SwiftLint.swift +++ b/Source/SwiftLintCore/Extensions/SwiftSyntax+SwiftLint.swift @@ -41,9 +41,12 @@ public extension AbsolutePosition { } } -public extension ByteSourceRange { +public extension Range { func toSourceKittenByteRange() -> ByteRange { - ByteRange(location: ByteCount(offset), length: ByteCount(length)) + ByteRange( + location: ByteCount(lowerBound), + length: ByteCount(upperBound.utf8Offset) - ByteCount(lowerBound.utf8Offset) + ) } } @@ -341,7 +344,7 @@ public extension DeclReferenceExprSyntax { public extension ClosureCaptureSyntax { var capturesSelf: Bool { - expression.as(DeclReferenceExprSyntax.self)?.isSelf == true + name.text == "self" } var capturesWeakly: Bool { diff --git a/Source/SwiftLintCoreMacros/RuleConfigurationMacros.swift b/Source/SwiftLintCoreMacros/RuleConfigurationMacros.swift index 51ba4427d7..f632352843 100644 --- a/Source/SwiftLintCoreMacros/RuleConfigurationMacros.swift +++ b/Source/SwiftLintCoreMacros/RuleConfigurationMacros.swift @@ -8,6 +8,7 @@ enum AutoConfigParser: MemberMacro { static func expansion( of _: AttributeSyntax, providingMembersOf declaration: some DeclGroupSyntax, + conformingTo _: [TypeSyntax], in context: some MacroExpansionContext ) throws -> [DeclSyntax] { guard let configuration = declaration.as(StructDeclSyntax.self) else {