diff --git a/CHANGELOG.md b/CHANGELOG.md index be786e3de4..08fcc8b8f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRule.swift index 6a5fb6765f..0f22e4479b 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRule.swift @@ -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 } @@ -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) } @@ -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) } diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRuleExamples.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRuleExamples.swift index 0fd4ada975..170ddd4050 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRuleExamples.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/MissingDocsRuleExamples.swift @@ -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 = [ @@ -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