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

Fix for #4788 - when disabled, superfluous_disable_command should not fire, even for invalid rule identifiers #4791

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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
with keypath arguments.
[JP Simard](https://github.com/jpsim)

* Fix for `superfluous_disable_command` not being completely disabled
by `disable` commands.
[Martin Redington](https://github.com/mildm8nnered)
[#4788](https://github.com/realm/SwiftLint/issues/4788)

## 0.50.3: Bundle of Towels

#### Breaking
Expand Down
7 changes: 6 additions & 1 deletion Source/SwiftLintFramework/Models/Linter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,14 @@ public struct CollectedLinter {
.configuration.customRuleConfigurations.map { RuleIdentifier($0.identifier) } ?? []
let allRuleIdentifiers = primaryRuleList.allValidIdentifiers().map { RuleIdentifier($0) }
let allValidIdentifiers = Set(allCustomIdentifiers + allRuleIdentifiers + [.all])
let superfluousRuleIdentifier = RuleIdentifier(SuperfluousDisableCommandRule.description.identifier)

return regions.flatMap { region in
region.disabledRuleIdentifiers.filter({ !allValidIdentifiers.contains($0) }).map { id in
region.disabledRuleIdentifiers.filter({
!allValidIdentifiers.contains($0) &&
!region.disabledRuleIdentifiers.contains(.all) &&
!region.disabledRuleIdentifiers.contains(superfluousRuleIdentifier)
}).map { id in
return StyleViolation(
ruleDescription: type(of: superfluousDisableCommandRule).description,
severity: superfluousDisableCommandRule.configuration.severity,
Expand Down
19 changes: 19 additions & 0 deletions Tests/SwiftLintFrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// swiftlint:disable file_length
import Foundation
import SourceKittenFramework
@_spi(TestHelper)
Expand Down Expand Up @@ -391,4 +392,22 @@ class CommandTests: XCTestCase {
[]
)
}

func testSuperfluousDisableCommandsDisabledWhenAllRulesDisabled() {
XCTAssertEqual(
violations(Example("""
// swiftlint:disable all
// swiftlint:disable non_existent_rule_name
"""
)),
[]
)
XCTAssertEqual(
violations(Example(
"// swiftlint:disable superfluous_disable_command\n" +
"// swiftlint:disable non_existent_rule_name\n"
)),
[]
)
}
}