Use SourceKit to validate associatedtype and typealias in type_name rule when linting with Swift 4.1

Part of #2021
This commit is contained in:
Marcelo Fabri
2018-01-26 22:08:59 -08:00
parent a278239277
commit 4c8df19c84
3 changed files with 10 additions and 0 deletions
+5
View File
@@ -36,6 +36,11 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#2021](https://github.com/realm/SwiftLint/issues/2021)
* Use SourceKit to validate `associatedtype` and `typealias` in `type_name` rule
when linting with Swift 4.1.
[Marcelo Fabri](https://github.com/marcelofabri)
[#2021](https://github.com/realm/SwiftLint/issues/2021)
## 0.24.2: Dented Tumbler
#### Breaking
@@ -39,6 +39,7 @@ extension SwiftDeclarationKind {
.`class`,
.`struct`,
.`typealias`,
.`associatedtype`,
.`enum`
]
@@ -48,6 +48,10 @@ public struct TypeNameRule: ASTRule, ConfigurationProviderRule {
}
private func validateTypeAliasesAndAssociatedTypes(in file: File) -> [StyleViolation] {
guard SwiftVersion.current < .fourDotOne else {
return []
}
let rangesAndTokens = file.rangesAndTokens(matching: "(typealias|associatedtype)\\s+.+?\\b")
return rangesAndTokens.flatMap { _, tokens -> [StyleViolation] in
guard tokens.count == 2,