Skip to content

Commit 8641f5b

Browse files
committed
add swiflint configuration and fix lint error
1 parent 33d7bfa commit 8641f5b

9 files changed

+141
-16
lines changed

.swiftlint.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
excluded:
2+
- ${PWD}/DerivedData
3+
- ${PWD}/.build
4+
- Tests
5+
- Demo.swiftpm
6+
7+
disabled_rules:
8+
- discarded_notification_center_observer
9+
- notification_center_detachment
10+
- orphaned_doc_comment
11+
- todo
12+
- unused_capture_list
13+
- opening_brace
14+
- trailing_comma
15+
16+
analyzer_rules:
17+
- unused_import
18+
19+
opt_in_rules:
20+
- array_init
21+
- attributes
22+
- closure_end_indentation
23+
- closure_spacing
24+
- collection_alignment
25+
- colon # promote to error
26+
- convenience_type
27+
- discouraged_object_literal
28+
- empty_collection_literal
29+
- empty_count
30+
- empty_string
31+
- enum_case_associated_values_count
32+
- fatal_error_message
33+
- first_where
34+
- force_unwrapping
35+
- implicitly_unwrapped_optional
36+
- indentation_width
37+
- last_where
38+
- legacy_random
39+
- literal_expression_end_indentation
40+
- multiline_arguments
41+
- multiline_function_chains
42+
- multiline_literal_brackets
43+
- multiline_parameters
44+
- multiline_parameters_brackets
45+
- operator_usage_whitespace
46+
- overridden_super_call
47+
- pattern_matching_keywords
48+
- prefer_self_type_over_type_of_self
49+
- redundant_nil_coalescing
50+
- redundant_type_annotation
51+
- strict_fileprivate
52+
- toggle_bool
53+
- trailing_closure
54+
- unneeded_parentheses_in_closure_argument
55+
- vertical_whitespace_closing_braces
56+
- vertical_whitespace_opening_braces
57+
- yoda_condition
58+
59+
60+
custom_rules:
61+
array_constructor:
62+
name: "Array/Dictionary initializer"
63+
regex: '[let,var] .+ = (\[.+\]\(\))'
64+
capture_group: 1
65+
message: "Use explicit type annotation when initializing empty arrays and dictionaries"
66+
severity: warning
67+
68+
69+
attributes:
70+
always_on_same_line:
71+
- "@IBSegueAction"
72+
- "@IBAction"
73+
- "@NSManaged"
74+
- "@objc"
75+
76+
force_cast: warning
77+
force_try: warning
78+
function_body_length:
79+
warning: 60
80+
81+
legacy_hashing: error
82+
83+
identifier_name:
84+
excluded:
85+
- i
86+
- id
87+
- x
88+
- y
89+
- z
90+
91+
indentation_width:
92+
indentation_width: 4
93+
94+
line_length:
95+
warning: 150
96+
ignores_urls: true
97+
ignores_function_declarations: true
98+
ignores_comments: true
99+
100+
multiline_arguments:
101+
first_argument_location: next_line
102+
only_enforce_after_first_closure_on_first_line: true
103+
104+
private_over_fileprivate:
105+
validate_extensions: true
106+
107+
trailing_whitespace:
108+
ignores_empty_lines: false
109+
ignores_comments: true
110+
111+
vertical_whitespace:
112+
max_empty_lines: 2

Mintfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Sources/FirebaseRemoteConfigOpenFeatureProvider/Extensions/Array+Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
import OpenFeature
1010

