From 04cd2719c9b8a5c9748942ada367ccaa05947606 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Mon, 1 Apr 2024 23:50:28 +0100 Subject: [PATCH 1/8] Enable the superfluous_disable_command when running the analyzer --- CHANGELOG.md | 5 +++++ Source/SwiftLintCore/Models/Linter.swift | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fc00ff80c..670a74ea8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -218,6 +218,11 @@ [woxtu](https://github.com/woxtu) [Martin Redington](https://github.com/mildm8nnered) [#4999](https://github.com/realm/SwiftLint/issues/4999) +* 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) ## 0.54.0: Macro-Economic Forces diff --git a/Source/SwiftLintCore/Models/Linter.swift b/Source/SwiftLintCore/Models/Linter.swift index 5fee18ad6c..f5b15c5b39 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 }) From 519ecd35e9b6ee8fb12942fdce26e3d67d86046c Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 00:36:21 +0100 Subject: [PATCH 2/8] parentheses not required --- Source/SwiftLintCore/Models/Linter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftLintCore/Models/Linter.swift b/Source/SwiftLintCore/Models/Linter.swift index f5b15c5b39..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 || rule is SuperfluousDisableCommandRule) + return rule is any AnalyzerRule || rule is SuperfluousDisableCommandRule } self.rules = rules self.isCollecting = rules.contains(where: { $0 is any AnyCollectingRule }) From 384674a271cd98db55c57b7e30c33d90f1d9f8d2 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 00:38:14 +0100 Subject: [PATCH 3/8] Moved to enhancements --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 670a74ea8f..f30f8cacf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,12 @@ [phlippieb](https://github.com/phlippieb) [#5471](https://github.com/realm/SwiftLint/issues/5471) +* 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) + #### Bug Fixes * Silence `discarded_notification_center_observer` rule in closures. Furthermore, From 5c557cb98b8d079050319d17b7be125fdc289ec5 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 13:27:55 +0100 Subject: [PATCH 4/8] Removed extra entry --- CHANGELOG.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30f8cacf1..e8b7bab64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -224,11 +224,6 @@ [woxtu](https://github.com/woxtu) [Martin Redington](https://github.com/mildm8nnered) [#4999](https://github.com/realm/SwiftLint/issues/4999) -* 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) ## 0.54.0: Macro-Economic Forces From f6842df705def86b789e81633eece482d9a1ada0 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 23:32:10 +0100 Subject: [PATCH 5/8] Added test to make sure that superfluous_disable_command is enabled during analysis --- .../CommandTests.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Tests/SwiftLintFrameworkTests/CommandTests.swift b/Tests/SwiftLintFrameworkTests/CommandTests.swift index f4e697f321..0e29a78899 100644 --- a/Tests/SwiftLintFrameworkTests/CommandTests.swift +++ b/Tests/SwiftLintFrameworkTests/CommandTests.swift @@ -2,6 +2,7 @@ import Foundation import SourceKittenFramework @testable import SwiftLintCore +@testable import SwiftLintBuiltInRules import XCTest private extension Command { @@ -454,4 +455,28 @@ 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") + } } From 904cb66dfa92d19dd7f7f8ce12f1da02ca3d6554 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 23:33:21 +0100 Subject: [PATCH 6/8] Moved to breaking --- CHANGELOG.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b7bab64f..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. @@ -154,12 +160,6 @@ [phlippieb](https://github.com/phlippieb) [#5471](https://github.com/realm/SwiftLint/issues/5471) -* 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) - #### Bug Fixes * Silence `discarded_notification_center_observer` rule in closures. Furthermore, From 131f2ca855f47b4929d7bc4ba05c5de7aa3e8f1a Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 23:45:14 +0100 Subject: [PATCH 7/8] imports must be sorted :-) --- Tests/SwiftLintFrameworkTests/CommandTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftLintFrameworkTests/CommandTests.swift b/Tests/SwiftLintFrameworkTests/CommandTests.swift index 0e29a78899..6aba956e78 100644 --- a/Tests/SwiftLintFrameworkTests/CommandTests.swift +++ b/Tests/SwiftLintFrameworkTests/CommandTests.swift @@ -1,8 +1,8 @@ // swiftlint:disable file_length import Foundation import SourceKittenFramework -@testable import SwiftLintCore @testable import SwiftLintBuiltInRules +@testable import SwiftLintCore import XCTest private extension Command { From 979ee3ab0f98662edefb1348fab3471aa0d1a901 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Wed, 3 Apr 2024 09:57:02 +0100 Subject: [PATCH 8/8] Make sure our violation is on the correct line --- Tests/SwiftLintFrameworkTests/CommandTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/SwiftLintFrameworkTests/CommandTests.swift b/Tests/SwiftLintFrameworkTests/CommandTests.swift index 6aba956e78..f53bf9dbe8 100644 --- a/Tests/SwiftLintFrameworkTests/CommandTests.swift +++ b/Tests/SwiftLintFrameworkTests/CommandTests.swift @@ -478,5 +478,6 @@ class CommandTests: SwiftLintTestCase { ) XCTAssertEqual(violations.count, 1) XCTAssertEqual(violations.first?.ruleIdentifier, "superfluous_disable_command") + XCTAssertEqual(violations.first?.location.line, 3) } }