Skip to content

Commit

Permalink
Fix for realm#4788 - when disabled, superfluous_disable_command sho…
Browse files Browse the repository at this point in the history
…uld not fire, even for invalid rule identifiers
  • Loading branch information
mildm8nnered committed Mar 4, 2023
1 parent 4f9a608 commit e8c7630
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ public struct SuperfluousDisableCommandRule: ConfigurationProviderRule, SourceKi
SwiftLint 'disable' commands are superfluous when the disabled rule would not have triggered a violation \
in the disabled region. Use " - " if you wish to document a command.
""",
kind: .lint
kind: .lint,
nonTriggeringExamples: [
Example("""
// swiftlint:disable all
// swiftlint:disable non_existent_rule_name
"""),
Example("""
// swiftlint:disable superfluous_disable_command
// swiftlint:disable non_existent_rule_name
""")
]
)

public func validate(file: SwiftLintFile) -> [StyleViolation] {
Expand Down

0 comments on commit e8c7630

Please sign in to comment.