Enforce any on existential types (#5273)

This makes syntactically clear which types are rather expensive.
This commit is contained in:
Danny Mösch
2023-10-12 08:37:23 +02:00
committed by GitHub
parent 6438c77b96
commit 58928b7e40
126 changed files with 268 additions and 230 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/// The rule list containing all available rules built into SwiftLint.
public let builtInRules: [Rule.Type] = [
public let builtInRules: [any Rule.Type] = [
{% for rule in types.structs where rule.name|hasSuffix:"Rule" %} {{ rule.name }}.self{% if not forloop.last %},{% endif %}
{% endfor %}]
+1 -1
View File
@@ -1,6 +1,6 @@
/// The reporters list containing all the reporters built into SwiftLint.
public let reportersList: [Reporter.Type] = [
public let reportersList: [any Reporter.Type] = [
{% for reporter in types.structs where reporter.name|hasSuffix:"Reporter" %}
{{ reporter.name }}.self{% if not forloop.last %},{% endif %}
{% endfor %}
+9
View File
@@ -6,6 +6,8 @@ load(
"swift_compiler_plugin"
)
copts = ["-enable-upcoming-feature", "ExistentialAny"]
# Targets
swift_library(
@@ -17,6 +19,7 @@ swift_library(
"@SwiftSyntax//:SwiftCompilerPlugin_opt",
"@SwiftSyntax//:SwiftSyntaxMacros_opt",
],
copts = copts,
)
swift_compiler_plugin(
@@ -26,6 +29,7 @@ swift_compiler_plugin(
"@SwiftSyntax//:SwiftCompilerPlugin_opt",
"@SwiftSyntax//:SwiftSyntaxMacros_opt",
],
copts = copts,
)
swift_library(
@@ -49,6 +53,7 @@ swift_library(
plugins = [
":SwiftLintCoreMacros",
],
copts = copts,
)
swift_library(
@@ -59,6 +64,7 @@ swift_library(
deps = [
":SwiftLintCore",
],
copts = copts,
)
swift_library(
@@ -86,6 +92,7 @@ swift_library(
":SwiftLintCore",
":SwiftLintExtraRules",
],
copts = copts,
)
swift_library(
@@ -99,6 +106,7 @@ swift_library(
"@sourcekitten_com_github_apple_swift_argument_parser//:ArgumentParser",
"@swiftlint_com_github_scottrhoyt_swifty_text_table//:SwiftyTextTable",
],
copts = copts,
)
swift_binary(
@@ -107,6 +115,7 @@ swift_binary(
deps = [
":swiftlint.library",
],
copts = copts,
)
apple_universal_binary(
+24 -10
View File
@@ -2,6 +2,10 @@
import CompilerPluginSupport
import PackageDescription
let swiftFeatures: [SwiftSetting] = [
.enableUpcomingFeature("ExistentialAny")
]
let package = Package(
name: "SwiftLint",
platforms: [.macOS(.v12)],
@@ -35,13 +39,15 @@ let package = Package(
"CollectionConcurrencyKit",
"SwiftLintFramework",
"SwiftyTextTable",
]
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "CLITests",
dependencies: [
"swiftlint"
]
],
swiftSettings: swiftFeatures
),
.target(
name: "SwiftLintCore",
@@ -57,11 +63,13 @@ let package = Package(
.product(name: "SwiftyTextTable", package: "SwiftyTextTable"),
.product(name: "Yams", package: "Yams"),
"SwiftLintCoreMacros"
]
],
swiftSettings: swiftFeatures
),
.target(
name: "SwiftLintBuiltInRules",
dependencies: ["SwiftLintCore"]
dependencies: ["SwiftLintCore"],
swiftSettings: swiftFeatures
),
.target(
name: "SwiftLintExtraRules",
@@ -76,7 +84,8 @@ let package = Package(
// Workaround for https://github.com/apple/swift-package-manager/issues/6940:
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"CollectionConcurrencyKit"
]
],
swiftSettings: swiftFeatures
),
.target(name: "DyldWarningWorkaround"),
.target(
@@ -95,21 +104,24 @@ let package = Package(
],
exclude: [
"Resources",
]
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "GeneratedTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers"
]
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "IntegrationTests",
dependencies: [
"SwiftLintFramework",
"SwiftLintTestHelpers"
]
],
swiftSettings: swiftFeatures
),
.testTarget(
name: "ExtraRulesTests",
@@ -129,14 +141,16 @@ let package = Package(
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
],
path: "Source/SwiftLintCoreMacros"
path: "Source/SwiftLintCoreMacros",
swiftSettings: swiftFeatures
),
.testTarget(
name: "MacroTests",
dependencies: [
"SwiftLintCoreMacros",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
]
],
swiftSettings: swiftFeatures
),
]
)
@@ -2,7 +2,7 @@
// DO NOT EDIT
/// The rule list containing all available rules built into SwiftLint.
public let builtInRules: [Rule.Type] = [
public let builtInRules: [any Rule.Type] = [
AccessibilityLabelForImageRule.self,
AccessibilityTraitForButtonRule.self,
AnonymousArgumentInMultilineClosureRule.self,
@@ -119,7 +119,7 @@ struct ConvenienceTypeRule: OptInRule, ConfigurationProviderRule {
private extension ConvenienceTypeRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: StructDeclSyntax) {
if hasViolation(
@@ -158,7 +158,7 @@ private extension ConvenienceTypeRule {
}
private class ConvenienceTypeCheckVisitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
private(set) var canBeConvenienceType = true
@@ -81,7 +81,7 @@ struct ExplicitEnumRawValueRule: OptInRule, ConfigurationProviderRule {
private extension ExplicitEnumRawValueRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: EnumCaseElementSyntax) {
if node.rawValue == nil, node.enclosingEnum()?.supportsRawValues == true {
@@ -173,7 +173,7 @@ struct ExplicitInitRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule,
Visitor(viewMode: .sourceAccurate, includeBareInit: configuration.includeBareInit)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(locationConverter: file.locationConverter, disabledRegions: disabledRegions(file: file))
}
}
@@ -32,7 +32,7 @@ struct ExplicitTopLevelACLRule: OptInRule, ConfigurationProviderRule {
private extension ExplicitTopLevelACLRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: ClassDeclSyntax) {
if hasViolation(modifiers: node.modifiers) {
@@ -78,7 +78,7 @@ private extension ExplicitTypeInterfaceRule {
final class Visitor: ViolationsSyntaxVisitor {
let configuration: ExplicitTypeInterfaceConfiguration
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
init(configuration: ExplicitTypeInterfaceConfiguration) {
self.configuration = configuration
@@ -37,7 +37,7 @@ struct JoinedDefaultParameterRule: SwiftSyntaxCorrectableRule, ConfigurationProv
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -104,7 +104,7 @@ struct LegacyCGGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationP
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
LegacyFunctionRuleHelper.Rewriter(
legacyFunctions: Self.legacyFunctions,
locationConverter: file.locationConverter,
@@ -15,7 +15,7 @@ struct LegacyConstantRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule
corrections: LegacyConstantRuleExamples.corrections
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -123,7 +123,7 @@ struct LegacyConstructorRule: SwiftSyntaxCorrectableRule, ConfigurationProviderR
"NSEdgeInsetsMake": "NSEdgeInsets",
"UIOffsetMake": "UIOffset"]
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -104,7 +104,7 @@ struct LegacyNSGeometryFunctionsRule: SwiftSyntaxCorrectableRule, ConfigurationP
LegacyFunctionRuleHelper.Visitor(legacyFunctions: Self.legacyFunctions)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
LegacyFunctionRuleHelper.Rewriter(
legacyFunctions: Self.legacyFunctions,
locationConverter: file.locationConverter,
@@ -25,7 +25,7 @@ struct NoExtensionAccessModifierRule: OptInRule, ConfigurationProviderRule {
private extension NoExtensionAccessModifierRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: ExtensionDeclSyntax) {
let modifiers = node.modifiers
@@ -132,7 +132,7 @@ private extension NoMagicNumbersRule {
collectViolation(forNode: node)
}
private func collectViolation(forNode node: ExprSyntaxProtocol) {
private func collectViolation(forNode node: some ExprSyntaxProtocol) {
if node.isMemberOfATestClass(testParentClasses) {
return
}
@@ -35,7 +35,7 @@ struct PreferZeroOverExplicitInitRule: SwiftSyntaxCorrectableRule, OptInRule, Co
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -58,7 +58,7 @@ struct PrivateOverFilePrivateRule: ConfigurationProviderRule, SwiftSyntaxCorrect
Visitor(validateExtensions: configuration.validateExtensions)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
validateExtensions: configuration.validateExtensions,
locationConverter: file.locationConverter,
@@ -22,7 +22,7 @@ struct RedundantNilCoalescingRule: OptInRule, SwiftSyntaxCorrectableRule, Config
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -105,7 +105,7 @@ struct RedundantOptionalInitializationRule: SwiftSyntaxCorrectableRule, Configur
""")
]
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -62,7 +62,7 @@ struct RedundantSetAccessControlRule: ConfigurationProviderRule {
private extension RedundantSetAccessControlRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
[FunctionDeclSyntax.self]
}
@@ -120,7 +120,7 @@ private extension SyntaxProtocol {
private extension DeclSyntax {
var modifiers: DeclModifierListSyntax? {
self.asProtocol(WithModifiersSyntax.self)?.modifiers
self.asProtocol((any WithModifiersSyntax).self)?.modifiers
}
}
@@ -80,7 +80,7 @@ struct ShorthandOptionalBindingRule: OptInRule, SwiftSyntaxCorrectableRule, Conf
deprecatedAliases: ["if_let_shadowing"]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -80,7 +80,7 @@ struct StaticOperatorRule: ConfigurationProviderRule, OptInRule {
private extension StaticOperatorRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: FunctionDeclSyntax) {
if node.isFreeFunction, node.isOperator {
@@ -185,7 +185,7 @@ private extension StrictFilePrivateRule {
violations.append(node.positionAfterSkippingLeadingTrivia)
}
private func implementedTypesInDecl(of node: SyntaxProtocol?) -> [String] {
private func implementedTypesInDecl(of node: (some SyntaxProtocol)?) -> [String] {
guard let node else {
queuedFatalError("Given node is nil. That should not happen.")
}
@@ -216,7 +216,7 @@ private final class ProtocolCollector: ViolationsSyntaxVisitor {
private(set) var protocols = [String: [ProtocolRequirementType]]()
private var currentProtocolName: String = ""
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .allExcept(ProtocolDeclSyntax.self) }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .allExcept(ProtocolDeclSyntax.self) }
override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
currentProtocolName = node.name.text
@@ -217,7 +217,7 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
return nil
}
private func violation(from node: SyntaxProtocol & SyntaxWithGenericClause) -> SyntacticSugarRuleViolation? {
private func violation(from node: some SyntaxProtocol & SyntaxWithGenericClause) -> SyntacticSugarRuleViolation? {
guard
let generic = node.genericArguments,
let firstGenericType = generic.arguments.first,
@@ -255,8 +255,8 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
}
}
private struct CorrectingContext {
let rule: Rule
private struct CorrectingContext<R: Rule> {
let rule: R
let file: SwiftLintFile
var contents: String
var corrections: [Correction] = []
@@ -30,7 +30,7 @@ struct ToggleBoolRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, Op
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -25,7 +25,7 @@ struct TrailingSemicolonRule: SwiftSyntaxCorrectableRule, ConfigurationProviderR
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -90,7 +90,7 @@ struct UnneededBreakInSwitchRule: SwiftSyntaxCorrectableRule, ConfigurationProvi
Visitor(viewMode: .sourceAccurate)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -28,7 +28,7 @@ struct UnneededSynthesizedInitializerRule: SwiftSyntaxCorrectableRule, Configura
corrections: UnneededSynthesizedInitializerRuleExamples.corrections
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -38,7 +38,7 @@ struct UnneededSynthesizedInitializerRule: SwiftSyntaxCorrectableRule, Configura
private extension UnneededSynthesizedInitializerRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
.allExcept(StructDeclSyntax.self, ClassDeclSyntax.self)
}
@@ -89,7 +89,7 @@ struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, SwiftSynta
Visitor(viewMode: .sourceAccurate)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -43,7 +43,7 @@ struct AnyObjectProtocolRule: SwiftSyntaxCorrectableRule, OptInRule, Configurati
return Visitor(viewMode: .sourceAccurate)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -114,7 +114,7 @@ struct BalancedXCTestLifecycleRule: SwiftSyntaxRule, OptInRule, ConfigurationPro
private extension BalancedXCTestLifecycleRule {
final class Visitor: ViolationsSyntaxVisitor {
private let testParentClasses: Set<String>
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
init(viewMode: SyntaxTreeViewMode, testParentClasses: Set<String>) {
self.testParentClasses = testParentClasses
@@ -138,7 +138,7 @@ private extension BalancedXCTestLifecycleRule {
}
private final class SetupTearDownVisitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
private(set) var methods: Set<XCTMethod> = []
override func visitPost(_ node: FunctionDeclSyntax) {
@@ -33,7 +33,7 @@ struct ClassDelegateProtocolRule: ConfigurationProviderRule {
private extension ClassDelegateProtocolRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
.allExcept(ProtocolDeclSyntax.self)
}
@@ -28,7 +28,7 @@ struct IBInspectableInExtensionRule: ConfigurationProviderRule, OptInRule {
private extension IBInspectableInExtensionRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
.allExcept(ExtensionDeclSyntax.self, VariableDeclSyntax.self)
}
@@ -81,7 +81,7 @@ struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, SwiftSyntax
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -16,7 +16,7 @@ struct NSObjectPreferIsEqualRule: ConfigurationProviderRule {
private extension NSObjectPreferIsEqualRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .extensionsAndProtocols }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .extensionsAndProtocols }
override func visitPost(_ node: FunctionDeclSyntax) {
if node.isSelfEqualFunction, node.isInObjcClass {
@@ -83,7 +83,7 @@ private extension OverriddenSuperCallRule {
final class Visitor: ViolationsSyntaxVisitor {
private let resolvedMethodNames: [String]
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
[ProtocolDeclSyntax.self]
}
@@ -49,7 +49,7 @@ private extension OverrideInExtensionRule {
super.init(viewMode: .sourceAccurate)
}
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .allExcept(ExtensionDeclSyntax.self) }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .allExcept(ExtensionDeclSyntax.self) }
override func visitPost(_ node: FunctionDeclSyntax) {
if node.modifiers.contains(keyword: .override) {
@@ -77,7 +77,7 @@ private extension OverrideInExtensionRule {
private class ClassNameCollectingVisitor: ViolationsSyntaxVisitor {
private(set) var classNames: Set<String> = []
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: ClassDeclSyntax) {
classNames.insert(node.name.text)
@@ -18,7 +18,7 @@ private extension PrivateSubjectRule {
final class Visitor: ViolationsSyntaxVisitor {
private let subjectTypes: Set<String> = ["PassthroughSubject", "CurrentValueSubject"]
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
[FunctionDeclSyntax.self, VariableDeclSyntax.self, SubscriptDeclSyntax.self, InitializerDeclSyntax.self]
}
@@ -197,7 +197,7 @@ struct PrivateSwiftUIStatePropertyRule: OptInRule, ConfigurationProviderRule {
private extension PrivateSwiftUIStatePropertyRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
[ProtocolDeclSyntax.self]
}
@@ -129,7 +129,7 @@ struct PrivateUnitTestRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRul
Visitor(configuration: configuration)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
configuration: configuration,
locationConverter: file.locationConverter,
@@ -142,7 +142,7 @@ private extension PrivateUnitTestRule {
final class Visitor: ViolationsSyntaxVisitor {
private let configuration: PrivateUnitTestConfiguration
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
init(configuration: PrivateUnitTestConfiguration) {
self.configuration = configuration
@@ -79,7 +79,7 @@ private extension ProhibitedSuperRule {
final class Visitor: ViolationsSyntaxVisitor {
private let resolvedMethodNames: [String]
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
[ProtocolDeclSyntax.self]
}
@@ -16,7 +16,7 @@ struct QuickDiscouragedFocusedTestRule: OptInRule, ConfigurationProviderRule {
private extension QuickDiscouragedFocusedTestRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: FunctionCallExprSyntax) {
if let identifierExpr = node.calledExpression.as(DeclReferenceExprSyntax.self),
@@ -16,7 +16,7 @@ struct QuickDiscouragedPendingTestRule: OptInRule, ConfigurationProviderRule {
private extension QuickDiscouragedPendingTestRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: FunctionCallExprSyntax) {
if let identifierExpr = node.calledExpression.as(DeclReferenceExprSyntax.self),
@@ -82,7 +82,7 @@ private extension RequiredDeinitRule {
private class DeinitVisitor: ViolationsSyntaxVisitor {
private(set) var hasDeinit = false
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: DeinitializerDeclSyntax) {
hasDeinit = true
@@ -28,7 +28,7 @@ struct StrongIBOutletRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRule
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -43,7 +43,7 @@ private extension TestCaseAccessibilityRule {
super.init(viewMode: .sourceAccurate)
}
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: ClassDeclSyntax) {
guard !testParentClasses.isDisjoint(with: node.inheritedTypes) else {
@@ -66,7 +66,7 @@ private final class XCTestClassVisitor: ViolationsSyntaxVisitor {
super.init(viewMode: .sourceAccurate)
}
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: VariableDeclSyntax) {
guard !node.modifiers.containsPrivateOrFileprivate(),
@@ -79,7 +79,7 @@ struct TypesafeArrayInitRule: AnalyzerRule, ConfigurationProviderRule {
}
}
private func pointsToSystemMapType(pointee: [String: SourceKitRepresentable]) -> Bool {
private func pointsToSystemMapType(pointee: [String: any SourceKitRepresentable]) -> Bool {
if let isSystem = pointee["key.is_system"], isSystem.isEqualTo(true),
let name = pointee["key.name"], name.isEqualTo("map(_:)"),
let typeName = pointee["key.typename"] as? String {
@@ -15,7 +15,7 @@ struct UnneededOverrideRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRu
corrections: UnneededOverrideRuleExamples.corrections
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -23,7 +23,7 @@ struct UnneededOverrideRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRu
}
}
private func simplify(_ node: SyntaxProtocol) -> ExprSyntaxProtocol? {
private func simplify(_ node: some SyntaxProtocol) -> (any ExprSyntaxProtocol)? {
if let expr = node.as(AwaitExprSyntax.self) {
return expr.expression
} else if let expr = node.as(TryExprSyntax.self) {
@@ -42,7 +42,7 @@ private func simplify(_ node: SyntaxProtocol) -> ExprSyntaxProtocol? {
return nil
}
private func extractFunctionCallSyntax(_ node: SyntaxProtocol) -> FunctionCallExprSyntax? {
private func extractFunctionCallSyntax(_ node: some SyntaxProtocol) -> FunctionCallExprSyntax? {
// Extract the function call from other expressions like try / await / return.
// If this returns a non-super calling function that will get filtered out later
var syntax = simplify(node)
@@ -15,7 +15,7 @@ struct UnusedClosureParameterRule: SwiftSyntaxCorrectableRule, ConfigurationProv
corrections: UnusedClosureParameterRuleExamples.corrections
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -84,7 +84,7 @@ struct UnusedControlFlowLabelRule: SwiftSyntaxCorrectableRule, ConfigurationProv
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -245,7 +245,7 @@ private extension SourceKittenDictionary {
}
func shouldSkipRelated(relatedUSRsToSkip: Set<String>) -> Bool {
return (value["key.related"] as? [[String: SourceKitRepresentable]])?
return (value["key.related"] as? [[String: any SourceKitRepresentable]])?
.compactMap { SourceKittenDictionary($0).usr }
.contains(where: relatedUSRsToSkip.contains) == true
}
@@ -131,7 +131,7 @@ struct UnusedSetterValueRule: ConfigurationProviderRule {
private extension UnusedSetterValueRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: AccessorDeclSyntax) {
guard node.accessorSpecifier.tokenKind == .keyword(.set) else {
@@ -153,7 +153,7 @@ struct ValidIBInspectableRule: ConfigurationProviderRule {
private extension ValidIBInspectableRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [FunctionDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [FunctionDeclSyntax.self] }
override func visitPost(_ node: VariableDeclSyntax) {
if node.isInstanceVariable, node.isIBInspectable, node.hasViolation {
@@ -69,11 +69,7 @@ struct WeakDelegateRule: OptInRule, ConfigurationProviderRule {
private extension WeakDelegateRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
[
ProtocolDeclSyntax.self
]
}
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: VariableDeclSyntax) {
guard node.hasDelegateSuffix,
@@ -22,7 +22,7 @@ struct ClosingBraceRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule {
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -50,7 +50,7 @@ struct ClosureSpacingRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule
Visitor(locationConverter: file.locationConverter)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -72,7 +72,7 @@ struct ControlStatementRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRu
]
)
func makeRewriter(file: SwiftLintCore.SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -82,7 +82,7 @@ struct ControlStatementRule: ConfigurationProviderRule, SwiftSyntaxCorrectableRu
private extension ControlStatementRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: CatchClauseSyntax) {
if node.catchItems.containSuperfluousParens == true {
@@ -179,7 +179,7 @@ struct DirectReturnRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule,
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -189,7 +189,7 @@ struct DirectReturnRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule,
private extension DirectReturnRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ statements: CodeBlockItemListSyntax) {
if let (binding, _) = statements.violation {
@@ -112,7 +112,7 @@ struct EmptyEnumArgumentsRule: SwiftSyntaxCorrectableRule, ConfigurationProvider
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -32,7 +32,7 @@ struct EmptyParametersRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRul
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -45,7 +45,7 @@ struct EmptyParenthesesWithTrailingClosureRule: SwiftSyntaxCorrectableRule, Conf
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -46,7 +46,7 @@ struct ExplicitSelfRule: CorrectableRule, ConfigurationProviderRule, AnalyzerRul
return []
}
let allCursorInfo: [[String: SourceKitRepresentable]]
let allCursorInfo: [[String: any SourceKitRepresentable]]
do {
let byteOffsets = try binaryOffsets(file: file, compilerArguments: compilerArguments)
allCursorInfo = try file.allCursorInfo(compilerArguments: compilerArguments,
@@ -85,7 +85,7 @@ private let kindsToFind: Set = [
private extension SwiftLintFile {
func allCursorInfo(compilerArguments: [String], atByteOffsets byteOffsets: [ByteCount]) throws
-> [[String: SourceKitRepresentable]] {
-> [[String: any SourceKitRepresentable]] {
return try byteOffsets.compactMap { offset in
if isExplicitAccess(at: offset) { return nil }
let cursorInfoRequest = Request.cursorInfoWithoutSymbolGraph(
@@ -22,7 +22,7 @@ private extension ImplicitReturnRule {
final class Visitor: ViolationsSyntaxVisitor {
private let config: ConfigurationType
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
init(config: ConfigurationType) {
self.config = config
@@ -188,7 +188,7 @@ private extension MultilineArgumentsBracketsRule {
}
}
private func hasLeadingNewline(_ syntax: SyntaxProtocol) -> Bool {
private func hasLeadingNewline(_ syntax: some SyntaxProtocol) -> Bool {
syntax.leadingTrivia.contains(where: \.isNewline)
}
}
@@ -44,7 +44,7 @@ struct NoSpaceInMethodCallRule: SwiftSyntaxCorrectableRule, ConfigurationProvide
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -106,7 +106,7 @@ private extension NonOverridableClassDeclarationRule {
private var finalClassScope = Stack<Bool>()
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
init(configuration: NonOverridableClassDeclarationConfiguration) {
self.configuration = configuration
@@ -29,7 +29,7 @@ struct NumberSeparatorRule: OptInRule, SwiftSyntaxCorrectableRule, Configuration
Visitor(configuration: configuration)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
configuration: configuration,
locationConverter: file.locationConverter,
@@ -154,7 +154,7 @@ struct OptionalEnumCaseMatchingRule: SwiftSyntaxCorrectableRule, ConfigurationPr
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -106,7 +106,7 @@ struct PreferSelfTypeOverTypeOfSelfRule: SwiftSyntaxCorrectableRule, OptInRule,
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -94,7 +94,7 @@ private extension PrefixedTopLevelConstantRule {
super.init(viewMode: .sourceAccurate)
}
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
override func visitPost(_ node: VariableDeclSyntax) {
guard node.bindingSpecifier.tokenKind == .keyword(.let) else {
@@ -23,7 +23,7 @@ struct ProtocolPropertyAccessorsOrderRule: ConfigurationProviderRule, SwiftSynta
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -33,7 +33,7 @@ struct ProtocolPropertyAccessorsOrderRule: ConfigurationProviderRule, SwiftSynta
private extension ProtocolPropertyAccessorsOrderRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
.allExcept(ProtocolDeclSyntax.self, VariableDeclSyntax.self)
}
@@ -27,7 +27,7 @@ struct RedundantDiscardableLetRule: SwiftSyntaxCorrectableRule, ConfigurationPro
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -40,7 +40,7 @@ private extension RedundantSelfInClosureRule {
private var functionCalls = Stack<FunctionCallType>()
private var selfCaptures = Stack<SelfCaptureKind>()
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .extensionsAndProtocols }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .extensionsAndProtocols }
override func visit(_ node: ActorDeclSyntax) -> SyntaxVisitorContinueKind {
typeDeclarations.push(.likeClass)
@@ -50,7 +50,7 @@ struct SelfBindingRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule, O
Visitor(bindIdentifier: configuration.bindIdentifier)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
bindIdentifier: configuration.bindIdentifier,
locationConverter: file.locationConverter,
@@ -66,7 +66,7 @@ struct SingleTestClassRule: SourceKitFreeRule, OptInRule, ConfigurationProviderR
private class TestClassVisitor: ViolationsSyntaxVisitor {
private let testParentClasses: Set<String>
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { .all }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
init(viewMode: SyntaxTreeViewMode, testParentClasses: Set<String>) {
self.testParentClasses = testParentClasses
@@ -80,8 +80,8 @@ struct SortedEnumCasesRule: ConfigurationProviderRule, OptInRule {
private extension SortedEnumCasesRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] {
return .allExcept(EnumDeclSyntax.self)
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
.allExcept(EnumDeclSyntax.self)
}
override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
@@ -98,7 +98,7 @@ struct SuperfluousElseRule: ConfigurationProviderRule, OptInRule {
private extension SuperfluousElseRule {
final class Visitor: ViolationsSyntaxVisitor {
override var skippableDeclarations: [DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { [ProtocolDeclSyntax.self] }
override func visitPost(_ node: IfExprSyntax) {
if node.violatesRule {
@@ -54,7 +54,7 @@ struct TrailingCommaRule: SwiftSyntaxCorrectableRule, ConfigurationProviderRule
)
}
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
mandatoryComma: configuration.mandatoryComma,
locationConverter: file.locationConverter,
@@ -200,7 +200,7 @@ private extension TrailingCommaRule {
}
private extension SourceLocationConverter {
func isSingleLine(node: SyntaxProtocol) -> Bool {
func isSingleLine(node: some SyntaxProtocol) -> Bool {
location(for: node.positionAfterSkippingLeadingTrivia).line ==
location(for: node.endPositionBeforeTrailingTrivia).line
}
@@ -73,7 +73,7 @@ struct UnneededParenthesesInClosureArgumentRule: ConfigurationProviderRule, Swif
]
)
func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? {
func makeRewriter(file: SwiftLintFile) -> (some ViolationsSyntaxRewriter)? {
Rewriter(
locationConverter: file.locationConverter,
disabledRegions: disabledRegions(file: file)
@@ -102,7 +102,7 @@ final class BodyLengthRuleVisitor<Parent: Rule>: ViolationsSyntaxVisitor {
}
private func registerViolations(
leftBrace: TokenSyntax, rightBrace: TokenSyntax, violationNode: SyntaxProtocol
leftBrace: TokenSyntax, rightBrace: TokenSyntax, violationNode: some SyntaxProtocol
) {
let leftBracePosition = leftBrace.positionAfterSkippingLeadingTrivia
let leftBraceLine = locationConverter.location(for: leftBracePosition).line
@@ -1,21 +1,21 @@
/// User-facing documentation for a SwiftLint rule.
struct RuleDocumentation {
private let ruleType: Rule.Type
private let ruleType: any Rule.Type
/// If this rule is an opt-in rule.
var isOptInRule: Bool { ruleType is OptInRule.Type }
var isOptInRule: Bool { ruleType is any OptInRule.Type }
/// If this rule is an analyzer rule.
var isAnalyzerRule: Bool { ruleType is AnalyzerRule.Type }
var isAnalyzerRule: Bool { ruleType is any AnalyzerRule.Type }
/// If this rule is a linter rule.
var isLinterRule: Bool { !isAnalyzerRule }
/// If this rule uses SourceKit.
var usesSourceKit: Bool { !(ruleType is SourceKitFreeRule.Type) }
var usesSourceKit: Bool { !(ruleType is any SourceKitFreeRule.Type) }
/// If this rule is disabled by default.
var isDisabledByDefault: Bool { ruleType is OptInRule.Type }
var isDisabledByDefault: Bool { ruleType is any OptInRule.Type }
/// If this rule is enabled by default.
var isEnabledByDefault: Bool { !isDisabledByDefault }
@@ -23,7 +23,7 @@ struct RuleDocumentation {
/// Creates a RuleDocumentation instance from a Rule type.
///
/// - parameter ruleType: A subtype of the `Rule` protocol to document.
init(_ ruleType: Rule.Type) {
init(_ ruleType: any Rule.Type) {
self.ruleType = ruleType
}
@@ -58,13 +58,13 @@ private func h1(_ text: String) -> String { "# \(text)" }
private func h2(_ text: String) -> String { "## \(text)" }
private func detailsSummary(_ rule: Rule) -> String {
private func detailsSummary(_ rule: some Rule) -> String {
let ruleDescription = """
* **Identifier:** \(type(of: rule).description.identifier)
* **Enabled by default:** \(rule is OptInRule ? "No" : "Yes")
* **Supports autocorrection:** \(rule is CorrectableRule ? "Yes" : "No")
* **Enabled by default:** \(rule is any OptInRule ? "No" : "Yes")
* **Supports autocorrection:** \(rule is any CorrectableRule ? "Yes" : "No")
* **Kind:** \(type(of: rule).description.kind)
* **Analyzer rule:** \(rule is AnalyzerRule ? "Yes" : "No")
* **Analyzer rule:** \(rule is any AnalyzerRule ? "Yes" : "No")
* **Minimum Swift compiler version:** \(type(of: rule).description.minSwiftVersion.rawValue)
"""
if rule.configurationDescription.hasContent {
@@ -36,7 +36,7 @@ extension Configuration {
inPath path: String,
forceExclude: Bool,
excludeBy: ExcludeBy,
fileManager: LintableFileManager = FileManager.default
fileManager: some LintableFileManager = FileManager.default
) -> [String] {
if fileManager.isFile(atPath: path) {
if forceExclude {
@@ -108,7 +108,7 @@ extension Configuration {
/// - parameter fileManager: The file manager to get child paths in a given parent location.
///
/// - returns: The expanded excluded file paths.
public func excludedPaths(fileManager: LintableFileManager = FileManager.default) -> [String] {
public func excludedPaths(fileManager: some LintableFileManager = FileManager.default) -> [String] {
return excludedPaths
.flatMap(Glob.resolveGlob)
.parallelFlatMap { fileManager.filesToLint(inPath: $0, rootDirectory: rootDirectory) }
@@ -169,7 +169,7 @@ extension Configuration {
}
case let .default(disabled: disabledRules, optIn: optInRules):
if rule is OptInRule.Type, Set(optInRules).isDisjoint(with: rule.description.allIdentifiers) {
if rule is any OptInRule.Type, Set(optInRules).isDisjoint(with: rule.description.allIdentifiers) {
Issue.genericWarning("\(message), but it is not enabled on '\(Key.optInRules.rawValue)'.").print()
} else if Set(disabledRules).isSuperset(of: rule.description.allIdentifiers) {
Issue.genericWarning("\(message), but it is disabled on '\(Key.disabledRules.rawValue)'.").print()
@@ -180,7 +180,7 @@ extension Configuration {
private static func warnAboutMisplacedAnalyzerRules(optInRules: [String], ruleList: RuleList) {
let analyzerRules = ruleList.list
.filter { $0.value.self is AnalyzerRule.Type }
.filter { $0.value.self is any AnalyzerRule.Type }
.map(\.key)
Set(analyzerRules).intersection(optInRules)
.sorted()
@@ -69,7 +69,7 @@ internal extension Configuration.FileGraph.FilePath {
}
// Load from url
var taskResult: (Data?, URLResponse?, Error?)
var taskResult: (Data?, URLResponse?, (any Error)?)
var taskDone = false
// `.ephemeral` disables caching (which we don't want to be managed by the system)
@@ -4,7 +4,7 @@ public extension Configuration {
/// - parameter ruleID: The identifier for the rule to look up.
///
/// - returns: The rule for the specified ID, if configured in this configuration.
func configuredRule(forID ruleID: String) -> Rule? {
func configuredRule(forID ruleID: String) -> (any Rule)? {
rules.first { rule in
if type(of: rule).description.identifier == ruleID {
if let customRules = rule as? CustomRules {
@@ -65,7 +65,7 @@ public extension Configuration {
let effectiveOptInRules: [String]
if optInRules.contains(RuleIdentifier.all.stringRepresentation) {
let allOptInRules = RuleRegistry.shared.list.list.compactMap { ruleID, ruleType in
ruleType is OptInRule.Type && !(ruleType is AnalyzerRule.Type) ? ruleID : nil
ruleType is any OptInRule.Type && !(ruleType is any AnalyzerRule.Type) ? ruleID : nil
}
effectiveOptInRules = Array(Set(allOptInRules + optInRules))
} else {
@@ -18,12 +18,12 @@ internal extension Configuration {
return Set(regularRuleIdentifiers + configurationCustomRulesIdentifiers)
}
private var cachedResultingRules: [Rule]?
private var cachedResultingRules: [any Rule]?
private let resultingRulesLock = NSLock()
/// All rules enabled in this configuration,
/// derived from rule mode (only / optIn - disabled) & existing rules
var resultingRules: [Rule] {
var resultingRules: [any Rule] {
// Lock for thread-safety (that's also why this is not a lazy var)
resultingRulesLock.lock()
defer { resultingRulesLock.unlock() }
@@ -33,7 +33,7 @@ internal extension Configuration {
// Calculate value
let customRulesFilter: (RegexConfiguration<CustomRules>) -> (Bool)
var resultingRules = [Rule]()
var resultingRules = [any Rule]()
switch mode {
case .allEnabled:
customRulesFilter = { _ in true }
@@ -53,7 +53,7 @@ internal extension Configuration {
resultingRules = allRulesWrapped.filter { tuple in
let id = type(of: tuple.rule).description.identifier
return !disabledRuleIdentifiers.contains(id)
&& (!(tuple.rule is OptInRule) || optInRuleIdentifiers.contains(id))
&& (!(tuple.rule is any OptInRule) || optInRuleIdentifiers.contains(id))
}.map { $0.rule }
}
@@ -288,7 +288,7 @@ internal extension Configuration {
}
let isOptInRule = allRulesWrapped
.first { type(of: $0.rule).description.identifier == identifier }?.rule is OptInRule
.first { type(of: $0.rule).description.identifier == identifier }?.rule is any OptInRule
Self.isOptInRuleCache[identifier] = isOptInRule
return isOptInRule
}
@@ -4,7 +4,7 @@ import SourceKittenFramework
/// values.
public struct SourceKittenDictionary {
/// The underlying SourceKitten dictionary.
public let value: [String: SourceKitRepresentable]
public let value: [String: any SourceKitRepresentable]
/// The cached substructure for this dictionary. Empty if there is no substructure.
public let substructure: [SourceKittenDictionary]
@@ -21,11 +21,11 @@ public struct SourceKittenDictionary {
/// Creates a SourceKitten dictionary given a `Dictionary<String, SourceKitRepresentable>` input.
///
/// - parameter value: The input dictionary/
public init(_ value: [String: SourceKitRepresentable]) {
public init(_ value: [String: any SourceKitRepresentable]) {
self.value = value
let substructure = value["key.substructure"] as? [SourceKitRepresentable] ?? []
self.substructure = substructure.compactMap { $0 as? [String: SourceKitRepresentable] }
let substructure = value["key.substructure"] as? [any SourceKitRepresentable] ?? []
self.substructure = substructure.compactMap { $0 as? [String: any SourceKitRepresentable] }
.map(Self.init)
let stringKind = value["key.kind"] as? String
@@ -136,20 +136,20 @@ public struct SourceKittenDictionary {
/// The fully preserved SourceKitten dictionaries for all the attributes associated with this dictionary.
public var swiftAttributes: [SourceKittenDictionary] {
let array = value["key.attributes"] as? [SourceKitRepresentable] ?? []
return array.compactMap { $0 as? [String: SourceKitRepresentable] }
let array = value["key.attributes"] as? [any SourceKitRepresentable] ?? []
return array.compactMap { $0 as? [String: any SourceKitRepresentable] }
.map(Self.init)
}
public var elements: [SourceKittenDictionary] {
let elements = value["key.elements"] as? [SourceKitRepresentable] ?? []
return elements.compactMap { $0 as? [String: SourceKitRepresentable] }
let elements = value["key.elements"] as? [any SourceKitRepresentable] ?? []
return elements.compactMap { $0 as? [String: any SourceKitRepresentable] }
.map(Self.init)
}
public var entities: [SourceKittenDictionary] {
let entities = value["key.entities"] as? [SourceKitRepresentable] ?? []
return entities.compactMap { $0 as? [String: SourceKitRepresentable] }
let entities = value["key.entities"] as? [any SourceKitRepresentable] ?? []
return entities.compactMap { $0 as? [String: any SourceKitRepresentable] }
.map(Self.init)
}
@@ -177,13 +177,13 @@ public struct SourceKittenDictionary {
}
public var inheritedTypes: [String] {
let array = value["key.inheritedtypes"] as? [SourceKitRepresentable] ?? []
let array = value["key.inheritedtypes"] as? [any SourceKitRepresentable] ?? []
return array.compactMap { ($0 as? [String: String]).flatMap { $0["key.name"] } }
}
public var secondarySymbols: [SourceKittenDictionary] {
let array = value["key.secondary_symbols"] as? [SourceKitRepresentable] ?? []
return array.compactMap { $0 as? [String: SourceKitRepresentable] }
let array = value["key.secondary_symbols"] as? [any SourceKitRepresentable] ?? []
return array.compactMap { $0 as? [String: any SourceKitRepresentable] }
.map(Self.init)
}
}
@@ -4,7 +4,7 @@ import SourceKittenFramework
public extension Request {
static let disableSourceKit = ProcessInfo.processInfo.environment["SWIFTLINT_DISABLE_SOURCEKIT"] != nil
func sendIfNotDisabled() throws -> [String: SourceKitRepresentable] {
func sendIfNotDisabled() throws -> [String: any SourceKitRepresentable] {
guard !Self.disableSourceKit else {
throw Self.Error.connectionInterrupted("SourceKit is disabled by `SWIFTLINT_DISABLE_SOURCEKIT`.")
}
@@ -10,7 +10,7 @@ import SwiftParserDiagnostics
import SwiftSyntax
private typealias FileCacheKey = UUID
private let responseCache = Cache { file -> [String: SourceKitRepresentable]? in
private let responseCache = Cache { file -> [String: any SourceKitRepresentable]? in
do {
return try Request.editorOpen(file: file.file).sendIfNotDisabled()
} catch let error as Request.Error {
@@ -267,7 +267,7 @@ extension SwiftLintFile {
invalidateCache()
}
public func ruleEnabled(violatingRanges: [NSRange], for rule: Rule) -> [NSRange] {
public func ruleEnabled(violatingRanges: [NSRange], for rule: some Rule) -> [NSRange] {
let fileRegions = regions()
if fileRegions.isEmpty { return violatingRanges }
return violatingRanges.filter { range in
@@ -278,7 +278,7 @@ extension SwiftLintFile {
}
}
public func ruleEnabled(violatingRange: NSRange, for rule: Rule) -> NSRange? {
public func ruleEnabled(violatingRange: NSRange, for rule: some Rule) -> NSRange? {
return ruleEnabled(violatingRanges: [violatingRange], for: rule).first
}
+1 -1
View File
@@ -49,7 +49,7 @@ public struct Stack<Element> {
}
}
extension Stack: CustomDebugStringConvertible where Element == CustomDebugStringConvertible {
extension Stack: CustomDebugStringConvertible where Element: CustomDebugStringConvertible {
public var debugDescription: String {
let intermediateElements = count > 1 ? elements[1 ..< count - 1] : []
return """
@@ -45,7 +45,7 @@ public struct Configuration {
// MARK: Public Computed
/// All rules enabled in this configuration
public var rules: [Rule] { rulesWrapper.resultingRules }
public var rules: [any Rule] { rulesWrapper.resultingRules }
/// The root directory is the directory that included & excluded paths relate to.
/// By default, the root directory is the current working directory,
@@ -1,2 +1,2 @@
@_spi(TestHelper)
public typealias ConfigurationRuleWrapper = (rule: Rule, initializedWithNonEmptyConfiguration: Bool)
public typealias ConfigurationRuleWrapper = (rule: any Rule, initializedWithNonEmptyConfiguration: Bool)
+1 -1
View File
@@ -55,7 +55,7 @@ public enum Issue: LocalizedError, Equatable {
/// - parameter error: Any `Error`.
///
/// - returns: A `SwiftLintError.genericWarning` containig the message of the `error` argument.
static func wrap(error: Error) -> Self {
static func wrap(error: some Error) -> Self {
error as? Issue ?? Self.genericWarning(error.localizedDescription)
}
+7 -7
View File
@@ -67,7 +67,7 @@ private extension Rule {
return nil
}
if !(self is SourceKitFreeRule) && file.sourcekitdFailed {
if !(self is any SourceKitFreeRule) && file.sourcekitdFailed {
warnSourceKitFailedOnce()
return nil
}
@@ -128,7 +128,7 @@ public struct Linter {
public let file: SwiftLintFile
/// Whether or not this linter will be used to collect information from several files.
public var isCollecting: Bool
fileprivate let rules: [Rule]
fileprivate let rules: [any Rule]
fileprivate let cache: LinterCache?
fileprivate let configuration: Configuration
fileprivate let compilerArguments: [String]
@@ -147,13 +147,13 @@ public struct Linter {
self.compilerArguments = compilerArguments
let rules = configuration.rules.filter { rule in
if compilerArguments.isEmpty {
return !(rule is AnalyzerRule)
return !(rule is any AnalyzerRule)
} else {
return rule is AnalyzerRule
return rule is any AnalyzerRule
}
}
self.rules = rules
self.isCollecting = rules.contains(where: { $0 is AnyCollectingRule })
self.isCollecting = rules.contains(where: { $0 is any AnyCollectingRule })
}
/// Returns a linter capable of checking for violations after running each rule's collection step.
@@ -175,7 +175,7 @@ public struct Linter {
public struct CollectedLinter {
/// The file to lint with this linter.
public let file: SwiftLintFile
private let rules: [Rule]
private let rules: [any Rule]
private let cache: LinterCache?
private let configuration: Configuration
private let compilerArguments: [String]
@@ -294,7 +294,7 @@ public struct CollectedLinter {
}
var corrections = [Correction]()
for rule in rules.compactMap({ $0 as? CorrectableRule }) {
for rule in rules.compactMap({ $0 as? any CorrectableRule }) {
let newCorrections = rule.correct(file: file, using: storage, compilerArguments: compilerArguments)
corrections += newCorrections
if newCorrections.isNotEmpty, !file.isVirtual {
@@ -28,11 +28,11 @@ public final class LinterCache {
private let readCacheLock = NSLock()
private var writeCache = Cache()
private let writeCacheLock = NSLock()
internal let fileManager: LintableFileManager
internal let fileManager: any LintableFileManager
private let location: URL?
private let swiftVersion: SwiftVersion
internal init(fileManager: LintableFileManager = FileManager.default, swiftVersion: SwiftVersion = .current) {
internal init(fileManager: some LintableFileManager = FileManager.default, swiftVersion: SwiftVersion = .current) {
location = nil
self.fileManager = fileManager
self.lazyReadCache = Cache()
@@ -43,14 +43,14 @@ public final class LinterCache {
///
/// - parameter configuration: The SwiftLint configuration for which this cache will be used.
/// - parameter fileManager: The file manager to use to read lintable file information.
public init(configuration: Configuration, fileManager: LintableFileManager = FileManager.default) {
public init(configuration: Configuration, fileManager: some LintableFileManager = FileManager.default) {
location = configuration.cacheURL
lazyReadCache = Cache()
self.fileManager = fileManager
self.swiftVersion = .current
}
private init(cache: Cache, location: URL?, fileManager: LintableFileManager, swiftVersion: SwiftVersion) {
private init(cache: Cache, location: URL?, fileManager: some LintableFileManager, swiftVersion: SwiftVersion) {
self.lazyReadCache = cache
self.location = location
self.fileManager = fileManager
+3 -3
View File
@@ -36,7 +36,7 @@ public struct Region: Equatable {
/// - parameter rule: The rule whose status should be determined.
///
/// - returns: True if the specified rule is enabled in this region.
public func isRuleEnabled(_ rule: Rule) -> Bool {
public func isRuleEnabled(_ rule: some Rule) -> Bool {
return !isRuleDisabled(rule)
}
@@ -45,7 +45,7 @@ public struct Region: Equatable {
/// - parameter rule: The rule whose status should be determined.
///
/// - returns: True if the specified rule is disabled in this region.
public func isRuleDisabled(_ rule: Rule) -> Bool {
public func isRuleDisabled(_ rule: some Rule) -> Bool {
guard !disabledRuleIdentifiers.contains(.all) else {
return true
}
@@ -61,7 +61,7 @@ public struct Region: Equatable {
/// - parameter rule: The rule to check.
///
/// - returns: Deprecated rule aliases.
public func deprecatedAliasesDisabling(rule: Rule) -> Set<String> {
public func deprecatedAliasesDisabling(rule: some Rule) -> Set<String> {
let identifiers = type(of: rule).description.deprecatedAliases
return Set(disabledRuleIdentifiers.map { $0.stringRepresentation }).intersection(identifiers)
}
@@ -2,7 +2,7 @@
// DO NOT EDIT
/// The reporters list containing all the reporters built into SwiftLint.
public let reportersList: [Reporter.Type] = [
public let reportersList: [any Reporter.Type] = [
CSVReporter.self,
CheckstyleReporter.self,
CodeClimateReporter.self,

Some files were not shown because too many files have changed in this diff Show More