-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Disable SeverityLevelsConfig error ruleParam if only warning is set #431
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,11 @@ public struct NameConfig: RuleConfig, Equatable { | |
var excluded: Set<String> | ||
|
||
var minLengthThreshold: Int { | ||
return max(minLength.warning, minLength.error) | ||
return max(minLength.warning, minLength.error ?? minLength.warning) | ||
} | ||
|
||
var maxLengthThreshold: Int { | ||
return min(maxLength.warning, maxLength.error) | ||
return min(maxLength.warning, maxLength.error ?? maxLength.warning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just be |
||
} | ||
|
||
public init(minLengthWarning: Int, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,24 +10,25 @@ import Foundation | |
|
||
public struct SeverityLevelsConfig: RuleConfig, Equatable { | ||
var warning: Int | ||
var error: Int | ||
var error: Int? | ||
|
||
var params: [RuleParameter<Int>] { | ||
return [RuleParameter(severity: .Error, value: error), | ||
if let error = error { | ||
return [RuleParameter(severity: .Error, value: error), | ||
RuleParameter(severity: .Warning, value: warning)] | ||
} | ||
return [RuleParameter(severity: .Warning, value: warning)] | ||
} | ||
|
||
mutating public func setConfig(config: AnyObject) throws { | ||
if let config = [Int].arrayOf(config) where !config.isEmpty { | ||
warning = config[0] | ||
if config.count > 1 { | ||
error = config[1] | ||
} | ||
error = (config.count > 1) ? config[1] : nil | ||
} else if let config = config as? [String: AnyObject] { | ||
if let warningNumber = config["warning"] as? Int { | ||
warning = warningNumber | ||
} | ||
if let errorNumber = config["error"] as? Int { | ||
error = config["error"] as? Int | ||
} else if let errorNumber = config["error"] as? Int { | ||
error = errorNumber | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure this can just be replaced with: if let warningNumber = config["warning"] as? Int {
warning = warningNumber
}
error = config["error"] as? Int What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's what I tried to convey in my original message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it, but it would change the behavior of the method in cases of config:
The first one can be addressed easily enough with a where clause. The second case might be ok too, since we're documenting this as a breaking change. However, since there's no formal config validator, I wasn't quite comfortable going that route. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An empty dictionary or dictionaries containing keys other than |
||
} | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be
return max(minLength.warning, minLength.error ?? minLength.warning)