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

Commit 7bdcbc5

Browse files
authored
Omit initializer expression if closure or function call to ensure sonable declaration code blocks (#150)
* Omit initializer expression if closure or function call to ensure reasonable declaration code blocks. Resolves #138 * Add changelog entry for #150
1 parent 2f79e97 commit 7bdcbc5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
#130 by @mattt.
3434
- Fixed file and directory unexpected permissions.
3535
#146 by @niw.
36+
- Fixed declarations for properties without explicit type annotations.
37+
#150 by @mattt.
3638

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

Sources/SwiftDoc/SourceFile.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public struct SourceFile: Hashable, Codable {
5858
func symbol<Node: SyntaxProtocol>(_ node: Node, api: API) -> Symbol? {
5959
guard let documentation = try? Documentation.parse(node.documentation) else { return nil }
6060
let sourceLocation = sourceLocationConverter.location(for: node.position)
61-
6261
return Symbol(api: api, context: context, declaration: "\(api)", documentation: documentation, sourceLocation: sourceLocation)
6362
}
6463

@@ -184,8 +183,16 @@ public struct SourceFile: Hashable, Codable {
184183
}
185184

186185
override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind {
187-
let variables = node.bindings.compactMap { binding in
188-
Variable(binding.withInitializer(nil))
186+
let variables = node.bindings.compactMap { binding -> Variable? in
187+
// Omit initializer expression if closure or function call
188+
// to ensure reasonable declaration code blocks.
189+
if let value = binding.initializer?.value,
190+
value.is(ClosureExprSyntax.self) || value.is(FunctionCallExprSyntax.self)
191+
{
192+
return Variable(binding.withInitializer(nil))
193+
} else {
194+
return Variable(binding)
195+
}
189196
}
190197

191198
for variable in variables {

0 commit comments

Comments
 (0)