[SwiftSyntax] Update to latest 509.0.0 tag (#4920)
* [bazel] Remove custom SwiftSyntax BUILD file Something similar to this has been merged upstream instead now. This also renames the repo name to SwiftSyntax in preparation for it being in the BCR * [SwiftSyntax] Update to latest 509.0.0 tag https://github.com/apple/swift-syntax/releases/tag/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-04-25-b
This commit is contained in:
parent
9054ec0658
commit
6b094dd711
6
BUILD
6
BUILD
|
@ -18,7 +18,11 @@ swift_library(
|
|||
module_name = "SwiftLintCore",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_github_apple_swift_syntax//:optlibs",
|
||||
"@SwiftSyntax//:SwiftIDEUtils_opt",
|
||||
"@SwiftSyntax//:SwiftOperators_opt",
|
||||
"@SwiftSyntax//:SwiftParserDiagnostics_opt",
|
||||
"@SwiftSyntax//:SwiftSyntaxBuilder_opt",
|
||||
"@SwiftSyntax//:SwiftSyntax_opt",
|
||||
"@com_github_jpsim_sourcekitten//:SourceKittenFramework",
|
||||
"@sourcekitten_com_github_jpsim_yams//:Yams",
|
||||
"@swiftlint_com_github_scottrhoyt_swifty_text_table//:SwiftyTextTable",
|
||||
|
|
|
@ -17,7 +17,7 @@ bazel_dep(name = "yams", version = "5.0.5", repo_name = "sourcekitten_com_github
|
|||
swiftlint_repos = use_extension("//bazel:repos.bzl", "swiftlint_repos_bzlmod")
|
||||
use_repo(
|
||||
swiftlint_repos,
|
||||
"com_github_apple_swift_syntax",
|
||||
"SwiftSyntax",
|
||||
"com_github_johnsundell_collectionconcurrencykit",
|
||||
"com_github_krzyzanowskim_cryptoswift",
|
||||
"swiftlint_com_github_scottrhoyt_swifty_text_table",
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-syntax.git",
|
||||
"state" : {
|
||||
"revision" : "2a9988f32c3439b1c850673cfccb085ddcde1395",
|
||||
"version" : "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a"
|
||||
"revision" : "ebe38853ae283adeffaf3e389aaf98172f2f7a04",
|
||||
"version" : "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-04-25-b"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
.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-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a"),
|
||||
.package(url: "https://github.com/apple/swift-syntax.git", exact: "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-04-25-b"),
|
||||
.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/scottrhoyt/SwiftyTextTable.git", from: "0.9.0"),
|
||||
|
@ -47,8 +47,8 @@ let package = Package(
|
|||
dependencies: [
|
||||
.product(name: "CryptoSwift", package: "CryptoSwift", condition: .when(platforms: [.linux])),
|
||||
.target(name: "DyldWarningWorkaround", condition: .when(platforms: [.macOS])),
|
||||
.product(name: "IDEUtils", package: "swift-syntax"),
|
||||
.product(name: "SourceKittenFramework", package: "SourceKitten"),
|
||||
.product(name: "SwiftIDEUtils", package: "swift-syntax"),
|
||||
.product(name: "SwiftOperators", package: "swift-syntax"),
|
||||
.product(name: "SwiftParser", package: "swift-syntax"),
|
||||
.product(name: "SwiftSyntax", package: "swift-syntax"),
|
||||
|
|
|
@ -125,13 +125,21 @@ private extension ConvenienceTypeRule {
|
|||
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
|
||||
|
||||
override func visitPost(_ node: StructDeclSyntax) {
|
||||
if hasViolation(inheritance: node.inheritanceClause, attributes: node.attributes, members: node.members) {
|
||||
if hasViolation(
|
||||
inheritance: node.inheritanceClause,
|
||||
attributes: node.attributes,
|
||||
members: node.memberBlock
|
||||
) {
|
||||
violations.append(node.structKeyword.positionAfterSkippingLeadingTrivia)
|
||||
}
|
||||
}
|
||||
|
||||
override func visitPost(_ node: ClassDeclSyntax) {
|
||||
if hasViolation(inheritance: node.inheritanceClause, attributes: node.attributes, members: node.members) {
|
||||
if hasViolation(
|
||||
inheritance: node.inheritanceClause,
|
||||
attributes: node.attributes,
|
||||
members: node.memberBlock
|
||||
) {
|
||||
violations.append(node.classKeyword.positionAfterSkippingLeadingTrivia)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,9 +165,9 @@ private extension LegacyConstructorRule {
|
|||
|
||||
correctionPositions.append(node.positionAfterSkippingLeadingTrivia)
|
||||
|
||||
let arguments = TupleExprElementListSyntax(node.argumentList.map { elem in
|
||||
let arguments = TupleExprElementListSyntax(node.argumentList.enumerated().map { index, elem in
|
||||
elem
|
||||
.with(\.label, .identifier(args[elem.indexInParent]))
|
||||
.with(\.label, .identifier(args[index]))
|
||||
.with(\.colon, .colonToken(trailingTrivia: .space))
|
||||
})
|
||||
let newExpression = identifierExpr.with(
|
||||
|
|
|
@ -148,104 +148,117 @@ private extension PrivateOverFilePrivateRule {
|
|||
// don't call super in any of the `visit` methods to avoid digging into the children
|
||||
override func visit(_ node: ExtensionDeclSyntax) -> DeclSyntax {
|
||||
guard validateExtensions, let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: ClassDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: StructDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: EnumDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: ProtocolDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: FunctionDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: VariableDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
|
||||
override func visit(_ node: TypealiasDeclSyntax) -> DeclSyntax {
|
||||
guard let modifier = node.modifiers.fileprivateModifier,
|
||||
let modifierIndex = node.modifiers.fileprivateModifierIndex,
|
||||
!node.isContainedIn(regions: disabledRegions, locationConverter: locationConverter) else {
|
||||
return DeclSyntax(node)
|
||||
}
|
||||
|
||||
correctionPositions.append(modifier.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifier: modifier))
|
||||
let newNode = node.with(\.modifiers, node.modifiers?.replacing(fileprivateModifierIndex: modifierIndex))
|
||||
return DeclSyntax(newNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension ModifierListSyntax? {
|
||||
var fileprivateModifierIndex: ModifierListSyntax.Index? {
|
||||
self?.firstIndex(where: { $0.name.tokenKind == .keyword(.fileprivate) })
|
||||
}
|
||||
|
||||
var fileprivateModifier: DeclModifierSyntax? {
|
||||
self?.first { $0.name.tokenKind == .keyword(.fileprivate) }
|
||||
fileprivateModifierIndex.flatMap { self?[$0] }
|
||||
}
|
||||
}
|
||||
|
||||
private extension ModifierListSyntax {
|
||||
func replacing(fileprivateModifier: DeclModifierSyntax) -> ModifierListSyntax? {
|
||||
replacing(
|
||||
childAt: fileprivateModifier.indexInParent,
|
||||
func replacing(fileprivateModifierIndex: ModifierListSyntax.Index) -> ModifierListSyntax? {
|
||||
let fileprivateModifier = self[fileprivateModifierIndex]
|
||||
return replacing(
|
||||
childAt: self.distance(from: self.startIndex, to: fileprivateModifierIndex),
|
||||
with: fileprivateModifier.with(
|
||||
\.name,
|
||||
.keyword(
|
||||
|
|
|
@ -36,7 +36,8 @@ struct RedundantNilCoalescingRule: OptInRule, SwiftSyntaxCorrectableRule, Config
|
|||
private extension RedundantNilCoalescingRule {
|
||||
final class Visitor: ViolationsSyntaxVisitor {
|
||||
override func visitPost(_ node: TokenSyntax) {
|
||||
if node.tokenKind.isNilCoalescingOperator && node.nextToken?.tokenKind == .keyword(.nil) {
|
||||
if node.tokenKind.isNilCoalescingOperator,
|
||||
node.nextToken(viewMode: .sourceAccurate)?.tokenKind == .keyword(.nil) {
|
||||
violations.append(node.position)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ private extension DeclSyntax {
|
|||
|
||||
private extension ModifierListSyntax {
|
||||
var setAccessor: DeclModifierSyntax? {
|
||||
first { $0.detail?.detail.tokenKind == .keyword(.set) }
|
||||
first { $0.detail?.detail.tokenKind == .identifier("set") }
|
||||
}
|
||||
|
||||
var getAccessor: DeclModifierSyntax? {
|
||||
|
|
|
@ -71,7 +71,7 @@ private extension RedundantStringEnumValueRule {
|
|||
return
|
||||
}
|
||||
|
||||
let enumsWithExplicitValues = node.members.members
|
||||
let enumsWithExplicitValues = node.memberBlock.members
|
||||
.flatMap { member -> EnumCaseElementListSyntax in
|
||||
guard let enumCaseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
|
||||
return EnumCaseElementListSyntax([])
|
||||
|
|
|
@ -194,7 +194,7 @@ private extension StrictFilePrivateRule {
|
|||
return
|
||||
}
|
||||
if let varDecl = grandparent.as(VariableDeclSyntax.self) {
|
||||
let isSpecificForSetter = node.detail?.detail.tokenKind == .keyword(.set)
|
||||
let isSpecificForSetter = node.detail?.detail.tokenKind == .identifier("set")
|
||||
let firstImplementingProtocol = varDecl.bindings
|
||||
.flatMap { binding in
|
||||
let pattern = binding.pattern
|
||||
|
|
|
@ -332,7 +332,7 @@ extension SimpleTypeIdentifierSyntax: SyntaxWithGenericClause {
|
|||
|
||||
extension SpecializeExprSyntax: SyntaxWithGenericClause {
|
||||
var typeName: String? {
|
||||
expression.as(IdentifierExprSyntax.self)?.firstToken?.text ??
|
||||
expression.as(IdentifierExprSyntax.self)?.firstToken(viewMode: .sourceAccurate)?.text ??
|
||||
expression.as(MemberAccessExprSyntax.self)?.name.text
|
||||
}
|
||||
var genericArguments: GenericArgumentClauseSyntax? { genericArgumentClause }
|
||||
|
|
|
@ -72,6 +72,9 @@ private extension TrailingSemicolonRule {
|
|||
private extension TokenSyntax {
|
||||
var isTrailingSemicolon: Bool {
|
||||
tokenKind == .semicolon &&
|
||||
(trailingTrivia.containsNewlines() || (nextToken?.leadingTrivia.containsNewlines() == true))
|
||||
(
|
||||
trailingTrivia.containsNewlines() ||
|
||||
(nextToken(viewMode: .sourceAccurate)?.leadingTrivia.containsNewlines() == true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ private extension BalancedXCTestLifecycleRule {
|
|||
}
|
||||
|
||||
let methods = SetupTearDownVisitor(viewMode: .sourceAccurate)
|
||||
.walk(tree: node.members, handler: \.methods)
|
||||
.walk(tree: node.memberBlock, handler: \.methods)
|
||||
guard methods.contains(.setUp) != methods.contains(.tearDown) else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import IDEUtils
|
||||
import SourceKittenFramework
|
||||
import SwiftIDEUtils
|
||||
|
||||
struct CommentSpacingRule: SourceKitFreeRule, ConfigurationProviderRule, SubstitutionCorrectableRule {
|
||||
var configuration = SeverityConfiguration(.warning)
|
||||
|
|
|
@ -79,9 +79,9 @@ private extension DiscardedNotificationCenterObserverRule {
|
|||
} else if node.parent?.is(ArrayElementSyntax.self) == true {
|
||||
return // result is an array literal element
|
||||
} else if
|
||||
let previousToken = node.previousToken,
|
||||
let previousToken = node.previousToken(viewMode: .sourceAccurate),
|
||||
case .equal = previousToken.tokenKind,
|
||||
previousToken.previousToken?.tokenKind != .wildcard
|
||||
previousToken.previousToken(viewMode: .sourceAccurate)?.tokenKind != .wildcard
|
||||
{
|
||||
return // result is assigned to something other than the wildcard keyword (`_`)
|
||||
}
|
||||
|
|
|
@ -177,9 +177,7 @@ private extension DuplicateConditionsRule {
|
|||
|
||||
let positionsByConditions = statementChain
|
||||
.reduce(into: [Set<String>: [AbsolutePosition]]()) { acc, elt in
|
||||
let conditions = elt.conditions.map {
|
||||
$0.condition.debugDescription(includeChildren: true, includeTrivia: false)
|
||||
}
|
||||
let conditions = elt.conditions.map { $0.condition.trimmedDescription }
|
||||
let location = elt.conditions.positionAfterSkippingLeadingTrivia
|
||||
acc[Set(conditions), default: []].append(location)
|
||||
}
|
||||
|
@ -197,10 +195,10 @@ private extension DuplicateConditionsRule {
|
|||
for caseItem in caseLabel.caseItems {
|
||||
let pattern = caseItem
|
||||
.pattern
|
||||
.debugDescription(includeChildren: true, includeTrivia: false)
|
||||
.trimmedDescription
|
||||
let whereClause = caseItem
|
||||
.whereClause?
|
||||
.debugDescription(includeChildren: true, includeTrivia: false)
|
||||
.trimmedDescription
|
||||
?? ""
|
||||
let location = caseItem.positionAfterSkippingLeadingTrivia
|
||||
acc[pattern + whereClause, default: []].append(location)
|
||||
|
|
|
@ -63,7 +63,7 @@ struct DuplicateEnumCasesRule: ConfigurationProviderRule, SwiftSyntaxRule {
|
|||
private extension DuplicateEnumCasesRule {
|
||||
final class Visitor: ViolationsSyntaxVisitor {
|
||||
override func visitPost(_ node: EnumDeclSyntax) {
|
||||
let enumElements = node.members.members
|
||||
let enumElements = node.memberBlock.members
|
||||
.flatMap { member -> EnumCaseElementListSyntax in
|
||||
guard let enumCaseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
|
||||
return EnumCaseElementListSyntax([])
|
||||
|
|
|
@ -46,6 +46,6 @@ private extension DynamicInlineRule {
|
|||
private extension AttributeSyntax {
|
||||
var isInlineAlways: Bool {
|
||||
attributeNameText == "inline" &&
|
||||
argument?.firstToken?.tokenKind == .identifier("__always")
|
||||
argument?.firstToken(viewMode: .sourceAccurate)?.tokenKind == .identifier("__always")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,6 @@ private extension IdenticalOperandsRule {
|
|||
|
||||
private extension ExprSyntax {
|
||||
var normalizedDescription: String {
|
||||
debugDescription(includeChildren: true, includeTrivia: false)
|
||||
debugDescription(includeTrivia: false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import IDEUtils
|
||||
import SwiftIDEUtils
|
||||
import SwiftSyntax
|
||||
|
||||
struct LocalDocCommentRule: SwiftSyntaxRule, ConfigurationProviderRule, OptInRule {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import IDEUtils
|
||||
import SwiftIDEUtils
|
||||
|
||||
struct OrphanedDocCommentRule: SourceKitFreeRule, ConfigurationProviderRule {
|
||||
var configuration = SeverityConfiguration(.warning)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import IDEUtils
|
||||
import SourceKittenFramework
|
||||
import SwiftIDEUtils
|
||||
|
||||
struct PeriodSpacingRule: SourceKitFreeRule, ConfigurationProviderRule, OptInRule, SubstitutionCorrectableRule {
|
||||
var configuration = SeverityConfiguration(.warning)
|
||||
|
|
|
@ -75,7 +75,7 @@ private extension RequiredDeinitRule {
|
|||
final class Visitor: ViolationsSyntaxVisitor {
|
||||
override func visitPost(_ node: ClassDeclSyntax) {
|
||||
let visitor = DeinitVisitor(viewMode: .sourceAccurate)
|
||||
if !visitor.walk(tree: node.members, handler: \.hasDeinit) {
|
||||
if !visitor.walk(tree: node.memberBlock, handler: \.hasDeinit) {
|
||||
violations.append(node.classKeyword.positionAfterSkippingLeadingTrivia)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ private extension RequiredEnumCaseRule {
|
|||
|
||||
private extension EnumDeclSyntax {
|
||||
var enumCasesNames: [String] {
|
||||
return members.members
|
||||
return memberBlock.members
|
||||
.flatMap { member -> [String] in
|
||||
guard let enumCaseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
|
||||
return []
|
||||
|
|
|
@ -52,7 +52,7 @@ private extension TestCaseAccessibilityRule {
|
|||
|
||||
violations.append(
|
||||
contentsOf: XCTestClassVisitor(allowedPrefixes: allowedPrefixes)
|
||||
.walk(tree: node.members, handler: \.violations)
|
||||
.walk(tree: node.memberBlock, handler: \.violations)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ private extension UnusedClosureParameterRule {
|
|||
correctionPositions.append(name.positionAfterSkippingLeadingTrivia)
|
||||
let newParameterList = newParams.parameterList.replacing(
|
||||
childAt: index,
|
||||
with: param.with(\.firstName, name.withKind(.wildcard))
|
||||
with: param.with(\.firstName, name.with(\.tokenKind, .wildcard))
|
||||
)
|
||||
newParams = newParams.with(\.parameterList, newParameterList)
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ private extension UnusedClosureParameterRule {
|
|||
correctionPositions.append(param.name.positionAfterSkippingLeadingTrivia)
|
||||
newParams = newParams.replacing(
|
||||
childAt: index,
|
||||
with: param.with(\.name, param.name.withKind(.wildcard))
|
||||
with: param.with(\.name, param.name.with(\.tokenKind, .wildcard))
|
||||
)
|
||||
}
|
||||
let newNode = node.with(\.signature, signature.with(\.input, .init(newParams)))
|
||||
|
|
|
@ -41,7 +41,7 @@ private extension ContainsOverFilterCountRule {
|
|||
let last = node.last?.as(IntegerLiteralExprSyntax.self),
|
||||
last.isZero,
|
||||
let second = node.dropFirst().first,
|
||||
second.firstToken?.tokenKind.isZeroComparison == true,
|
||||
second.firstToken(viewMode: .sourceAccurate)?.tokenKind.isZeroComparison == true,
|
||||
let first = node.first?.as(MemberAccessExprSyntax.self),
|
||||
first.name.text == "count",
|
||||
let firstBase = first.base?.asFunctionCall,
|
||||
|
|
|
@ -36,10 +36,10 @@ private extension EmptyCollectionLiteralRule {
|
|||
override func visitPost(_ node: TokenSyntax) {
|
||||
guard
|
||||
node.tokenKind.isEqualityComparison,
|
||||
let violationPosition = node.previousToken?.endPositionBeforeTrailingTrivia,
|
||||
let expectedLeftSquareBracketToken = node.nextToken,
|
||||
let violationPosition = node.previousToken(viewMode: .sourceAccurate)?.endPositionBeforeTrailingTrivia,
|
||||
let expectedLeftSquareBracketToken = node.nextToken(viewMode: .sourceAccurate),
|
||||
expectedLeftSquareBracketToken.tokenKind == .leftSquareBracket,
|
||||
let expectedColonToken = expectedLeftSquareBracketToken.nextToken,
|
||||
let expectedColonToken = expectedLeftSquareBracketToken.nextToken(viewMode: .sourceAccurate),
|
||||
expectedColonToken.tokenKind == .colon || expectedColonToken.tokenKind == .rightSquareBracket
|
||||
else {
|
||||
return
|
||||
|
|
|
@ -33,14 +33,15 @@ private extension EmptyStringRule {
|
|||
guard
|
||||
// Empty string literal: `""`, `#""#`, etc.
|
||||
node.segments.onlyElement?.contentLength == .zero,
|
||||
let previousToken = node.previousToken,
|
||||
let previousToken = node.previousToken(viewMode: .sourceAccurate),
|
||||
// On the rhs of an `==` or `!=` operator
|
||||
previousToken.tokenKind.isEqualityComparison,
|
||||
let violationPosition = previousToken.previousToken?.endPositionBeforeTrailingTrivia
|
||||
let secondPreviousToken = previousToken.previousToken(viewMode: .sourceAccurate)
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let violationPosition = secondPreviousToken.endPositionBeforeTrailingTrivia
|
||||
violations.append(violationPosition)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,10 @@ private extension ClosingBraceRule {
|
|||
|
||||
private extension TokenSyntax {
|
||||
var hasClosingBraceViolation: Bool {
|
||||
guard tokenKind == .rightBrace,
|
||||
let nextToken,
|
||||
nextToken.tokenKind == .rightParen
|
||||
guard
|
||||
tokenKind == .rightBrace,
|
||||
let nextToken = nextToken(viewMode: .sourceAccurate),
|
||||
nextToken.tokenKind == .rightParen
|
||||
else {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -168,7 +168,8 @@ private extension TokenSyntax {
|
|||
var hasSingleSpaceToItsLeft: Bool {
|
||||
if case .spaces(1) = Array(leadingTrivia).last {
|
||||
return true
|
||||
} else if let previousToken, case .spaces(1) = Array(previousToken.trailingTrivia).last {
|
||||
} else if let previousToken = previousToken(viewMode: .sourceAccurate),
|
||||
case .spaces(1) = Array(previousToken.trailingTrivia).last {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
@ -178,7 +179,8 @@ private extension TokenSyntax {
|
|||
var hasSingleSpaceToItsRight: Bool {
|
||||
if case .spaces(1) = trailingTrivia.first {
|
||||
return true
|
||||
} else if let nextToken, case .spaces(1) = nextToken.leadingTrivia.first {
|
||||
} else if let nextToken = nextToken(viewMode: .sourceAccurate),
|
||||
case .spaces(1) = nextToken.leadingTrivia.first {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
@ -206,7 +208,7 @@ private extension TokenSyntax {
|
|||
}
|
||||
|
||||
var hasAllowedNoSpaceLeftToken: Bool {
|
||||
let previousTokenKind = parent?.previousToken?.tokenKind
|
||||
let previousTokenKind = parent?.previousToken(viewMode: .sourceAccurate)?.tokenKind
|
||||
return previousTokenKind == .leftParen || previousTokenKind == .leftSquareBracket
|
||||
}
|
||||
|
||||
|
@ -226,9 +228,10 @@ private extension TokenSyntax {
|
|||
]
|
||||
if case .newlines = trailingTrivia.first {
|
||||
return true
|
||||
} else if case .newlines = nextToken?.leadingTrivia.first {
|
||||
} else if case .newlines = nextToken(viewMode: .sourceAccurate)?.leadingTrivia.first {
|
||||
return true
|
||||
} else if let nextToken, allowedKinds.contains(nextToken.tokenKind) {
|
||||
} else if let nextToken = nextToken(viewMode: .sourceAccurate),
|
||||
allowedKinds.contains(nextToken.tokenKind) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
|
|
@ -95,7 +95,7 @@ private final class CommaInheritanceRuleVisitor: SyntaxVisitor {
|
|||
|
||||
for ampersand in composition.elements.compactMap(\.ampersand) {
|
||||
let position: AbsolutePosition
|
||||
if let previousToken = ampersand.previousToken {
|
||||
if let previousToken = ampersand.previousToken(viewMode: .sourceAccurate) {
|
||||
position = previousToken.endPositionBeforeTrailingTrivia
|
||||
} else {
|
||||
position = ampersand.position
|
||||
|
|
|
@ -198,7 +198,7 @@ private extension PatternSyntax {
|
|||
private extension FunctionCallExprSyntax {
|
||||
var argumentsHasViolation: Bool {
|
||||
!calledExpression.is(IdentifierExprSyntax.self) &&
|
||||
calledExpression.as(MemberAccessExprSyntax.self)?.lastToken?.tokenKind != .keyword(.`init`) &&
|
||||
calledExpression.as(MemberAccessExprSyntax.self)?.isInit == false &&
|
||||
argumentList.allSatisfy(\.expression.isDiscardAssignmentOrFunction)
|
||||
}
|
||||
|
||||
|
@ -246,3 +246,9 @@ private extension ExprSyntax {
|
|||
(self.as(FunctionCallExprSyntax.self)?.argumentsHasViolation == true)
|
||||
}
|
||||
}
|
||||
|
||||
private extension MemberAccessExprSyntax {
|
||||
var isInit: Bool {
|
||||
lastToken(viewMode: .sourceAccurate)?.tokenKind == .keyword(.`init`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ private extension NumberSeparatorRule {
|
|||
}
|
||||
|
||||
let newNode = node.with(\.floatingDigits,
|
||||
node.floatingDigits.withKind(.floatingLiteral(violation.correction)))
|
||||
node.floatingDigits.with(\.tokenKind, .floatingLiteral(violation.correction)))
|
||||
correctionPositions.append(violation.position)
|
||||
return super.visit(newNode)
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ private extension NumberSeparatorRule {
|
|||
return super.visit(node)
|
||||
}
|
||||
|
||||
let newNode = node.with(\.digits, node.digits.withKind(.integerLiteral(violation.correction)))
|
||||
let newNode = node.with(\.digits, node.digits.with(\.tokenKind, .integerLiteral(violation.correction)))
|
||||
correctionPositions.append(violation.position)
|
||||
return super.visit(newNode)
|
||||
}
|
||||
|
|
|
@ -172,8 +172,8 @@ private class OperatorUsageWhitespaceVisitor: SyntaxVisitor {
|
|||
}
|
||||
|
||||
private func violation(operatorToken: TokenSyntax) -> (ByteRange, String)? {
|
||||
guard let previousToken = operatorToken.previousToken,
|
||||
let nextToken = operatorToken.nextToken else {
|
||||
guard let previousToken = operatorToken.previousToken(viewMode: .sourceAccurate),
|
||||
let nextToken = operatorToken.nextToken(viewMode: .sourceAccurate) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,8 @@ private struct ArrowViolation {
|
|||
|
||||
private extension TokenSyntax {
|
||||
var arrowViolation: ArrowViolation? {
|
||||
guard let previousToken, let nextToken else {
|
||||
guard let previousToken = previousToken(viewMode: .sourceAccurate),
|
||||
let nextToken = nextToken(viewMode: .sourceAccurate) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ private final class SelfBindingRuleRewriter: SyntaxRewriter, ViolationsSyntaxRew
|
|||
let newPattern = PatternSyntax(
|
||||
identifierPattern
|
||||
.with(\.identifier,
|
||||
identifierPattern.identifier.withKind(.identifier(bindIdentifier))
|
||||
identifierPattern.identifier.with(\.tokenKind, .identifier(bindIdentifier))
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -132,7 +132,7 @@ private final class SelfBindingRuleRewriter: SyntaxRewriter, ViolationsSyntaxRew
|
|||
let newPattern = PatternSyntax(
|
||||
identifierPattern
|
||||
.with(\.identifier,
|
||||
identifierPattern.identifier.withKind(.identifier(bindIdentifier)))
|
||||
identifierPattern.identifier.with(\.tokenKind, .identifier(bindIdentifier)))
|
||||
)
|
||||
|
||||
let newInitializer = InitializerClauseSyntax(
|
||||
|
|
|
@ -92,7 +92,7 @@ private extension SortedEnumCasesRule {
|
|||
return .skipChildren
|
||||
}
|
||||
|
||||
let cases = node.members.members.compactMap { $0.decl.as(EnumCaseDeclSyntax.self) }
|
||||
let cases = node.memberBlock.members.compactMap { $0.decl.as(EnumCaseDeclSyntax.self) }
|
||||
let sortedCases = cases
|
||||
.sorted(by: { $0.elements.first!.identifier.text < $1.elements.first!.identifier.text })
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ private extension TrailingCommaRule {
|
|||
.appending(trivia: commaToken.trailingTrivia)
|
||||
let newNode = node
|
||||
.replacing(
|
||||
childAt: lastElement.indexInParent,
|
||||
childAt: node.count - 1,
|
||||
with: lastElement
|
||||
.with(\.trailingComma, nil)
|
||||
.with(\.trailingTrivia, newTrailingTrivia)
|
||||
|
@ -148,7 +148,7 @@ private extension TrailingCommaRule {
|
|||
correctionPositions.append(lastElement.endPositionBeforeTrailingTrivia)
|
||||
let newNode = node
|
||||
.replacing(
|
||||
childAt: lastElement.indexInParent,
|
||||
childAt: node.count - 1,
|
||||
with: lastElement
|
||||
.with(\.trailingTrivia, [])
|
||||
.with(\.trailingComma, .commaToken())
|
||||
|
@ -171,7 +171,7 @@ private extension TrailingCommaRule {
|
|||
correctionPositions.append(commaToken.positionAfterSkippingLeadingTrivia)
|
||||
let newNode = node
|
||||
.replacing(
|
||||
childAt: lastElement.indexInParent,
|
||||
childAt: node.count - 1,
|
||||
with: lastElement
|
||||
.with(\.trailingComma, nil)
|
||||
.with(\.trailingTrivia,
|
||||
|
@ -184,7 +184,7 @@ private extension TrailingCommaRule {
|
|||
case (nil, true) where !locationConverter.isSingleLine(node: node):
|
||||
correctionPositions.append(lastElement.endPositionBeforeTrailingTrivia)
|
||||
let newNode = node.replacing(
|
||||
childAt: lastElement.indexInParent,
|
||||
childAt: node.count - 1,
|
||||
with: lastElement
|
||||
.with(\.expression, lastElement.expression.with(\.trailingTrivia, []))
|
||||
.with(\.trailingComma, .commaToken())
|
||||
|
|
|
@ -34,8 +34,8 @@ final class BodyLengthRuleVisitor: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: EnumDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.members.leftBrace },
|
||||
getRightBrace: { node.members.rightBrace },
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.enumKeyword }
|
||||
)
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ final class BodyLengthRuleVisitor: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: ClassDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.members.leftBrace },
|
||||
getRightBrace: { node.members.rightBrace },
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.classKeyword }
|
||||
)
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ final class BodyLengthRuleVisitor: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: StructDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.members.leftBrace },
|
||||
getRightBrace: { node.members.rightBrace },
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.structKeyword }
|
||||
)
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ final class BodyLengthRuleVisitor: ViolationsSyntaxVisitor {
|
|||
override func visitPost(_ node: ActorDeclSyntax) {
|
||||
if kind == .type {
|
||||
registerViolations(
|
||||
getLeftBrace: { node.members.leftBrace },
|
||||
getRightBrace: { node.members.rightBrace },
|
||||
getLeftBrace: { node.memberBlock.leftBrace },
|
||||
getRightBrace: { node.memberBlock.rightBrace },
|
||||
getViolationNode: { node.actorKeyword }
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import Darwin
|
||||
#endif
|
||||
import Foundation
|
||||
import IDEUtils
|
||||
import SourceKittenFramework
|
||||
import SwiftIDEUtils
|
||||
import SwiftOperators
|
||||
import SwiftParser
|
||||
import SwiftParserDiagnostics
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import IDEUtils
|
||||
import SwiftIDEUtils
|
||||
|
||||
public extension SyntaxClassification {
|
||||
// True if it is any kind of comment.
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
load("@SwiftLint//bazel:opt_wrapper.bzl", "opt_wrapper")
|
||||
|
||||
swift_library(
|
||||
name = "SwiftSyntax",
|
||||
srcs = glob(
|
||||
["Sources/SwiftSyntax/**/*.swift"],
|
||||
exclude = ["Sources/SwiftSyntax/Documentation.docc/**"],
|
||||
),
|
||||
module_name = "SwiftSyntax",
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftBasicFormat",
|
||||
srcs = glob(["Sources/SwiftBasicFormat/**/*.swift"]),
|
||||
module_name = "SwiftBasicFormat",
|
||||
deps = [":SwiftSyntax"],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftDiagnostics",
|
||||
srcs = glob(["Sources/SwiftDiagnostics/**/*.swift"]),
|
||||
module_name = "SwiftDiagnostics",
|
||||
deps = [":SwiftSyntax"],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftParser",
|
||||
srcs = glob(["Sources/SwiftParser/**/*.swift"]),
|
||||
module_name = "SwiftParser",
|
||||
deps = [
|
||||
":SwiftDiagnostics",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftSyntaxBuilder",
|
||||
srcs = glob(["Sources/SwiftSyntaxBuilder/**/*.swift"]),
|
||||
module_name = "SwiftSyntaxBuilder",
|
||||
deps = [
|
||||
":SwiftBasicFormat",
|
||||
":SwiftParser",
|
||||
":SwiftParserDiagnostics",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftSyntaxParser",
|
||||
srcs = glob(["Sources/SwiftSyntaxParser/**/*.swift"]),
|
||||
module_name = "SwiftSyntaxParser",
|
||||
deps = [
|
||||
":SwiftParser",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftOperators",
|
||||
srcs = glob(["Sources/SwiftOperators/**/*.swift"]),
|
||||
module_name = "SwiftOperators",
|
||||
deps = [
|
||||
":SwiftDiagnostics",
|
||||
":SwiftParser",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftParserDiagnostics",
|
||||
srcs = glob(["Sources/SwiftParserDiagnostics/**/*.swift"]),
|
||||
module_name = "SwiftParserDiagnostics",
|
||||
deps = [
|
||||
":SwiftBasicFormat",
|
||||
":SwiftDiagnostics",
|
||||
":SwiftParser",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "SwiftRefactor",
|
||||
srcs = glob(["Sources/SwiftRefactor/**/*.swift"]),
|
||||
module_name = "SwiftRefactor",
|
||||
deps = [
|
||||
":SwiftParser",
|
||||
":SwiftSyntax",
|
||||
],
|
||||
)
|
||||
|
||||
swift_library(
|
||||
name = "IDEUtils",
|
||||
srcs = glob(["Sources/IDEUtils/**/*.swift"]),
|
||||
module_name = "IDEUtils",
|
||||
deps = [":SwiftSyntax"],
|
||||
)
|
||||
|
||||
opt_wrapper(
|
||||
name = "optlibs",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":IDEUtils",
|
||||
":SwiftOperators",
|
||||
":SwiftParser",
|
||||
":SwiftParserDiagnostics",
|
||||
":SwiftSyntax",
|
||||
":SwiftSyntaxBuilder",
|
||||
],
|
||||
)
|
|
@ -1,35 +0,0 @@
|
|||
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_common")
|
||||
|
||||
def _force_opt_impl(_settings, _attr):
|
||||
return {"//command_line_option:compilation_mode": "opt"}
|
||||
|
||||
_force_opt = transition(
|
||||
implementation = _force_opt_impl,
|
||||
inputs = [],
|
||||
outputs = ["//command_line_option:compilation_mode"],
|
||||
)
|
||||
|
||||
def _impl(ctx):
|
||||
ccinfos = []
|
||||
swiftinfos = []
|
||||
|
||||
for dep in ctx.attr.deps:
|
||||
ccinfos.append(dep[CcInfo])
|
||||
swiftinfos.append(dep[SwiftInfo])
|
||||
|
||||
return [
|
||||
cc_common.merge_cc_infos(direct_cc_infos = ccinfos),
|
||||
swift_common.create_swift_info(swift_infos = swiftinfos),
|
||||
]
|
||||
|
||||
opt_wrapper = rule(
|
||||
implementation = _impl,
|
||||
attrs = {
|
||||
"deps": attr.label_list(
|
||||
cfg = _force_opt,
|
||||
),
|
||||
"_allowlist_function_transition": attr.label(
|
||||
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
|
||||
),
|
||||
},
|
||||
)
|
|
@ -19,11 +19,10 @@ def swiftlint_repos(bzlmod = False):
|
|||
)
|
||||
|
||||
http_archive(
|
||||
name = "com_github_apple_swift_syntax",
|
||||
sha256 = "3b9380abc9a3d15fc718d87f1c278d978078d777bb03e3861b904aad6ef6bb54",
|
||||
build_file = "@SwiftLint//bazel:SwiftSyntax.BUILD",
|
||||
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-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a.tar.gz",
|
||||
name = "SwiftSyntax",
|
||||
sha256 = "9eff9d7154f62d5cfaa967f288847bbfbdfad69f2fcaf47fa44d314aa647a77b",
|
||||
strip_prefix = "swift-syntax-509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-04-25-b",
|
||||
url = "https://github.com/apple/swift-syntax/archive/refs/tags/509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-04-25-b.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
|
|
Loading…
Reference in New Issue