-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathMissingDocsRuleExamples.swift
More file actions
248 lines (247 loc) · 6.47 KB
/
MissingDocsRuleExamples.swift
File metadata and controls
248 lines (247 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
struct MissingDocsRuleExamples {
static let nonTriggeringExamples = [
// locally-defined superclass member is documented, but subclass member is not
Example("""
/// docs
public class A {
/// docs
public func b() {}
}
// no docs
public class B: A { override public func b() {} }
"""),
// externally-defined superclass member is documented, but subclass member is not
Example("""
import Foundation
// no docs
public class B: NSObject {
// no docs
override public var description: String { fatalError() } }
"""),
Example("""
/// docs
public class A {
var j = 1
var i: Int { 1 }
func f() {}
deinit {}
}
"""),
Example("""
public extension A {}
"""),
Example("""
enum E {
case A
}
"""),
Example("""
/// docs
public class A {
public init() {}
}
""", configuration: ["excludes_trivial_init": true]),
Example("""
class C {
public func f() {}
}
""", configuration: ["evaluate_effective_access_control_level": true]),
Example("""
public struct S: ~Copyable, P {
public init() {}
}
"""),
Example("""
/// my doc
#if os(macOS)
public func f() {}
#else
public func f() async {}
#endif
""", excludeFromDocumentation: true),
Example("""
/// my doc
#if os(macOS)
#if is(iOS)
public func f() {}
#endif
#else
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 = [
// public, undocumented
Example("public ↓func a() {}"),
// public, undocumented
Example("// regular comment\npublic ↓func a() {}"),
// public, undocumented
Example("/* regular comment */\npublic ↓func a() {}"),
// protocol member and inherited member are both undocumented
Example("""
/// docs
public protocol A {
// no docs
↓var b: Int { get }
}
/// docs
public struct C: A {
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
public class C {
public static ↓let i = 1
}
"""),
// `excludes_extensions` only excludes the extension declaration itself; not its children.
Example("""
public extension A {
public ↓func f() {}
static ↓var i: Int { 1 }
↓struct S {
func f() {}
}
↓class C {
func f() {}
}
↓actor A {
func f() {}
}
↓enum E {
↓case a
func f() {}
}
}
"""),
Example("""
public extension A {
↓enum E {
enum Inner {
case a
}
}
}
"""),
Example("""
extension E {
public ↓struct S {
public static ↓let i = 1
}
}
"""),
Example("""
extension E {
public ↓func f() {}
}
"""),
Example("""
/// docs
public class A {
public ↓init(argument: String) {}
}
""", configuration: ["excludes_trivial_init": true]),
Example("""
public ↓struct C: A {
public ↓let b: Int
}
""", configuration: ["excludes_inherited_types": false]),
Example("""
public ↓extension A {
public ↓func f() {}
}
""", configuration: ["excludes_extensions": false]),
Example("""
public extension E {
↓var i: Int {
let j = 1
func f() {}
return j
}
}
"""),
Example("""
#if os(macOS)
public ↓func f() {}
#endif
"""),
Example("""
public ↓enum E {
↓case A, B
func f() {}
init(_ i: Int) { self = .A }
}
"""),
Example("""
open ↓class C {
public ↓enum E {
↓case A
func f() {}
init(_ i: Int) { self = .A }
}
}
""", excludeFromDocumentation: true),
/// Nested types inherit the ACL from the declaring extension.
Example("""
/// a doc
public struct S {}
public extension S {
↓enum E {
↓case A
}
}
"""),
Example("""
public extension URL {
fileprivate enum E {
static let source = ""
}
static ↓var a: Int { 1 }
}
""", excludeFromDocumentation: true),
Example("""
class C {
public ↓func f() {}
}
""", configuration: ["evaluate_effective_access_control_level": false]),
Example("""
public ↓struct S: ~Copyable, ~Escapable {
public ↓init() {}
}
"""),
Example("""
/// my doc
#if os(macOS)
public func f() {}
public ↓func g() {}
#endif
""", excludeFromDocumentation: true),
]
}