forked from realm/SwiftLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscouragedOptionalBooleanRuleExamples.swift
More file actions
178 lines (147 loc) · 7.4 KB
/
DiscouragedOptionalBooleanRuleExamples.swift
File metadata and controls
178 lines (147 loc) · 7.4 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
//
// DiscouragedOptionalBooleanExamples.swift
// SwiftLint
//
// Created by Ornithologist Coder on 1/21/18.
// Copyright © 2018 Realm. All rights reserved.
//
import Foundation
internal struct DiscouragedOptionalBooleanRuleExamples {
static let nonTriggeringExamples = [
// Global variable
"var foo: Bool",
"var foo: [String: Bool]",
"var foo: [Bool]",
"let foo: Bool = true",
"let foo: Bool = false",
"let foo: [String: Bool] = [:]",
"let foo: [Bool] = []",
// Computed get variable
"var foo: Bool { return true }",
"let foo: Bool { return false }()",
// Free function return
"func foo() -> Bool {}",
"func foo() -> [String: Bool] {}",
"func foo() -> ([Bool]) -> String {}",
// Free function parameter
"func foo(input: Bool = true) {}",
"func foo(input: [String: Bool] = [:]) {}",
"func foo(input: [Bool] = []) {}",
// Method return
wrapExample("class", "func foo() -> Bool {}"),
wrapExample("class", "func foo() -> [String: Bool] {}"),
wrapExample("class", "func foo() -> ([Bool]) -> String {}"),
wrapExample("struct", "func foo() -> Bool {}"),
wrapExample("struct", "func foo() -> [String: Bool] {}"),
wrapExample("struct", "func foo() -> ([Bool]) -> String {}"),
wrapExample("enum", "func foo() -> Bool {}"),
wrapExample("enum", "func foo() -> [String: Bool] {}"),
wrapExample("enum", "func foo() -> ([Bool]) -> String {}"),
// Method parameter
wrapExample("class", "func foo(input: Bool = true) {}"),
wrapExample("class", "func foo(input: [String: Bool] = [:]) {}"),
wrapExample("class", "func foo(input: [Bool] = []) {}"),
wrapExample("struct", "func foo(input: Bool = true) {}"),
wrapExample("struct", "func foo(input: [String: Bool] = [:]) {}"),
wrapExample("struct", "func foo(input: [Bool] = []) {}"),
wrapExample("enum", "func foo(input: Bool = true) {}"),
wrapExample("enum", "func foo(input: [String: Bool] = [:]) {}"),
wrapExample("enum", "func foo(input: [Bool] = []) {}")
]
static let triggeringExamples = [
// Global variable
"var foo: ↓Bool?",
"var foo: [String: ↓Bool?]",
"var foo: [↓Bool?]",
"let foo: ↓Bool? = nil",
"let foo: [String: ↓Bool?] = [:]",
"let foo: [↓Bool?] = []",
"let foo = ↓Optional.some(false)",
"let foo = ↓Optional.some(true)",
// Computed Get Variable
"var foo: ↓Bool? { return nil }",
"let foo: ↓Bool? { return nil }()",
// Free function return
"func foo() -> ↓Bool? {}",
"func foo() -> [String: ↓Bool?] {}",
"func foo() -> [↓Bool?] {}",
"static func foo() -> ↓Bool? {}",
"static func foo() -> [String: ↓Bool?] {}",
"static func foo() -> [↓Bool?] {}",
"func foo() -> (↓Bool?) -> String {}",
"func foo() -> ([Int]) -> ↓Bool? {}",
// Free function parameter
"func foo(input: ↓Bool?) {}",
"func foo(input: [String: ↓Bool?]) {}",
"func foo(input: [↓Bool?]) {}",
"static func foo(input: ↓Bool?) {}",
"static func foo(input: [String: ↓Bool?]) {}",
"static func foo(input: [↓Bool?]) {}",
// Instance variable
wrapExample("class", "var foo: ↓Bool?"),
wrapExample("class", "var foo: [String: ↓Bool?]"),
wrapExample("class", "let foo: ↓Bool? = nil"),
wrapExample("class", "let foo: [String: ↓Bool?] = [:]"),
wrapExample("class", "let foo: [↓Bool?] = []"),
wrapExample("struct", "var foo: ↓Bool?"),
wrapExample("struct", "var foo: [String: ↓Bool?]"),
wrapExample("struct", "let foo: ↓Bool? = nil"),
wrapExample("struct", "let foo: [String: ↓Bool?] = [:]"),
wrapExample("struct", "let foo: [↓Bool?] = []"),
// Instance computed variable
wrapExample("class", "var foo: ↓Bool? { return nil }"),
wrapExample("class", "let foo: ↓Bool? { return nil }()"),
wrapExample("struct", "var foo: ↓Bool? { return nil }"),
wrapExample("struct", "let foo: ↓Bool? { return nil }()"),
wrapExample("enum", "var foo: ↓Bool? { return nil }"),
wrapExample("enum", "let foo: ↓Bool? { return nil }()"),
// Method return
wrapExample("class", "func foo() -> ↓Bool? {}"),
wrapExample("class", "func foo() -> [String: ↓Bool?] {}"),
wrapExample("class", "func foo() -> [↓Bool?] {}"),
wrapExample("class", "static func foo() -> ↓Bool? {}"),
wrapExample("class", "static func foo() -> [String: ↓Bool?] {}"),
wrapExample("class", "static func foo() -> [↓Bool?] {}"),
wrapExample("class", "func foo() -> (↓Bool?) -> String {}"),
wrapExample("class", "func foo() -> ([Int]) -> ↓Bool? {}"),
wrapExample("struct", "func foo() -> ↓Bool? {}"),
wrapExample("struct", "func foo() -> [String: ↓Bool?] {}"),
wrapExample("struct", "func foo() -> [↓Bool?] {}"),
wrapExample("struct", "static func foo() -> ↓Bool? {}"),
wrapExample("struct", "static func foo() -> [String: ↓Bool?] {}"),
wrapExample("struct", "static func foo() -> [↓Bool?] {}"),
wrapExample("struct", "func foo() -> (↓Bool?) -> String {}"),
wrapExample("struct", "func foo() -> ([Int]) -> ↓Bool? {}"),
wrapExample("enum", "func foo() -> ↓Bool? {}"),
wrapExample("enum", "func foo() -> [String: ↓Bool?] {}"),
wrapExample("enum", "func foo() -> [↓Bool?] {}"),
wrapExample("enum", "static func foo() -> ↓Bool? {}"),
wrapExample("enum", "static func foo() -> [String: ↓Bool?] {}"),
wrapExample("enum", "static func foo() -> [↓Bool?] {}"),
wrapExample("enum", "func foo() -> (↓Bool?) -> String {}"),
wrapExample("enum", "func foo() -> ([Int]) -> ↓Bool? {}"),
// Method parameter
wrapExample("class", "func foo(input: ↓Bool?) {}"),
wrapExample("class", "func foo(input: [String: ↓Bool?]) {}"),
wrapExample("class", "func foo(input: [↓Bool?]) {}"),
wrapExample("class", "static func foo(input: ↓Bool?) {}"),
wrapExample("class", "static func foo(input: [String: ↓Bool?]) {}"),
wrapExample("class", "static func foo(input: [↓Bool?]) {}"),
wrapExample("struct", "func foo(input: ↓Bool?) {}"),
wrapExample("struct", "func foo(input: [String: ↓Bool?]) {}"),
wrapExample("struct", "func foo(input: [↓Bool?]) {}"),
wrapExample("struct", "static func foo(input: ↓Bool?) {}"),
wrapExample("struct", "static func foo(input: [String: ↓Bool?]) {}"),
wrapExample("struct", "static func foo(input: [↓Bool?]) {}"),
wrapExample("enum", "func foo(input: ↓Bool?) {}"),
wrapExample("enum", "func foo(input: [String: ↓Bool?]) {}"),
wrapExample("enum", "func foo(input: [↓Bool?]) {}"),
wrapExample("enum", "static func foo(input: ↓Bool?) {}"),
wrapExample("enum", "static func foo(input: [String: ↓Bool?]) {}"),
wrapExample("enum", "static func foo(input: [↓Bool?]) {}")
]
}
// MARK: - Private
private func wrapExample(_ type: String, _ test: String) -> String {
return "\(type) Foo {\n\t\(test)\n}"
}