Skip to content

Commit

Permalink
Do not throw deprecation warning if deprecated property is not presen…
Browse files Browse the repository at this point in the history
…ted in configuration
  • Loading branch information
chipp committed Sep 15, 2024
1 parent 8241909 commit 7059f49
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5787](https://github.com/realm/SwiftLint/issues/5787)

* Do not throw deprecation warning if deprecated property is not
presented in configuration.
[chipp](https://github.com/chipp)
[#5791](https://github.com/realm/SwiftLint/issues/5791)

## 0.57.0: Squeaky Clean Cycle

#### Breaking
Expand Down
4 changes: 3 additions & 1 deletion Source/SwiftLintCoreMacros/RuleConfigurationMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ enum AutoConfigParser: MemberMacro {
"""
for option in nonInlinedOptions {
"""
try \(raw: option).apply(configuration[$\(raw: option).key], ruleID: Parent.identifier)
if let value = configuration[$\(raw: option).key] {
try \(raw: option).apply(value, ruleID: Parent.identifier)
}
"""
}
"""
Expand Down
24 changes: 18 additions & 6 deletions Tests/MacroTests/AutoConfigParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ final class AutoConfigParserTests: XCTestCase {
guard let configuration = configuration as? [String: Any] else {
throw Issue.invalidConfiguration(ruleID: Parent.identifier)
}
try eA.apply(configuration[$eA.key], ruleID: Parent.identifier)
try eB.apply(configuration[$eB.key], ruleID: Parent.identifier)
if let value = configuration[$eA.key] {
try eA.apply(value, ruleID: Parent.identifier)
}
if let value = configuration[$eB.key] {
try eB.apply(value, ruleID: Parent.identifier)
}
if !supportedKeys.isSuperset(of: configuration.keys) {
let unknownKeys = Set(configuration.keys).subtracting(supportedKeys)
Issue.invalidConfigurationKeys(ruleID: Parent.identifier, keys: unknownKeys).print()
Expand Down Expand Up @@ -131,8 +135,12 @@ final class AutoConfigParserTests: XCTestCase {
guard let configuration = configuration as? [String: Any] else {
return
}
try eA.apply(configuration[$eA.key], ruleID: Parent.identifier)
try eC.apply(configuration[$eC.key], ruleID: Parent.identifier)
if let value = configuration[$eA.key] {
try eA.apply(value, ruleID: Parent.identifier)
}
if let value = configuration[$eC.key] {
try eC.apply(value, ruleID: Parent.identifier)
}
if !supportedKeys.isSuperset(of: configuration.keys) {
let unknownKeys = Set(configuration.keys).subtracting(supportedKeys)
Issue.invalidConfigurationKeys(ruleID: Parent.identifier, keys: unknownKeys).print()
Expand Down Expand Up @@ -211,8 +219,12 @@ final class AutoConfigParserTests: XCTestCase {
guard let configuration = configuration as? [String: Any] else {
return
}
try severityConfiguration.apply(configuration[$severityConfiguration.key], ruleID: Parent.identifier)
try foo.apply(configuration[$foo.key], ruleID: Parent.identifier)
if let value = configuration[$severityConfiguration.key] {
try severityConfiguration.apply(value, ruleID: Parent.identifier)
}
if let value = configuration[$foo.key] {
try foo.apply(value, ruleID: Parent.identifier)
}
if !supportedKeys.isSuperset(of: configuration.keys) {
let unknownKeys = Set(configuration.keys).subtracting(supportedKeys)
Issue.invalidConfigurationKeys(ruleID: Parent.identifier, keys: unknownKeys).print()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ final class RuleConfigurationDescriptionTests: XCTestCase {
)
}

func testNoDeprecationWarningIfNoDeprecatedPropertySet() throws {
var configuration = TestConfiguration()

XCTAssert(try Issue.captureConsole { try configuration.apply(configuration: ["flag": false]) }.isEmpty)
}

func testInvalidKeys() throws {
var configuration = TestConfiguration()

Expand All @@ -511,10 +517,7 @@ final class RuleConfigurationDescriptionTests: XCTestCase {
"unsupported": true,
])
},
"""
warning: Configuration option 'set' in 'my_rule' rule is deprecated. Use the option 'other_opt' instead.
warning: Configuration for 'RuleMock' rule contains the invalid key(s) 'unknown', 'unsupported'.
"""
"warning: Configuration for 'RuleMock' rule contains the invalid key(s) 'unknown', 'unsupported'."
)
}

Expand Down

0 comments on commit 7059f49

Please sign in to comment.