Skip to content

Commit b92c42b

Browse files
authored
fix: setup swift-lint (#361)
1 parent 9bb07bb commit b92c42b

13 files changed

+193
-109
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ jobs:
2727
- name: Typecheck files
2828
run: yarn typecheck
2929

30+
swift-lint:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout Repository
34+
uses: actions/checkout@v2
35+
- name: SwiftLint
36+
uses: norio-nomura/action-swiftlint@3.2.1
37+
env:
38+
WORKING_DIRECTORY: Source
39+
3040
build-library:
3141
runs-on: ubuntu-latest
3242
steps:
@@ -94,7 +104,7 @@ jobs:
94104
95105
- name: Build example for Android
96106
env:
97-
JAVA_OPTS: "-XX:MaxHeapSize=6g"
107+
JAVA_OPTS: '-XX:MaxHeapSize=6g'
98108
run: |
99109
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
100110
@@ -153,7 +163,7 @@ jobs:
153163
154164
- name: Build example for Android new arch
155165
env:
156-
JAVA_OPTS: "-XX:MaxHeapSize=6g"
166+
JAVA_OPTS: '-XX:MaxHeapSize=6g'
157167
run: |
158168
yarn turbo run build:android:fabric --cache-dir="${{ env.TURBO_CACHE_DIR }}"
159169
@@ -200,7 +210,6 @@ jobs:
200210
run: |
201211
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
202212
203-
204213
build-ios-newarch:
205214
runs-on: macos-15
206215
env:

.swiftlint.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
opt_in_rules:
2+
- anonymous_argument_in_multiline_closure
3+
- array_init
4+
- closure_end_indentation
5+
- closure_spacing
6+
- collection_alignment
7+
- comma_inheritance
8+
- contains_over_filter_count
9+
- contains_over_filter_is_empty
10+
- contains_over_first_not_nil
11+
- contains_over_range_nil_comparison
12+
- convenience_type
13+
- direct_return
14+
- discarded_notification_center_observer
15+
- discouraged_none_name
16+
- discouraged_object_literal
17+
- empty_collection_literal
18+
- empty_count
19+
- empty_string
20+
- enum_case_associated_values_count
21+
- expiring_todo
22+
- explicit_init
23+
- fallthrough
24+
- fatal_error_message
25+
- file_name_no_space
26+
- first_where
27+
- flatmap_over_map_reduce
28+
# - force_unwrapping # nice to have
29+
- identical_operands
30+
- implicit_return
31+
# - implicitly_unwrapped_optional # nice to have
32+
- joined_default_parameter
33+
- last_where
34+
- legacy_multiple
35+
- legacy_objc_type
36+
- literal_expression_end_indentation
37+
- local_doc_comment
38+
- modifier_order
39+
- multiline_arguments
40+
- multiline_arguments_brackets
41+
- multiline_function_chains
42+
- multiline_literal_brackets
43+
- multiline_parameters
44+
- multiline_parameters_brackets
45+
# - no_magic_numbers # nice to have
46+
- nslocalizedstring_key
47+
- number_separator
48+
- operator_usage_whitespace
49+
- optional_enum_case_matching
50+
- overridden_super_call
51+
- prefer_self_type_over_type_of_self
52+
- reduce_into
53+
- redundant_nil_coalescing
54+
- redundant_self_in_closure
55+
- redundant_type_annotation
56+
- return_value_from_void_function
57+
- self_binding
58+
- shorthand_optional_binding
59+
- sorted_first_last
60+
- sorted_imports
61+
- strict_fileprivate
62+
- superfluous_else
63+
- switch_case_on_newline
64+
- toggle_bool
65+
- trailing_closure
66+
- unavailable_function
67+
- unhandled_throwing_task
68+
- unneeded_parentheses_in_closure_argument
69+
- unowned_variable_capture
70+
- untyped_error_in_catch
71+
- vertical_parameter_alignment_on_call
72+
- vertical_whitespace_closing_braces
73+
- vertical_whitespace_opening_braces
74+
- weak_delegate
75+
- yoda_condition
76+
77+
disabled_rules:
78+
- nesting
79+
80+
identifier_name:
81+
excluded: # excluded via string array
82+
- id
83+
- ID

packages/react-native-bottom-tabs/ios/Events/OnNativeLayoutEvent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class OnNativeLayoutEvent: NSObject, RCTEvent {
66
public var viewTag: NSNumber
77

88
public var eventName: String {
9-
return "onNativeLayout"
9+
"onNativeLayout"
1010
}
1111

1212
public init(reactTag: NSNumber, size: CGSize) {
@@ -16,15 +16,15 @@ public class OnNativeLayoutEvent: NSObject, RCTEvent {
1616
}
1717

1818
public class func moduleDotMethod() -> String {
19-
return "RCTEventEmitter.receiveEvent"
19+
"RCTEventEmitter.receiveEvent"
2020
}
21-
21+
2222
public func canCoalesce() -> Bool {
23-
return false
23+
false
2424
}
2525

2626
public func arguments() -> [Any] {
27-
return [
27+
[
2828
viewTag,
2929
RCTNormalizeInputEventName(eventName) ?? eventName,
3030
[

packages/react-native-bottom-tabs/ios/Events/PageSelectedEvent.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ import React
44
public class PageSelectedEvent: NSObject, RCTEvent {
55
private var key: NSString
66
public var viewTag: NSNumber
7-
7+
88
public var eventName: String {
9-
return "onPageSelected"
9+
"onPageSelected"
1010
}
11-
11+
1212
public init(reactTag: NSNumber, key: NSString) {
1313
self.viewTag = reactTag
1414
self.key = key
1515
super.init()
1616
}
17-
17+
1818
public class func moduleDotMethod() -> String {
19-
return "RCTEventEmitter.receiveEvent"
19+
"RCTEventEmitter.receiveEvent"
2020
}
21-
21+
2222
public func canCoalesce() -> Bool {
23-
return false
23+
false
2424
}
25-
25+
2626
public func arguments() -> [Any] {
27-
return [
27+
[
2828
viewTag,
2929
RCTNormalizeInputEventName(eventName) ?? eventName,
3030
[

packages/react-native-bottom-tabs/ios/Events/TabBarMeasuredEvent.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ import React
44
public class TabBarMeasuredEvent: NSObject, RCTEvent {
55
private var height: NSInteger
66
public var viewTag: NSNumber
7-
7+
88
public var eventName: String {
9-
return "onTabBarMeasured"
9+
"onTabBarMeasured"
1010
}
11-
11+
1212
public init(reactTag: NSNumber, height: NSInteger) {
1313
self.viewTag = reactTag
1414
self.height = height
1515
super.init()
1616
}
17-
17+
1818
public class func moduleDotMethod() -> String {
19-
return "RCTEventEmitter.receiveEvent"
19+
"RCTEventEmitter.receiveEvent"
2020
}
21-
21+
2222
public func canCoalesce() -> Bool {
23-
return false
23+
false
2424
}
25-
25+
2626
public func arguments() -> [Any] {
27-
return [
27+
[
2828
viewTag,
2929
RCTNormalizeInputEventName(eventName) ?? eventName,
3030
[

packages/react-native-bottom-tabs/ios/Events/TabLongPressedEvent.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
import React
22

3-
43
// RCTEvent is not defined for new arch.
54
protocol RCTEvent {}
65

76
@objcMembers
87
public class TabLongPressEvent: NSObject, RCTEvent {
98
private var key: NSString
109
public var viewTag: NSNumber
11-
10+
1211
public var eventName: String {
13-
return "onTabLongPress"
12+
"onTabLongPress"
1413
}
15-
14+
1615
public init(reactTag: NSNumber, key: NSString) {
1716
self.viewTag = reactTag
1817
self.key = key
1918
super.init()
2019
}
21-
20+
2221
public class func moduleDotMethod() -> String {
23-
return "RCTEventEmitter.receiveEvent"
22+
"RCTEventEmitter.receiveEvent"
2423
}
25-
24+
2625
public func canCoalesce() -> Bool {
27-
return false
26+
false
2827
}
29-
28+
3029
public func arguments() -> [Any] {
31-
return [
30+
[
3231
viewTag,
3332
RCTNormalizeInputEventName(eventName) ?? eventName,
3433
[

packages/react-native-bottom-tabs/ios/Extensions.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import UIKit
1111
extension Collection {
1212
// Returns the element at the specified index if it is within bounds, otherwise nil.
1313
subscript(safe index: Index) -> Element? {
14-
return indices.contains(index) ? self[index] : nil
14+
indices.contains(index) ? self[index] : nil
1515
}
1616
}
1717

1818
extension Collection where Element == TabInfo {
1919
func findByKey(_ key: String?) -> Element? {
2020
guard let key else { return nil }
2121
guard !isEmpty else { return nil }
22-
return first(where: { $0.key == key })
22+
return first { $0.key == key }
2323
}
2424
}
2525

@@ -37,25 +37,23 @@ extension PlatformView {
3737
extension PlatformImage {
3838
func resizeImageTo(size: CGSize) -> PlatformImage? {
3939
#if os(macOS)
40-
let newImage = NSImage(size: size, flipped: false) { (rect) -> Bool in
40+
return NSImage(size: size, flipped: false) { rect -> Bool in
4141
self.draw(in: rect,
4242
from: CGRect(origin: .zero, size: self.size),
4343
operation: .copy,
4444
fraction: 1.0)
4545
return true
4646
}
47-
return newImage
4847
#else
4948
let renderer = UIGraphicsImageRenderer(size: size)
50-
return renderer.image { context in
49+
return renderer.image { _ in
5150
self.draw(in: CGRect(origin: .zero, size: size))
5251
}
5352
#endif
5453
}
5554
}
5655

5756
extension View {
58-
5957
#if os(macOS)
6058
@MainActor
6159
@ViewBuilder
@@ -82,13 +80,12 @@ extension View {
8280
#endif
8381
}
8482
#endif
85-
86-
83+
8784
@MainActor
8885
@ViewBuilder
8986
func measureView(onLayout: @escaping (_ size: CGSize) -> Void) -> some View {
9087
self
91-
.background (
88+
.background(
9289
GeometryReader { geometry in
9390
Color.clear
9491
.onChange(of: geometry.size) { newValue in

packages/react-native-bottom-tabs/ios/RepresentableView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import SwiftUI
55
*/
66
struct RepresentableView: PlatformViewRepresentable {
77
var view: PlatformView
8-
8+
99
#if os(macOS)
10-
10+
1111
func makeNSView(context: Context) -> PlatformView {
12-
return view
12+
view
1313
}
14-
14+
1515
func updateNSView(_ nsView: PlatformView, context: Context) {}
16-
16+
1717
#else
18-
18+
1919
func makeUIView(context: Context) -> PlatformView {
20-
return view
20+
view
2121
}
22-
22+
2323
func updateUIView(_ uiView: PlatformView, context: Context) {}
24-
24+
2525
#endif
2626
}

packages/react-native-bottom-tabs/ios/TabItem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct TabItem: View {
55
var icon: PlatformImage?
66
var sfSymbol: String?
77
var labeled: Bool?
8-
8+
99
var body: some View {
1010
if let icon {
1111
#if os(macOS)
@@ -17,7 +17,7 @@ struct TabItem: View {
1717
Image(systemName: sfSymbol)
1818
.noneSymbolVariant()
1919
}
20-
if (labeled != false) {
20+
if labeled != false {
2121
Text(title ?? "")
2222
}
2323
}

0 commit comments

Comments
 (0)