Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the superfluous_disable_command when running the analyzer #5522

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}