mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Update RegexConfig to use a Set for matchTokens. Fixed CustomRules.
This commit is contained in:
@@ -58,15 +58,13 @@ public struct CustomRules: Rule, ConfigProviderRule {
|
||||
}
|
||||
|
||||
private func validate(file: File, withConfig config: RegexConfig) -> [StyleViolation] {
|
||||
// We are not using the preconstucted regex due to the API available, but it is important
|
||||
// to still construct it at configuration parsing time to catch errors.
|
||||
let ranges = file.matchPattern(config.regex.pattern, withSyntaxKinds: config.matchTokens)
|
||||
let violations = ranges.map {
|
||||
StyleViolation(ruleDescription: config.description,
|
||||
severity: config.severity,
|
||||
location: Location(file: file, characterOffset: $0.location),
|
||||
reason: config.message)
|
||||
}
|
||||
return violations
|
||||
return file.matchPattern(config.regex).filter {
|
||||
!config.matchTokens.intersect($0.1).isEmpty
|
||||
}.map {
|
||||
StyleViolation(ruleDescription: config.description,
|
||||
severity: config.severity,
|
||||
location: Location(file: file, characterOffset: $0.0.location),
|
||||
reason: config.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct RegexConfig: RuleConfig, Equatable {
|
||||
let identifier: String
|
||||
var message = "Regex matched."
|
||||
var regex = NSRegularExpression()
|
||||
var matchTokens = SyntaxKind.allKinds()
|
||||
var matchTokens = Set(SyntaxKind.allKinds())
|
||||
var severityConfig = SeverityConfig(.Warning)
|
||||
|
||||
public var severity: ViolationSeverity {
|
||||
@@ -42,7 +42,7 @@ public struct RegexConfig: RuleConfig, Equatable {
|
||||
self.regex = try NSRegularExpression(pattern: regexString, options: [])
|
||||
}
|
||||
try [String].arrayOf(configDict["match_tokens"])?.forEach {
|
||||
self.matchTokens.append(try SyntaxKind(shortName: $0))
|
||||
self.matchTokens.insert(try SyntaxKind(shortName: $0))
|
||||
}
|
||||
if let severityString = configDict["severity"] as? String {
|
||||
try severityConfig.setConfig(severityString)
|
||||
|
||||
Reference in New Issue
Block a user