Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension SwiftDeclarationKind {
.`class`,
.`struct`,
.`typealias`,
.`associatedtype`,
.`enum`
]

Expand Down
4 changes: 4 additions & 0 deletions Source/SwiftLintFramework/Rules/TypeNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down