From 60a1d342f43808a9d669cd53706688f9d717b970 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Sat, 24 Aug 2024 09:51:04 +0100 Subject: [PATCH] Remove `anyobject_protocol` rule (#5770) --- .swiftlint.yml | 1 - CHANGELOG.md | 4 +- .../Models/BuiltInRules.swift | 1 - .../Rules/Lint/AnyObjectProtocolRule.swift | 77 ------------------- Tests/GeneratedTests/GeneratedTests.swift | 6 -- .../default_rule_configurations.yml | 2 - 6 files changed, 3 insertions(+), 88 deletions(-) delete mode 100644 Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index 05b56bc77a..8dc4c564ed 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -15,7 +15,6 @@ opt_in_rules: - all disabled_rules: - anonymous_argument_in_multiline_closure - - anyobject_protocol - conditional_returns_on_newline - contrasted_opening_brace - convenience_type diff --git a/CHANGELOG.md b/CHANGELOG.md index 928ff5cfba..e42e2ca5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ #### Breaking -* None. +* The deprecated `anyobject_protocol` rule has now been removed. + [Martin Redington](https://github.com/mildm8nnered) + [#5769](https://github.com/realm/SwiftLint/issues/5769) #### Experimental diff --git a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift index 06613a00ad..73f981ab41 100644 --- a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift +++ b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift @@ -6,7 +6,6 @@ public let builtInRules: [any Rule.Type] = [ AccessibilityLabelForImageRule.self, AccessibilityTraitForButtonRule.self, AnonymousArgumentInMultilineClosureRule.self, - AnyObjectProtocolRule.self, ArrayInitRule.self, AttributesRule.self, BalancedXCTestLifecycleRule.self, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift deleted file mode 100644 index 3d8ded4ae5..0000000000 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/AnyObjectProtocolRule.swift +++ /dev/null @@ -1,77 +0,0 @@ -import SwiftSyntax - -// TODO: [09/07/2024] Remove deprecation warning after ~2 years. -private let warnDeprecatedOnceImpl: Void = { - Issue.ruleDeprecated(ruleID: AnyObjectProtocolRule.description.identifier).print() -}() - -private func warnDeprecatedOnce() { - _ = warnDeprecatedOnceImpl -} - -struct AnyObjectProtocolRule: SwiftSyntaxCorrectableRule, OptInRule { - var configuration = SeverityConfiguration(.warning) - - static let description = RuleDescription( - identifier: "anyobject_protocol", - name: "AnyObject Protocol", - description: "Prefer using `AnyObject` over `class` for class-only protocols", - kind: .lint, - nonTriggeringExamples: [ - Example("protocol SomeProtocol {}"), - Example("protocol SomeClassOnlyProtocol: AnyObject {}"), - Example("protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}"), - Example("@objc protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}"), - ], - triggeringExamples: [ - Example("protocol SomeClassOnlyProtocol: ↓class {}"), - Example("protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {}"), - Example("@objc protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {}"), - ], - corrections: [ - Example("protocol SomeClassOnlyProtocol: ↓class {}"): - Example("protocol SomeClassOnlyProtocol: AnyObject {}"), - Example("protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {}"): - Example("protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}"), - Example("@objc protocol SomeClassOnlyProtocol: ↓class, SomeInheritedProtocol {}"): - Example("@objc protocol SomeClassOnlyProtocol: AnyObject, SomeInheritedProtocol {}"), - ] - ) - - func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { - warnDeprecatedOnce() - return Visitor(configuration: configuration, file: file) - } - - func makeRewriter(file: SwiftLintFile) -> ViolationsSyntaxRewriter? { - Rewriter(configuration: configuration, file: file) - } -} - -private extension AnyObjectProtocolRule { - final class Visitor: ViolationsSyntaxVisitor { - override func visitPost(_ node: ClassRestrictionTypeSyntax) { - violations.append(node.positionAfterSkippingLeadingTrivia) - } - } - - final class Rewriter: ViolationsSyntaxRewriter { - override func visit(_ node: InheritedTypeSyntax) -> InheritedTypeSyntax { - let typeName = node.type - guard typeName.is(ClassRestrictionTypeSyntax.self) else { - return super.visit(node) - } - correctionPositions.append(node.positionAfterSkippingLeadingTrivia) - return super.visit( - node.with( - \.type, - TypeSyntax( - IdentifierTypeSyntax(name: .identifier("AnyObject"), genericArgumentClause: nil) - .with(\.leadingTrivia, typeName.leadingTrivia) - .with(\.trailingTrivia, typeName.trailingTrivia) - ) - ) - ) - } - } -} diff --git a/Tests/GeneratedTests/GeneratedTests.swift b/Tests/GeneratedTests/GeneratedTests.swift index d46eff77b4..1b506913c1 100644 --- a/Tests/GeneratedTests/GeneratedTests.swift +++ b/Tests/GeneratedTests/GeneratedTests.swift @@ -25,12 +25,6 @@ final class AnonymousArgumentInMultilineClosureRuleGeneratedTests: SwiftLintTest } } -final class AnyObjectProtocolRuleGeneratedTests: SwiftLintTestCase { - func testWithDefaultConfiguration() { - verifyRule(AnyObjectProtocolRule.description) - } -} - final class ArrayInitRuleGeneratedTests: SwiftLintTestCase { func testWithDefaultConfiguration() { verifyRule(ArrayInitRule.description) diff --git a/Tests/IntegrationTests/default_rule_configurations.yml b/Tests/IntegrationTests/default_rule_configurations.yml index 0c75d9ac43..969ca71aa8 100644 --- a/Tests/IntegrationTests/default_rule_configurations.yml +++ b/Tests/IntegrationTests/default_rule_configurations.yml @@ -4,8 +4,6 @@ accessibility_trait_for_button: severity: warning anonymous_argument_in_multiline_closure: severity: warning -anyobject_protocol: - severity: warning array_init: severity: warning attributes: