mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Add options to generic_type_name and type_name rules
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user