diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e6fe9893..dbc9656f8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ [Bradley Mackey](https://github.com/bradleymackey) [#5514](https://github.com/realm/SwiftLint/issues/5514) +* The `inert_defer` and `unused_capture_list` rules have completely been removed after being deprecated for 2 years. + [SimplyDanny](https://github.com/SimplyDanny) + #### Experimental * None. diff --git a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift index 2527ee1d79..b93b94e752 100644 --- a/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift +++ b/Source/SwiftLintBuiltInRules/Models/BuiltInRules.swift @@ -92,7 +92,6 @@ public let builtInRules: [any Rule.Type] = [ ImplicitlyUnwrappedOptionalRule.self, InclusiveLanguageRule.self, IndentationWidthRule.self, - InertDeferRule.self, InvalidSwiftLintCommandRule.self, IsDisjointRule.self, JoinedDefaultParameterRule.self, diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift deleted file mode 100644 index 87a8775ebd..0000000000 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift +++ /dev/null @@ -1,116 +0,0 @@ -import SwiftSyntax - -// TODO: [12/23/2024] Remove deprecation warning after ~2 years. -private let warnDeprecatedOnceImpl: Void = { - Issue.ruleDeprecated(ruleID: InertDeferRule.identifier).print() -}() - -private func warnDeprecatedOnce() { - _ = warnDeprecatedOnceImpl -} - -struct InertDeferRule: SwiftSyntaxRule, OptInRule { - var configuration = SeverityConfiguration(.warning) - - static let description = RuleDescription( - identifier: "inert_defer", - name: "Inert Defer", - description: "If defer is at the end of its parent scope, it will be executed right where it is anyway", - kind: .lint, - nonTriggeringExamples: [ - Example(""" - func example3() { - defer { /* deferred code */ } - - print("other code") - } - """), - Example(""" - func example4() { - if condition { - defer { /* deferred code */ } - print("other code") - } - } - """), - Example(""" - func f() { - #if os(macOS) - defer { print(2) } - #else - defer { print(3) } - #endif - print(1) - } - """, excludeFromDocumentation: true), - ], - triggeringExamples: [ - Example(""" - func example0() { - ↓defer { /* deferred code */ } - } - """), - Example(""" - func example1() { - ↓defer { /* deferred code */ } - // comment - } - """), - Example(""" - func example2() { - if condition { - ↓defer { /* deferred code */ } - // comment - } - } - """), - Example(""" - func f(arg: Int) { - if arg == 1 { - ↓defer { print(2) } - // a comment - } else { - ↓defer { print(3) } - } - print(1) - #if os(macOS) - ↓defer { print(4) } - #else - ↓defer { print(5) } - #endif - } - """, excludeFromDocumentation: true), - ] - ) - - func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor { - warnDeprecatedOnce() - return Visitor(configuration: configuration, file: file) - } -} - -private extension InertDeferRule { - final class Visitor: ViolationsSyntaxVisitor { - override func visitPost(_ node: DeferStmtSyntax) { - guard node.isLastStatement else { - return - } - if let ifConfigClause = node.parent?.parent?.parent?.as(IfConfigClauseSyntax.self), - ifConfigClause.parent?.parent?.isLastStatement == false { - return - } - - violations.append(node.deferKeyword.positionAfterSkippingLeadingTrivia) - } - } -} - -private extension SyntaxProtocol { - var isLastStatement: Bool { - if let codeBlockItem = parent?.as(CodeBlockItemSyntax.self), - let codeBlockList = codeBlockItem.parent?.as(CodeBlockItemListSyntax.self) { - return codeBlockList.last == codeBlockItem - } - return false - } -} diff --git a/Tests/GeneratedTests/GeneratedTests.swift b/Tests/GeneratedTests/GeneratedTests.swift index 14f1c866ad..a67ea93b77 100644 --- a/Tests/GeneratedTests/GeneratedTests.swift +++ b/Tests/GeneratedTests/GeneratedTests.swift @@ -541,12 +541,6 @@ final class IndentationWidthRuleGeneratedTests: SwiftLintTestCase { } } -final class InertDeferRuleGeneratedTests: SwiftLintTestCase { - func testWithDefaultConfiguration() { - verifyRule(InertDeferRule.description) - } -} - final class InvalidSwiftLintCommandRuleGeneratedTests: SwiftLintTestCase { func testWithDefaultConfiguration() { verifyRule(InvalidSwiftLintCommandRule.description) diff --git a/Tests/IntegrationTests/default_rule_configurations.yml b/Tests/IntegrationTests/default_rule_configurations.yml index 835a0743a4..3a35616033 100644 --- a/Tests/IntegrationTests/default_rule_configurations.yml +++ b/Tests/IntegrationTests/default_rule_configurations.yml @@ -255,8 +255,6 @@ indentation_width: include_comments: true include_compiler_directives: true include_multiline_strings: true -inert_defer: - severity: warning invalid_swiftlint_command: severity: warning is_disjoint: