mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Enable legacy_multiple and prefer_self_type_over_type_of_self in our codebase
This commit is contained in:
@@ -36,6 +36,7 @@ opt_in_rules:
|
||||
- legacy_random
|
||||
- let_var_whitespace
|
||||
- last_where
|
||||
- legacy_multiple
|
||||
- literal_expression_end_indentation
|
||||
- lower_acl_than_parent
|
||||
- modifier_order
|
||||
@@ -47,6 +48,7 @@ opt_in_rules:
|
||||
- overridden_super_call
|
||||
- override_in_extension
|
||||
- pattern_matching_keywords
|
||||
- prefer_self_type_over_type_of_self
|
||||
- private_action
|
||||
- private_outlet
|
||||
- prohibited_interface_builder
|
||||
|
||||
@@ -56,7 +56,7 @@ extension CallPairRule {
|
||||
}
|
||||
|
||||
return violatingLocations.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: severity,
|
||||
location: Location(file: file, byteOffset: $0),
|
||||
reason: reason)
|
||||
|
||||
@@ -74,7 +74,7 @@ extension Rule {
|
||||
}
|
||||
|
||||
public func isEqualTo(_ rule: Rule) -> Bool {
|
||||
return type(of: self).description == type(of: rule).description
|
||||
return Self.description == type(of: rule).description
|
||||
}
|
||||
|
||||
public func collectInfo(for file: SwiftLintFile, into storage: RuleStorage, compilerArguments: [String]) {
|
||||
@@ -164,7 +164,7 @@ public extension SubstitutionCorrectableRule {
|
||||
let violatingRanges = file.ruleEnabled(violatingRanges: violationRanges(in: file), for: self)
|
||||
guard !violatingRanges.isEmpty else { return [] }
|
||||
|
||||
let description = type(of: self).description
|
||||
let description = Self.description
|
||||
var corrections = [Correction]()
|
||||
var contents = file.contents
|
||||
for range in violatingRanges.sorted(by: { $0.location > $1.location }) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public struct BlockBasedKVORule: ASTRule, ConfigurationProviderRule, AutomaticTe
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -88,7 +88,7 @@ public struct ConvenienceTypeRule: ASTRule, OptInRule, ConfigurationProviderRule
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -35,7 +35,7 @@ public struct DiscouragedObjectLiteralRule: ASTRule, OptInRule, ConfigurationPro
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public struct DiscouragedOptionalBooleanRule: OptInRule, ConfigurationProviderRu
|
||||
let excludingKinds = SyntaxKind.commentAndStringKinds
|
||||
|
||||
return file.match(pattern: pattern, excludingSyntaxKinds: excludingKinds).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public struct DiscouragedOptionalCollectionRule: ASTRule, OptInRule, Configurati
|
||||
functionViolations(file: file, kind: kind, dictionary: dictionary)
|
||||
|
||||
return offsets.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public struct DuplicateImportsRule: ConfigurationProviderRule, AutomaticTestable
|
||||
}
|
||||
|
||||
// Make sure that each #if has corresponding #endif
|
||||
guard ranges.count % 2 == 0 else { return [] }
|
||||
guard ranges.count.isMultiple(of: 2) else { return [] }
|
||||
|
||||
return stride(from: 0, to: ranges.count, by: 2).reduce(into: []) { result, rangeIndex in
|
||||
result.append(ranges[rangeIndex].union(with: ranges[rangeIndex + 1]))
|
||||
@@ -84,7 +84,7 @@ public struct DuplicateImportsRule: ConfigurationProviderRule, AutomaticTestable
|
||||
}()
|
||||
|
||||
let location = Location(file: file, characterOffset: lineWithDuplicatedImport.range.location)
|
||||
let violation = StyleViolation(ruleDescription: type(of: self).description,
|
||||
let violation = StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: location)
|
||||
violations.append(violation)
|
||||
|
||||
@@ -138,7 +138,7 @@ public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTe
|
||||
thatAreNotInRanges: explicitInternalRanges)
|
||||
|
||||
return violations.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public struct ExplicitEnumRawValueRule: ASTRule, OptInRule, ConfigurationProvide
|
||||
|
||||
let violations = violatingOffsetsForEnum(dictionary: dictionary)
|
||||
return violations.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public struct ExplicitInitRule: SubstitutionCorrectableASTRule, ConfigurationPro
|
||||
public func validate(file: SwiftLintFile, kind: SwiftExpressionKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public struct ExplicitTopLevelACLRule: OptInRule, ConfigurationProviderRule, Aut
|
||||
}
|
||||
|
||||
return violationOffsets.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public struct ExplicitTypeInterfaceRule: OptInRule, ConfigurationProviderRule {
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -111,7 +111,7 @@ public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, O
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
@@ -148,7 +148,7 @@ public struct ExtensionAccessModifierRule: ASTRule, ConfigurationProviderRule, O
|
||||
}
|
||||
|
||||
return violationOffsets.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public struct FallthroughRule: ConfigurationProviderRule, OptInRule, AutomaticTe
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return file.match(pattern: "fallthrough", with: [.keyword]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public struct FatalErrorMessageRule: ASTRule, ConfigurationProviderRule, OptInRu
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ public struct FileNameNoSpaceRule: ConfigurationProviderRule, OptInRule {
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity.severity,
|
||||
location: Location(file: filePath, line: 1))]
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public struct FileNameRule: ConfigurationProviderRule, OptInRule {
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity.severity,
|
||||
location: Location(file: filePath, line: 1))]
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public struct ForWhereRule: ASTRule, ConfigurationProviderRule, AutomaticTestabl
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -18,7 +18,7 @@ public struct ForceCastRule: ConfigurationProviderRule, AutomaticTestableRule {
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return file.match(pattern: "as!", with: [.keyword]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public struct ForceTryRule: ConfigurationProviderRule, AutomaticTestableRule {
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return file.match(pattern: "try!", with: [.keyword]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public struct ForceUnwrappingRule: OptInRule, ConfigurationProviderRule, Automat
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public struct FunctionDefaultParameterAtEndRule: ASTRule, ConfigurationProviderR
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -88,7 +88,7 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule {
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(of: CharacterSet(charactersIn: name)) {
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: .error,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Generic type name should only contain alphanumeric characters: '\(name)'")
|
||||
@@ -96,14 +96,14 @@ public struct GenericTypeNameRule: ASTRule, ConfigurationProviderRule {
|
||||
} else if configuration.validatesStartWithLowercase &&
|
||||
!String(name[name.startIndex]).isUppercase() {
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: .error,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Generic type name should start with an uppercase character: '\(name)'")
|
||||
]
|
||||
} else if let severity = severity(forLength: name.count) {
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Generic type name should be between \(configuration.minLengthThreshold) and " +
|
||||
@@ -122,12 +122,12 @@ extension GenericTypeNameRule {
|
||||
private static let genericTypeRegex = regex(genericTypePattern)
|
||||
|
||||
private func validateGenericTypeAliases(in file: SwiftLintFile) -> [StyleViolation] {
|
||||
let pattern = "typealias\\s+\\w+?\\s*" + type(of: self).genericTypePattern + "\\s*="
|
||||
let pattern = "typealias\\s+\\w+?\\s*" + Self.genericTypePattern + "\\s*="
|
||||
return file.match(pattern: pattern).flatMap { range, tokens -> [(String, ByteCount)] in
|
||||
guard tokens.first == .keyword,
|
||||
Set(tokens.dropFirst()) == [.identifier],
|
||||
let match = type(of: self).genericTypeRegex.firstMatch(in: file.contents, options: [],
|
||||
range: range)?.range(at: 1) else {
|
||||
let match = Self.genericTypeRegex.firstMatch(in: file.contents, options: [],
|
||||
range: range)?.range(at: 1) else {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ extension GenericTypeNameRule {
|
||||
case let length = bodyOffset - start,
|
||||
case let byteRange = ByteRange(location: start, length: length),
|
||||
let range = file.stringView.byteRangeToNSRange(byteRange),
|
||||
let match = type(of: self).genericTypeRegex.firstMatch(in: file.contents, options: [],
|
||||
range: range)?.range(at: 1) else {
|
||||
let match = Self.genericTypeRegex.firstMatch(in: file.contents, options: [],
|
||||
range: range)?.range(at: 1) else {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -164,8 +164,8 @@ extension GenericTypeNameRule {
|
||||
case let contents = file.stringView,
|
||||
case let byteRange = ByteRange(location: offset, length: length),
|
||||
let range = contents.byteRangeToNSRange(byteRange),
|
||||
let match = type(of: self).genericTypeRegex.firstMatch(in: file.contents,
|
||||
options: [], range: range)?.range(at: 1),
|
||||
let match = Self.genericTypeRegex.firstMatch(in: file.contents,
|
||||
options: [], range: range)?.range(at: 1),
|
||||
match.location < minParameterOffset(parameters: dictionary.enclosedVarParameters, file: file)
|
||||
else {
|
||||
return []
|
||||
|
||||
@@ -61,7 +61,7 @@ public struct ImplicitlyUnwrappedOptionalRule: ASTRule, ConfigurationProviderRul
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity.severity,
|
||||
location: location)
|
||||
]
|
||||
|
||||
@@ -26,7 +26,7 @@ public struct IsDisjointRule: ConfigurationProviderRule, AutomaticTestableRule {
|
||||
let pattern = "\\bintersection\\(\\S+\\)\\.isEmpty"
|
||||
let excludingKinds = SyntaxKind.commentAndStringKinds
|
||||
return file.match(pattern: pattern, excludingSyntaxKinds: excludingKinds).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public struct JoinedDefaultParameterRule: SubstitutionCorrectableASTRule, Config
|
||||
kind: SwiftExpressionKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public struct LegacyCGGeometryFunctionsRule: CorrectableRule, ConfigurationProvi
|
||||
let pattern = "\\b(" + functions.joined(separator: "|") + ")\\b"
|
||||
|
||||
return file.match(pattern: pattern, with: [.identifier]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public struct LegacyConstantRule: CorrectableRule, ConfigurationProviderRule, Au
|
||||
.filter { Set($0.1).isSubset(of: [.identifier]) }
|
||||
.map { $0.0 }
|
||||
.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public struct LegacyConstructorRule: ASTRule, CorrectableRule, ConfigurationProv
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
@@ -153,7 +153,7 @@ public struct LegacyConstructorRule: ASTRule, CorrectableRule, ConfigurationProv
|
||||
guard kind == .call,
|
||||
let name = dictionary.name,
|
||||
dictionary.offset != nil,
|
||||
let expectedArguments = type(of: self).constructorsToArguments[name],
|
||||
let expectedArguments = Self.constructorsToArguments[name],
|
||||
dictionary.enclosedArguments.count == expectedArguments.count else {
|
||||
return false
|
||||
}
|
||||
@@ -184,10 +184,10 @@ public struct LegacyConstructorRule: ASTRule, CorrectableRule, ConfigurationProv
|
||||
guard let byteRange = dictionary.byteRange,
|
||||
let range = file.stringView.byteRangeToNSRange(byteRange),
|
||||
let name = dictionary.name,
|
||||
let correctedName = type(of: self).constructorsToCorrectedNames[name],
|
||||
let correctedName = Self.constructorsToCorrectedNames[name],
|
||||
file.ruleEnabled(violatingRanges: [range], for: self) == [range],
|
||||
case let arguments = argumentsContents(file: file, arguments: dictionary.enclosedArguments),
|
||||
let expectedArguments = type(of: self).constructorsToArguments[name],
|
||||
let expectedArguments = Self.constructorsToArguments[name],
|
||||
arguments.count == expectedArguments.count else {
|
||||
continue
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public struct LegacyConstructorRule: ASTRule, CorrectableRule, ConfigurationProv
|
||||
}
|
||||
|
||||
let corrections = adjustedLocations.map {
|
||||
Correction(ruleDescription: type(of: self).description,
|
||||
Correction(ruleDescription: Self.description,
|
||||
location: Location(file: file, characterOffset: $0))
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public struct LegacyHashingRule: ASTRule, ConfigurationProviderRule, AutomaticTe
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public struct LegacyMultipleRule: OptInRule, ConfigurationProviderRule, Automati
|
||||
let pattern = "(?!\\b\\s*)%\(RegexHelpers.variableOrNumber)[=!]=\\s*0\\b"
|
||||
return file.match(pattern: pattern, excludingSyntaxKinds: SyntaxKind.commentAndStringKinds)
|
||||
.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public struct LegacyNSGeometryFunctionsRule: CorrectableRule, ConfigurationProvi
|
||||
let pattern = "\\b(" + functions.joined(separator: "|") + ")\\b"
|
||||
|
||||
return file.match(pattern: pattern, with: [.identifier]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public struct LegacyRandomRule: ASTRule, OptInRule, ConfigurationProviderRule, A
|
||||
|
||||
let location = Location(file: file, byteOffset: offset)
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: location)
|
||||
]
|
||||
|
||||
@@ -94,7 +94,7 @@ public struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, Correcta
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
let matches = violationMatchesRanges(in: file)
|
||||
return matches.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public struct NimbleOperatorRule: ConfigurationProviderRule, OptInRule, Correcta
|
||||
.filter { !file.ruleEnabled(violatingRanges: [$0], for: self).isEmpty }
|
||||
guard !matches.isEmpty else { return [] }
|
||||
|
||||
let description = type(of: self).description
|
||||
let description = Self.description
|
||||
var corrections: [Correction] = []
|
||||
var contents = file.contents
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public struct NoExtensionAccessModifierRule: ASTRule, OptInRule, ConfigurationPr
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: aclToken.offset))
|
||||
]
|
||||
|
||||
@@ -40,7 +40,7 @@ public struct NoFallthroughOnlyRule: ASTRule, ConfigurationProviderRule, Automat
|
||||
let nsRange = nonCommentCaseBody[0].0
|
||||
if contents.substring(with: nsRange) == "fallthrough" && nonCommentCaseBody[0].1 == [.keyword] &&
|
||||
!isNextTokenUnknownAttribute(afterOffset: byteRange.upperBound, file: file) {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: nsRange.location))]
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public struct NoGroupingExtensionRule: OptInRule, ConfigurationProviderRule, Aut
|
||||
return nil
|
||||
}
|
||||
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: element.offset))
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public struct ObjectLiteralRule: ASTRule, ConfigurationProviderRule, OptInRule {
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -61,7 +61,7 @@ public struct PatternMatchingKeywordsRule: ASTRule, ConfigurationProviderRule, O
|
||||
}
|
||||
|
||||
return (letMatches + varMatches).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public struct PrivateOverFilePrivateRule: ConfigurationProviderRule, Substitutio
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public struct RedundantNilCoalescingRule: OptInRule, SubstitutionCorrectableRule
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public struct RedundantObjcAttributeRule: SubstitutionCorrectableRule, Configura
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public struct RedundantOptionalInitializationRule: SubstitutionCorrectableASTRul
|
||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public struct RedundantSetAccessControlRule: ConfigurationProviderRule, Automati
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -84,7 +84,7 @@ public struct RedundantStringEnumValueRule: ASTRule, ConfigurationProviderRule,
|
||||
|
||||
let violations = violatingOffsetsForEnum(dictionary: dictionary, file: file)
|
||||
return violations.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRul
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map { range in
|
||||
StyleViolation(
|
||||
ruleDescription: type(of: self).description,
|
||||
ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location)
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
|
||||
public func validate(file: SwiftLintFile, kind: SwiftDeclarationKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public struct StaticOperatorRule: ASTRule, ConfigurationProviderRule, OptInRule,
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -62,7 +62,7 @@ public struct StrictFilePrivateRule: OptInRule, ConfigurationProviderRule, Autom
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
// Mark all fileprivate occurences as a violation
|
||||
return file.match(pattern: "fileprivate", with: [.attributeBuiltin]).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public struct SyntacticSugarRule: SubstitutionCorrectableRule, ConfigurationProv
|
||||
let contents = file.stringView
|
||||
return violationResults(in: file).map {
|
||||
let typeString = contents.substring(with: $0.range(at: 1))
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.range.location),
|
||||
reason: message(for: typeString))
|
||||
@@ -189,7 +189,7 @@ public struct SyntacticSugarRule: SubstitutionCorrectableRule, ConfigurationProv
|
||||
typeString = "Dictionary<String, Int>"
|
||||
sugaredType = "[String: Int]"
|
||||
default:
|
||||
return type(of: self).description.description
|
||||
return Self.description.description
|
||||
}
|
||||
|
||||
return "Shorthand syntactic sugar should be used, i.e. \(sugaredType) instead of \(typeString)."
|
||||
|
||||
@@ -30,7 +30,7 @@ public struct TrailingSemicolonRule: SubstitutionCorrectableRule, ConfigurationP
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -71,18 +71,18 @@ public struct TypeNameRule: ASTRule, ConfigurationProviderRule {
|
||||
.nameStrippingTrailingSwiftUIPreviewProvider(dictionary)
|
||||
let allowedSymbols = configuration.allowedSymbols.union(.alphanumerics)
|
||||
if !allowedSymbols.isSuperset(of: CharacterSet(charactersIn: name)) {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: .error,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Type name should only contain alphanumeric characters: '\(name)'")]
|
||||
} else if configuration.validatesStartWithLowercase &&
|
||||
!String(name[name.startIndex]).isUppercase() {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: .error,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Type name should start with an uppercase character: '\(name)'")]
|
||||
} else if let severity = severity(forLength: name.count) {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Type name should be between \(configuration.minLengthThreshold) and " +
|
||||
|
||||
@@ -72,7 +72,7 @@ public struct UnavailableFunctionRule: ASTRule, ConfigurationProviderRule, OptIn
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -70,7 +70,7 @@ public struct UnneededBreakInSwitchRule: ConfigurationProviderRule, AutomaticTes
|
||||
return nil
|
||||
}
|
||||
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location))
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, Aut
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file).map {
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location),
|
||||
reason: configuration.consoleDescription)
|
||||
@@ -112,7 +112,7 @@ public struct UntypedErrorInCatchRule: OptInRule, ConfigurationProviderRule, Aut
|
||||
}
|
||||
|
||||
fileprivate func violationRanges(in file: SwiftLintFile) -> [NSRange] {
|
||||
return file.match(pattern: type(of: self).regularExpression,
|
||||
return file.match(pattern: Self.regularExpression,
|
||||
with: [.keyword, .keyword, .identifier])
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ extension UntypedErrorInCatchRule: CorrectableRule {
|
||||
if matches.isEmpty { return [] }
|
||||
|
||||
var contents = file.contents.bridge()
|
||||
let description = type(of: self).description
|
||||
let description = Self.description
|
||||
var corrections = [Correction]()
|
||||
|
||||
for range in matches.reversed() where contents.substring(with: range).contains("let error") {
|
||||
|
||||
@@ -54,7 +54,7 @@ public struct UnusedEnumeratedRule: ASTRule, ConfigurationProviderRule, Automati
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: reason)
|
||||
|
||||
@@ -48,7 +48,7 @@ public struct XCTFailMessageRule: ASTRule, ConfigurationProviderRule, AutomaticT
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public struct XCTSpecificMatcherRule: ASTRule, OptInRule, ConfigurationProviderR
|
||||
else { return [] }
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Prefer the specific matcher '\(suggestedMatcher)' instead.")
|
||||
|
||||
@@ -42,7 +42,7 @@ public struct AnyObjectProtocolRule: SubstitutionCorrectableASTRule, OptInRule,
|
||||
kind: SwiftDeclarationKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public struct ArrayInitRule: ASTRule, ConfigurationProviderRule, OptInRule, Auto
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -73,7 +73,7 @@ public struct ClassDelegateProtocolRule: ASTRule, ConfigurationProviderRule, Aut
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -34,10 +34,10 @@ public struct CompilerProtocolInitRule: ASTRule, ConfigurationProviderRule {
|
||||
return violationRanges(in: file, kind: kind, dictionary: dictionary).map {
|
||||
let (violation, range) = $0
|
||||
return StyleViolation(
|
||||
ruleDescription: type(of: self).description,
|
||||
ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location),
|
||||
reason: type(of: self).violationReason(protocolName: violation.protocolName, isPlural: false)
|
||||
reason: Self.violationReason(protocolName: violation.protocolName, isPlural: false)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public struct DeploymentTargetRule: ConfigurationProviderRule {
|
||||
Availability \(violationType) is using a version (\(versionString)) that is \
|
||||
satisfied by the deployment target (\(minVersion.stringValue)) for platform \(platform).
|
||||
"""
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, byteOffset: byteOffsetToReport),
|
||||
reason: reason)
|
||||
|
||||
@@ -53,7 +53,7 @@ public struct DiscardedNotificationCenterObserverRule: ASTRule, ConfigurationPro
|
||||
public func validate(file: SwiftLintFile, kind: SwiftExpressionKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationOffsets(in: file, dictionary: dictionary, kind: kind).map { location in
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: location))
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public struct DiscouragedDirectInitRule: ASTRule, ConfigurationProviderRule {
|
||||
return []
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public struct DuplicateEnumCasesRule: ConfigurationProviderRule, ASTRule, Automa
|
||||
return elementsByName.filter { $0.value.count > 1 }
|
||||
.flatMap { $0.value }
|
||||
.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public struct DynamicInlineRule: ASTRule, ConfigurationProviderRule, AutomaticTe
|
||||
else {
|
||||
return []
|
||||
}
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: funcOffset))]
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public struct EmptyXCTestMethodRule: Rule, OptInRule, ConfigurationProviderRule,
|
||||
subDictionary.enclosedVarParameters.isEmpty,
|
||||
subDictionary.substructure.isEmpty else { return nil }
|
||||
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
|
||||
}
|
||||
|
||||
return StyleViolation(
|
||||
ruleDescription: type(of: self).description,
|
||||
ruleDescription: Self.description,
|
||||
severity: severity,
|
||||
location: Location(file: file, characterOffset: range.location),
|
||||
reason: violationLevel.reason
|
||||
|
||||
@@ -44,7 +44,7 @@ public struct IBInspectableInExtensionRule: ConfigurationProviderRule, OptInRule
|
||||
}
|
||||
}
|
||||
.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ public struct IdenticalOperandsRule: ConfigurationProviderRule, OptInRule, Autom
|
||||
}
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
let operators = type(of: self).operators.joined(separator: "|")
|
||||
let operators = Self.operators.joined(separator: "|")
|
||||
return
|
||||
file.matchesAndTokens(matching: "\\s(" + operators + ")\\s")
|
||||
.filter { _, tokens in tokens.isEmpty }
|
||||
.compactMap { matchResult, _ in violationRangeFrom(match: matchResult, in: file) }
|
||||
.map { range in
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location))
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public struct InertDeferRule: ConfigurationProviderRule, AutomaticTestableRule {
|
||||
return nil
|
||||
}
|
||||
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location))
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, Auto
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return validateACL(isHigherThan: .open, in: file.structureDictionary).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||
|
||||
public func validate(file: SwiftLintFile) -> [StyleViolation] {
|
||||
return violationRanges(in: file, matching: pattern).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: $0.location))
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||
if matches.isEmpty { return [] }
|
||||
|
||||
var nsstring = file.contents.bridge()
|
||||
let description = type(of: self).description
|
||||
let description = Self.description
|
||||
var corrections = [Correction]()
|
||||
for var range in matches.reversed() {
|
||||
if keepLastChar {
|
||||
|
||||
@@ -99,7 +99,7 @@ public struct MissingDocsRule: OptInRule, ConfigurationProviderRule, AutomaticTe
|
||||
let acls = configuration.parameters.map { $0.value }
|
||||
let dict = file.structureDictionary
|
||||
return file.missingDocOffsets(in: dict, acls: acls).map { offset, acl in
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.parameters.first { $0.value == acl }?.severity ?? .warning,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "\(acl.description) declarations should be documented.")
|
||||
|
||||
@@ -34,7 +34,7 @@ public struct NSLocalizedStringKeyRule: ASTRule, OptInRule, ConfigurationProvide
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: byteRange.location))
|
||||
]
|
||||
|
||||
@@ -52,7 +52,7 @@ public struct NSLocalizedStringRequireBundleRule: ASTRule, OptInRule, Configurat
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -40,7 +40,7 @@ public struct NSObjectPreferIsEqualRule: Rule, ConfigurationProviderRule, Automa
|
||||
isDoubleEqualsMethod(subDictionary, onType: typeName),
|
||||
let offset = subDictionary.offset
|
||||
else { return nil }
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public struct NotificationCenterDetachmentRule: ASTRule, ConfigurationProviderRu
|
||||
}
|
||||
|
||||
return violationOffsets(file: file, dictionary: dictionary).map { offset in
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
}
|
||||
|
||||
@@ -70,9 +70,9 @@ public struct OrphanedDocCommentRule: ConfigurationProviderRule {
|
||||
return false
|
||||
}
|
||||
|
||||
return !contents.trimmingCharacters(in: type(of: self).characterSet).isEmpty
|
||||
return !contents.trimmingCharacters(in: Self.characterSet).isEmpty
|
||||
}.map { token in
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: token.offset))
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public struct OverriddenSuperCallRule: ConfigurationProviderRule, ASTRule, OptIn
|
||||
let callsToSuper = dictionary.extractCallsToSuper(methodName: name)
|
||||
|
||||
if callsToSuper.isEmpty {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Method '\(name)' should call to super function")]
|
||||
} else if callsToSuper.count > 1 {
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Method '\(name)' should call to super only once")]
|
||||
|
||||
@@ -56,7 +56,7 @@ public struct OverrideInExtensionRule: ConfigurationProviderRule, OptInRule, Aut
|
||||
}
|
||||
}
|
||||
.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public struct PrivateActionRule: ASTRule, OptInRule, ConfigurationProviderRule,
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -50,7 +50,7 @@ public struct PrivateOutletRule: ASTRule, OptInRule, ConfigurationProviderRule {
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: location)
|
||||
]
|
||||
|
||||
@@ -172,7 +172,7 @@ public struct PrivateUnitTestRule: ASTRule, ConfigurationProviderRule, CacheDesc
|
||||
!dictionary.enclosedSwiftAttributes.contains(.objc)
|
||||
else { return [] }
|
||||
let offset = dictionary.offset ?? 0
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severityConfiguration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: configuration.message)]
|
||||
|
||||
@@ -27,7 +27,7 @@ public struct ProhibitedInterfaceBuilderRule: ConfigurationProviderRule, ASTRule
|
||||
}
|
||||
|
||||
func makeViolation() -> StyleViolation {
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public struct ProhibitedSuperRule: ConfigurationProviderRule, ASTRule, OptInRule
|
||||
!dictionary.extractCallsToSuper(methodName: name).isEmpty
|
||||
else { return [] }
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset),
|
||||
reason: "Method '\(name)' should not call to super function")]
|
||||
|
||||
@@ -53,7 +53,7 @@ public struct QuickDiscouragedCallRule: OptInRule, ConfigurationProviderRule, Au
|
||||
else { return [] }
|
||||
|
||||
return violationOffsets(in: dictionary.enclosedArguments).map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0),
|
||||
reason: "Discouraged call inside a '\(name)' block.")
|
||||
|
||||
@@ -50,7 +50,7 @@ public struct QuickDiscouragedFocusedTestRule: OptInRule, ConfigurationProviderR
|
||||
let offset = dictionary.offset,
|
||||
QuickFocusedCallKind(rawValue: name) != nil else { return [] }
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public struct QuickDiscouragedPendingTestRule: OptInRule, ConfigurationProviderR
|
||||
let offset = dictionary.offset,
|
||||
QuickPendingCallKind(rawValue: name) != nil else { return [] }
|
||||
|
||||
return [StyleViolation(ruleDescription: type(of: self).description,
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public struct RawValueForCamelCasedCodableEnumRule: ASTRule, OptInRule, Configur
|
||||
|
||||
let violations = violatingOffsetsForEnum(dictionary: dictionary)
|
||||
return violations.map {
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public struct RequiredDeinitRule: ASTRule, OptInRule, ConfigurationProviderRule,
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -211,7 +211,7 @@ public struct RequiredEnumCaseRule: ASTRule, OptInRule, ConfigurationProviderRul
|
||||
for protocolName: String,
|
||||
missing requiredCase: RequiredCase) -> StyleViolation {
|
||||
return StyleViolation(
|
||||
ruleDescription: type(of: self).description,
|
||||
ruleDescription: Self.description,
|
||||
severity: requiredCase.severity,
|
||||
location: parsed.location,
|
||||
reason: "Enums conforming to \"\(protocolName)\" must have a \"\(requiredCase.name)\" case")
|
||||
|
||||
@@ -33,7 +33,7 @@ public struct StrongIBOutletRule: ConfigurationProviderRule, ASTRule, OptInRule,
|
||||
}
|
||||
|
||||
return [
|
||||
StyleViolation(ruleDescription: type(of: self).description,
|
||||
StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
]
|
||||
|
||||
@@ -35,7 +35,7 @@ public struct TodoRule: ConfigurationProviderRule {
|
||||
)
|
||||
|
||||
private func customMessage(file: SwiftLintFile, range: NSRange) -> String {
|
||||
var reason = type(of: self).description.description
|
||||
var reason = Self.description.description
|
||||
let offset = NSMaxRange(range)
|
||||
|
||||
guard let (lineNumber, _) = file.stringView.lineAndCharacter(forCharacterOffset: offset) else {
|
||||
@@ -78,7 +78,7 @@ public struct TodoRule: ConfigurationProviderRule {
|
||||
}
|
||||
let reason = customMessage(file: file, range: range)
|
||||
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location),
|
||||
reason: reason)
|
||||
|
||||
@@ -55,7 +55,7 @@ public struct UnownedVariableCaptureRule: ASTRule, OptInRule, ConfigurationProvi
|
||||
}.unique
|
||||
|
||||
return unownedVariableOffsets.map { offset in
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public struct UnusedCaptureListRule: ASTRule, ConfigurationProviderRule, Automat
|
||||
let offset = captureListRange.location + location
|
||||
let reason = "Unused reference \(reference) in a capture list should be removed."
|
||||
return StyleViolation(
|
||||
ruleDescription: type(of: self).description,
|
||||
ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: offset),
|
||||
reason: reason
|
||||
|
||||
@@ -102,7 +102,7 @@ public struct UnusedClosureParameterRule: SubstitutionCorrectableASTRule, Config
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
return violationRanges(in: file, dictionary: dictionary, kind: kind).map { range, name in
|
||||
let reason = "Unused parameter \"\(name)\" in a closure should be replaced with _."
|
||||
return StyleViolation(ruleDescription: type(of: self).description,
|
||||
return StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, characterOffset: range.location),
|
||||
reason: reason)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user