mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Use SwiftSyntax version 601.0.0 (#6003)
This commit is contained in:
@@ -96,7 +96,7 @@ swift_library(
|
||||
"@SwiftSyntax//:SwiftSyntaxBuilder_opt",
|
||||
"@SwiftSyntax//:SwiftSyntax_opt",
|
||||
"@com_github_jpsim_sourcekitten//:SourceKittenFramework",
|
||||
"@sourcekitten_com_github_jpsim_yams//:Yams",
|
||||
":Yams.wrapper",
|
||||
"@swiftlint_com_github_scottrhoyt_swifty_text_table//:SwiftyTextTable",
|
||||
] + select({
|
||||
"@platforms//os:linux": ["@com_github_krzyzanowskim_cryptoswift//:CryptoSwift"],
|
||||
@@ -104,6 +104,16 @@ swift_library(
|
||||
}),
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "Yams.wrapper",
|
||||
srcs = ["Source/YamsWrapper/Empty.swift"],
|
||||
module_name = "YamsWrapper",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"@sourcekitten_com_github_jpsim_yams//:Yams",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftLintBuiltInRules",
|
||||
package_name = "SwiftLint",
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ bazel_dep(name = "rules_shell", version = "0.4.0", repo_name = "build_bazel_rule
|
||||
bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift")
|
||||
bazel_dep(name = "sourcekitten", version = "0.37.0", repo_name = "com_github_jpsim_sourcekitten")
|
||||
bazel_dep(name = "swift_argument_parser", version = "1.3.1.1", repo_name = "sourcekitten_com_github_apple_swift_argument_parser")
|
||||
bazel_dep(name = "swift-syntax", version = "600.0.0", repo_name = "SwiftSyntax")
|
||||
bazel_dep(name = "swift-syntax", version = "601.0.0", repo_name = "SwiftSyntax")
|
||||
bazel_dep(name = "yams", version = "5.3.0", repo_name = "sourcekitten_com_github_jpsim_yams")
|
||||
|
||||
swiftlint_repos = use_extension("//bazel:repos.bzl", "swiftlint_repos_bzlmod")
|
||||
|
||||
+2
-2
@@ -41,8 +41,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swiftlang/swift-syntax.git",
|
||||
"state" : {
|
||||
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
|
||||
"version" : "600.0.0"
|
||||
"revision" : "1103c45ece4f7fe160b8f75b4ea1ee2e5fac1841",
|
||||
"version" : "601.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(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"),
|
||||
.package(url: "https://github.com/jpsim/SourceKitten.git", .upToNextMajor(from: "0.37.0")),
|
||||
.package(url: "https://github.com/jpsim/Yams.git", .upToNextMajor(from: "5.3.0")),
|
||||
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", .upToNextMajor(from: "0.9.0")),
|
||||
|
||||
@@ -66,11 +66,13 @@ private final class ImportPathVisitor: SyntaxVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private typealias ByteSourceRange = Range<AbsolutePosition>
|
||||
|
||||
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<AbsolutePosition>()
|
||||
|
||||
@@ -151,10 +151,10 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
|
||||
|
||||
override func visitPost(_ node: SameTypeRequirementSyntax) {
|
||||
// @_specialize(where S == ↓Array<Character>)
|
||||
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<Array<T>>'
|
||||
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<Array<T>>'
|
||||
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,
|
||||
|
||||
@@ -51,7 +51,7 @@ struct LocalDocCommentRule: SwiftSyntaxRule, OptInRule {
|
||||
|
||||
private extension LocalDocCommentRule {
|
||||
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
|
||||
private let docCommentRanges: [ByteSourceRange]
|
||||
private let docCommentRanges: [Range<AbsolutePosition>]
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -44,12 +44,12 @@ public extension SwiftLintFile {
|
||||
.tokens(viewMode: .sourceAccurate)
|
||||
.reduce(into: []) { linesWithTokens, token in
|
||||
if case .stringSegment = token.tokenKind {
|
||||
let sourceRange = token
|
||||
.trimmed
|
||||
.sourceRange(converter: locationConverter)
|
||||
let startLine = sourceRange.start.line
|
||||
let endLine = sourceRange.end.line
|
||||
linesWithTokens.formUnion(startLine...endLine)
|
||||
let sourceRange = token.sourceRange(
|
||||
converter: locationConverter,
|
||||
afterLeadingTrivia: true,
|
||||
afterTrailingTrivia: true
|
||||
)
|
||||
linesWithTokens.formUnion(sourceRange.start.line...sourceRange.end.line)
|
||||
} else {
|
||||
let line = locationConverter.location(for: token.positionAfterSkippingLeadingTrivia).line
|
||||
linesWithTokens.insert(line)
|
||||
|
||||
@@ -41,9 +41,12 @@ public extension AbsolutePosition {
|
||||
}
|
||||
}
|
||||
|
||||
public extension ByteSourceRange {
|
||||
public extension Range<AbsolutePosition> {
|
||||
func toSourceKittenByteRange() -> ByteRange {
|
||||
ByteRange(location: ByteCount(offset), length: ByteCount(length))
|
||||
ByteRange(
|
||||
location: ByteCount(lowerBound),
|
||||
length: ByteCount(upperBound.utf8Offset) - ByteCount(lowerBound.utf8Offset)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +348,7 @@ public extension DeclReferenceExprSyntax {
|
||||
|
||||
public extension ClosureCaptureSyntax {
|
||||
var capturesSelf: Bool {
|
||||
expression.as(DeclReferenceExprSyntax.self)?.isSelf == true
|
||||
name.text == "self"
|
||||
}
|
||||
|
||||
var capturesWeakly: Bool {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user