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

Speedup computed accessors order rule #3727

Merged
merged 1 commit into from
Oct 1, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#3724](https://github.com/realm/SwiftLint/issues/3724)

* Speed up Computed Accessors Order rule.
[PaulTaykalo](https://github.com/PaulTaykalo)
[#3727](https://github.com/realm/SwiftLint/issues/3727)

## 0.44.0: Travel Size Lint Roller

#### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct ComputedAccessorsOrderRule: ConfigurationProviderRule {
file: SwiftLintFile,
range: NSRange? = nil) -> [SwiftLintSyntaxToken] {
let pattern = "\\b\(keyword)\\b"
return file.rangesAndTokens(matching: pattern).compactMap { _, tokens in
return file.rangesAndTokens(matching: pattern, range: range).compactMap { _, tokens in
guard tokens.count == 1,
let token = tokens.last,
token.kind == .keyword else {
Expand All @@ -101,7 +101,9 @@ private extension ComputedAccessorsOrderRule {
let allowedKinds = SwiftDeclarationKind.variableKinds.subtracting([.varParameter])
.union([.functionSubscript])

func parse(dictionary: SourceKittenDictionary, parentKind: SwiftDeclarationKind?) {
func parse(dictionary: SourceKittenDictionary,
parentKind: SwiftDeclarationKind?,
into results: inout [SourceKittenDictionary]) {
// Only accepts declarations which contains a body and contains the
// searched byteOffset
guard let kind = dictionary.declarationKind,
Expand All @@ -116,13 +118,13 @@ private extension ComputedAccessorsOrderRule {
}

for dictionary in dictionary.substructure {
parse(dictionary: dictionary, parentKind: kind)
parse(dictionary: dictionary, parentKind: kind, into: &results)
}
}

let dict = structureDictionary
for dictionary in dict.substructure {
parse(dictionary: dictionary, parentKind: nil)
parse(dictionary: dictionary, parentKind: nil, into: &results)
}

return results
Expand Down