diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fc00ff80c..07ad5a2c52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,18 @@ * Rewrite `SwiftLintPlugin` using `BUILD_WORKSPACE_DIRECTORY` without relying on the `--config` option. [Garric Nahapetian](https://github.com/garricn) - + * Introduce SwiftLintCommandPlugin. Rename SwiftLintBuildToolPlugin. Add Swift Package Manager installation instructions. [garricn](https://github.com/garricn) +* The `superfluous_disable_command` rule will now be enabled for the `analyze` + command, unless it has been disabled, and will warn about superfluous + disablement of analyzer rules. + [Martin Redington](https://github.com/mildm8nnered) + [#4792](https://github.com/realm/SwiftLint/issues/4792) + #### Experimental * None. diff --git a/Source/SwiftLintCore/Models/Linter.swift b/Source/SwiftLintCore/Models/Linter.swift index 5fee18ad6c..f2d202977c 100644 --- a/Source/SwiftLintCore/Models/Linter.swift +++ b/Source/SwiftLintCore/Models/Linter.swift @@ -160,7 +160,7 @@ public struct Linter { if compilerArguments.isEmpty { return !(rule is any AnalyzerRule) } - return rule is any AnalyzerRule + return rule is any AnalyzerRule || rule is SuperfluousDisableCommandRule } self.rules = rules self.isCollecting = rules.contains(where: { $0 is any AnyCollectingRule }) diff --git a/Tests/SwiftLintFrameworkTests/CommandTests.swift b/Tests/SwiftLintFrameworkTests/CommandTests.swift index f4e697f321..f53bf9dbe8 100644 --- a/Tests/SwiftLintFrameworkTests/CommandTests.swift +++ b/Tests/SwiftLintFrameworkTests/CommandTests.swift @@ -1,6 +1,7 @@ // swiftlint:disable file_length import Foundation import SourceKittenFramework +@testable import SwiftLintBuiltInRules @testable import SwiftLintCore import XCTest @@ -454,4 +455,29 @@ class CommandTests: SwiftLintTestCase { [] ) } + + func testSuperfluousDisableCommandsEnabledForAnalyzer() { + let configuration = Configuration( + rulesMode: .default(disabled: [], optIn: [UnusedDeclarationRule.description.identifier]) + ) + let violations = violations( + Example(""" + public class Foo { + // swiftlint:disable:next unused_declaration + func foo() -> Int { + 1 + } + // swiftlint:disable:next unused_declaration + func bar() { + foo() + } + } + """), + config: configuration, + requiresFileOnDisk: true + ) + XCTAssertEqual(violations.count, 1) + XCTAssertEqual(violations.first?.ruleIdentifier, "superfluous_disable_command") + XCTAssertEqual(violations.first?.location.line, 3) + } }