1111
extension Array where Element == Any {
12+
// swiftlint:disable:next cyclomatic_complexity
1213
func wrapInValue() throws -> [Value] {
1314
try self.map { value in
1415
switch TypeDetector.detectType(from: value) {

Sources/FirebaseRemoteConfigOpenFeatureProvider/Extensions/Dictionary+Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
import OpenFeature
1010

1111
extension Dictionary<String, Any> {
12+
// swiftlint:disable:next cyclomatic_complexity
1213
func wrapInValue() throws -> [String: OpenFeature.Value] {
1314
try self.mapValues { value in
1415
switch TypeDetector.detectType(from: value) {

Sources/FirebaseRemoteConfigOpenFeatureProvider/Extensions/RemoteConfigValueCompatible+Extensions.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ extension RemoteConfigValueCompatible {
4040
throw OpenFeatureError.parseError(message: "指定されたキーから取得した文字列を日付に変換することができない")
4141
}
4242

43-
return .init(value: date, variant: FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.string(from: date), reason: source.reason.rawValue)
43+
return .init(
44+
value: date,
45+
variant: FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.string(from: date),
46+
reason: source.reason.rawValue
47+
)
4448
}
4549
}
4650

@@ -86,10 +90,12 @@ extension RemoteConfigValueCompatible {
8690
case (_, let .some(dictionary), _):
8791
value = .structure(try dictionary.wrapInValue())
8892
case (_, _, let .some(unwrappedString)):
89-
switch (FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: unwrappedString),
90-
Int64(unwrappedString),
91-
Double(unwrappedString),
92-
Bool(unwrappedString)) {
93+
switch (
94+
FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: unwrappedString),
95+
Int64(unwrappedString),
96+
Double(unwrappedString),
97+
Bool(unwrappedString)
98+
) {
9399
case (let .some(date), _, _, _):
94100
value = .date(date)
95101
case (_, let .some(int), _, _):

Sources/FirebaseRemoteConfigOpenFeatureProvider/FirebaseRemoteConfigOpenFeatureProvider.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import OpenFeature
55
import FirebaseRemoteConfig
66
import FirebaseCore
77

8-
public let firebaseRemoteConfigOpenFeatureProviderStaleTimeIntervalKey = "firebaseRemoteConfigOpenFeatureProviderStaleTimeIntervalKey"
8+
// swiftlint:disable:next identifier_name
99
public let firebaseRemoteConfigOpenFeatureProviderOldContextKey = "firebaseRemoteConfigOpenFeatureProviderOldContextKey"
10+
// swiftlint:disable:next identifier_name
1011
public let firebaseRemoteConfigOpenFeatureProviderNewContextKey = "firebaseRemoteConfigOpenFeatureProviderNewContextKey"
1112

1213
public final class FirebaseRemoteConfigOpenFeatureProvider: FeatureProvider {
@@ -25,7 +26,7 @@ public final class FirebaseRemoteConfigOpenFeatureProvider: FeatureProvider {
2526

2627
return dateFormatter
2728
}()
28-
29+
2930
/// Provider status
3031
public private(set) var status: FirebaseRemoteConfigOpenFeatureProviderStatus = .notReady {
3132
didSet {
@@ -39,7 +40,7 @@ public final class FirebaseRemoteConfigOpenFeatureProvider: FeatureProvider {
3940
}
4041
}
4142
}
42-
43+
4344
/// Provider initializer
4445
///
4546
/// This initilizer updates provider status belong with remote config instance. Also it starts observing notification for remoteConfig update.
@@ -49,19 +50,19 @@ public final class FirebaseRemoteConfigOpenFeatureProvider: FeatureProvider {
4950
updateStatus(for: remoteConfig)
5051
NotificationCenter.default.addObserver(self, selector: #selector(remoteConfigDidActivated), name: .onRemoteConfigActivated, object: nil)
5152
}
52-
53+
5354
deinit {
5455
NotificationCenter.default.removeObserver(self, name: .onRemoteConfigActivated, object: nil)
5556
}
56-
57+
5758
/// Provider initializer
5859
///
5960
/// This provider does not support context
6061
/// - Parameter initialContext: initial context
6162
public func initialize(initialContext: EvaluationContext?) {
6263
updateStatus(for: remoteConfig)
6364
}
64-
65+
6566
/// Update contexts for the provider
6667
///
6768
/// This function notifies `.configurationChanged`event
@@ -168,12 +169,13 @@ extension FirebaseRemoteConfigOpenFeatureProvider {
168169
// Make sure this key is consistent with kFIRGoogleAppIDKey in FirebaseCore SDK
169170
// see also https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseRemoteConfig/Swift/PropertyWrapper/RemoteConfigValueObservable.swift
170171
let firebaseRemoteConfigAppNameKey = "FIRAppNameKey"
171-
172-
guard let appName = notification.userInfo?[firebaseRemoteConfigAppNameKey] as? String,
173-
FirebaseApp.app()?.name == appName else {
172+
173+
guard
174+
let appName = notification.userInfo?[firebaseRemoteConfigAppNameKey] as? String,
175+
FirebaseApp.app()?.name == appName else {
174176
return
175177
}
176-
178+
177179
if status != .ready {
178180
status = .ready
179181
}

Sources/FirebaseRemoteConfigOpenFeatureProvider/FirebaseRemoteConfigOpenFeatureProviderMetadata.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import OpenFeature
33

4+
// swiftlint:disable:next type_name
45
public struct FirebaseRemoteConfigOpenFeatureProviderMetadata: ProviderMetadata {
56
public var name: String? {
67
return "FirebaseRemoteConfigOpenFeatureProvider"

Sources/FirebaseRemoteConfigOpenFeatureProvider/FirebaseRemoteConfigOpenFeatureProviderStatus.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
/// Status of provider
1111
///
1212
/// Note: This provider and RemoteConfig does not support `STALED` status.
13+
// swiftlint:disable:next type_name
1314
public enum FirebaseRemoteConfigOpenFeatureProviderStatus: String {
1415
case notReady = "NOT_READY"
1516
case ready = "READY"

Sources/FirebaseRemoteConfigOpenFeatureProvider/Utils/TypeDetector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum TypeDetector {
2020
case unknown
2121
}
2222

23+
// swiftlint:disable:next cyclomatic_complexity
2324
static func detectType(from object: Any) -> DetectedType {
2425
switch CFGetTypeID(object as CFTypeRef) {
2526
case CFBooleanGetTypeID():
@@ -59,4 +60,3 @@ enum TypeDetector {
5960
}
6061
}
6162
}
62-

0 commit comments

Comments
 (0)