Add options to generic_type_name and type_name rules

This commit is contained in:
Javier Hernández
2017-05-01 00:22:59 +01:00
parent 9d31eaccda
commit d652cfe4ab
9 changed files with 172 additions and 20 deletions
@@ -166,14 +166,16 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule {
return []
}
if !CharacterSet.alphanumerics.isSuperset(ofCharactersIn: name) {
let containsAllowedSymbol = configuration.allowedSymbols.first(where: { name.contains($0) }) != nil
if !containsAllowedSymbol && !CharacterSet.alphanumerics.isSuperset(ofCharactersIn: name) {
return [
StyleViolation(ruleDescription: type(of: self).description,
severity: .error,
location: Location(file: file, byteOffset: offset),
reason: "Generic type name should only contain alphanumeric characters: '\(name)'")
]
} else if !name.substring(to: name.index(after: name.startIndex)).isUppercase() {
} else if configuration.validatesStartWithLowercase &&
!name.substring(to: name.index(after: name.startIndex)).isUppercase() {
return [
StyleViolation(ruleDescription: type(of: self).description,
severity: .error,
@@ -74,12 +74,14 @@ public struct TypeNameRule: ASTRule, ConfigurationProviderRule {
}
let name = name.nameStrippingLeadingUnderscoreIfPrivate(dictionary)
if !CharacterSet.alphanumerics.isSuperset(ofCharactersIn: name) {
let containsAllowedSymbol = configuration.allowedSymbols.first(where: { name.contains($0) }) != nil
if !containsAllowedSymbol && !CharacterSet.alphanumerics.isSuperset(ofCharactersIn: name) {
return [StyleViolation(ruleDescription: type(of: self).description,
severity: .error,
location: Location(file: file, byteOffset: offset),
reason: "Type name should only contain alphanumeric characters: '\(name)'")]
} else if !name.substring(to: name.index(after: name.startIndex)).isUppercase() {
} else if configuration.validatesStartWithLowercase &&
!name.substring(to: name.index(after: name.startIndex)).isUppercase() {
return [StyleViolation(ruleDescription: type(of: self).description,
severity: .error,
location: Location(file: file, byteOffset: offset),