mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Workaround union not working on Linux on Swift 3.1
This commit is contained in:
@@ -9,13 +9,16 @@
|
||||
import Foundation
|
||||
|
||||
extension CharacterSet {
|
||||
func isSuperset(ofCharactersIn string: String) -> Bool {
|
||||
#if swift(>=4.0)
|
||||
return isSuperset(of: CharacterSet(charactersIn: string))
|
||||
func isSuperset(ofCharactersIn string: String,
|
||||
union other: CharacterSet = CharacterSet()) -> Bool {
|
||||
#if swift(>=3.2)
|
||||
let set = union(other)
|
||||
return set.isSuperset(of: CharacterSet(charactersIn: string))
|
||||
#else
|
||||
// workaround for https://bugs.swift.org/browse/SR-3485
|
||||
return !Set(string.characters).contains { character in
|
||||
!contains(String(character).unicodeScalars.first!)
|
||||
let scalar = String(character).unicodeScalars.first!
|
||||
return !contains(scalar) && !other.contains(scalar)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule {
|
||||
return []
|
||||
}
|
||||
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name) {
|
||||
let allowedSymbols = configuration.allowedSymbols
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name, union: .alphanumerics) {
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
severity: .error,
|
||||
|
||||
@@ -48,8 +48,8 @@ public struct IdentifierNameRule: ASTRule, ConfigurationProviderRule {
|
||||
|
||||
let type = self.type(for: kind)
|
||||
if !isFunction {
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name) {
|
||||
let allowedSymbols = configuration.allowedSymbols
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name, union: .alphanumerics) {
|
||||
return [
|
||||
StyleViolation(ruleDescription: description,
|
||||
severity: .error,
|
||||
|
||||
@@ -75,8 +75,8 @@ public struct TypeNameRule: ASTRule, ConfigurationProviderRule {
|
||||
}
|
||||
|
||||
let name = name.nameStrippingLeadingUnderscoreIfPrivate(dictionary)
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name) {
|
||||
let allowedSymbols = configuration.allowedSymbols
|
||||
if !allowedSymbols.isSuperset(ofCharactersIn: name, union: .alphanumerics) {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
severity: .error,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
|
||||
Reference in New Issue
Block a user