Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Omit initializer expression if closure or function call to ensure sonable declaration code blocks #150

Merged
merged 2 commits into from
Jul 31, 2020
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
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#130 by @mattt.
- Fixed file and directory unexpected permissions.
#146 by @niw.
- Fixed declarations for properties without explicit type annotations.
#150 by @mattt.

## [1.0.0-beta.3] - 2020-05-19

Expand Down
13 changes: 10 additions & 3 deletions Sources/SwiftDoc/SourceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public struct SourceFile: Hashable, Codable {
func symbol<Node: SyntaxProtocol>(_ node: Node, api: API) -> Symbol? {
guard let documentation = try? Documentation.parse(node.documentation) else { return nil }
let sourceLocation = sourceLocationConverter.location(for: node.position)

return Symbol(api: api, context: context, declaration: "\(api)", documentation: documentation, sourceLocation: sourceLocation)
}

Expand Down Expand Up @@ -184,8 +183,16 @@ public struct SourceFile: Hashable, Codable {
}

override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind {
let variables = node.bindings.compactMap { binding in
Variable(binding.withInitializer(nil))
let variables = node.bindings.compactMap { binding -> Variable? in
// Omit initializer expression if closure or function call
// to ensure reasonable declaration code blocks.
if let value = binding.initializer?.value,
value.is(ClosureExprSyntax.self) || value.is(FunctionCallExprSyntax.self)
{
return Variable(binding.withInitializer(nil))
} else {
return Variable(binding)
}
}

for variable in variables {
Expand Down