Skip to content

Commit

Permalink
Enable superfluous_disable_command rule for analyzer rules (#5522)
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered authored Apr 3, 2024
1 parent 8fdf669 commit dfb0982
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Models/Linter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftLintFrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swiftlint:disable file_length
import Foundation
import SourceKittenFramework
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import XCTest

Expand Down Expand Up @@ -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)
}
}

0 comments on commit dfb0982

Please sign in to comment.