Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@

### Bug Fixes

* Treat actors as implicitly inheriting from `Actor` in `missing_docs` when
`excludes_inherited_types` is enabled, avoiding false positives on members
such as `unownedExecutor`.
[leno23](https://github.com/leno23)
[#5422](https://github.com/realm/SwiftLint/issues/5422)

* Detect and autocorrect missing whitespace before `else` in `guard`
statements for the `statement_position` rule.
[theamodhshetty](https://github.com/theamodhshetty)
Expand Down
20 changes: 7 additions & 13 deletions Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private extension MissingDocsRule {
}

override func visit(_ node: ActorDeclSyntax) -> SyntaxVisitorContinueKind {
if node.inherits, configuration.excludesInheritedTypes {
if configuration.excludesInheritedTypes {
_ = super.visit(node)
return .skipChildren
}
Expand Down Expand Up @@ -71,11 +71,9 @@ private extension MissingDocsRule {
}

override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
if node.inherits, configuration.excludesInheritedTypes {
_ = super.visit(node)
return .skipChildren
if !(node.inherits && configuration.excludesInheritedTypes) {
collectViolation(from: node, on: node.enumKeyword)
}
collectViolation(from: node, on: node.enumKeyword)
return super.visit(node)
}

Expand Down Expand Up @@ -103,20 +101,16 @@ private extension MissingDocsRule {
}

override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
if node.inherits, configuration.excludesInheritedTypes {
_ = super.visit(node)
return .skipChildren
if !(node.inherits && configuration.excludesInheritedTypes) {
collectViolation(from: node, on: node.protocolKeyword)
}
collectViolation(from: node, on: node.protocolKeyword)
return super.visit(node)
}

override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
if node.inherits, configuration.excludesInheritedTypes {
_ = super.visit(node)
return .skipChildren
if !(node.inherits && configuration.excludesInheritedTypes) {
collectViolation(from: node, on: node.structKeyword)
}
collectViolation(from: node, on: node.structKeyword)
return super.visit(node)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ struct MissingDocsRuleExamples {
public func f() async {}
#endif
""", excludeFromDocumentation: true),
Example("""
/// My type.
public struct MyType: Identifiable {
public var id: String
}
""", configuration: ["excludes_inherited_types": true]),
Example("""
/// Documentation for MyActor.
public actor MyActor {
public nonisolated var unownedExecutor: Int { 0 }
}
"""),
]

static let triggeringExamples = [
Expand All @@ -90,6 +102,19 @@ struct MissingDocsRuleExamples {
public let b: Int
}
"""),
Example("""
/// My type.
public struct MyType: Identifiable {
public var id: String
public ↓var name: String
}
""", configuration: ["excludes_inherited_types": true]),
Example("""
/// Documentation for MyActor.
public actor MyActor {
public nonisolated ↓var unownedExecutor: Int { 0 }
}
""", configuration: ["excludes_inherited_types": false]),
// Violation marker is on `static` keyword.
Example("""
/// a doc
Expand Down