Skip to content

fix: setup swift-lint #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ jobs:
- name: Typecheck files
run: yarn typecheck

swift-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: SwiftLint
uses: norio-nomura/action-swiftlint@3.2.1
env:
WORKING_DIRECTORY: Source

build-library:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -94,7 +104,7 @@ jobs:

- name: Build example for Android
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
JAVA_OPTS: '-XX:MaxHeapSize=6g'
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"

Expand Down Expand Up @@ -153,7 +163,7 @@ jobs:

- name: Build example for Android new arch
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
JAVA_OPTS: '-XX:MaxHeapSize=6g'
run: |
yarn turbo run build:android:fabric --cache-dir="${{ env.TURBO_CACHE_DIR }}"

Expand Down Expand Up @@ -200,7 +210,6 @@ jobs:
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"


build-ios-newarch:
runs-on: macos-15
env:
Expand Down
83 changes: 83 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
opt_in_rules:
- anonymous_argument_in_multiline_closure
- array_init
- closure_end_indentation
- closure_spacing
- collection_alignment
- comma_inheritance
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- convenience_type
- direct_return
- discarded_notification_center_observer
- discouraged_none_name
- discouraged_object_literal
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- expiring_todo
- explicit_init
- fallthrough
- fatal_error_message
- file_name_no_space
- first_where
- flatmap_over_map_reduce
# - force_unwrapping # nice to have
- identical_operands
- implicit_return
# - implicitly_unwrapped_optional # nice to have
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_objc_type
- literal_expression_end_indentation
- local_doc_comment
- modifier_order
- multiline_arguments
- multiline_arguments_brackets
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
# - no_magic_numbers # nice to have
- nslocalizedstring_key
- number_separator
- operator_usage_whitespace
- optional_enum_case_matching
- overridden_super_call
- prefer_self_type_over_type_of_self
- reduce_into
- redundant_nil_coalescing
- redundant_self_in_closure
- redundant_type_annotation
- return_value_from_void_function
- self_binding
- shorthand_optional_binding
- sorted_first_last
- sorted_imports
- strict_fileprivate
- superfluous_else
- switch_case_on_newline
- toggle_bool
- trailing_closure
- unavailable_function
- unhandled_throwing_task
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- weak_delegate
- yoda_condition

disabled_rules:
- nesting

identifier_name:
excluded: # excluded via string array
- id
- ID
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
@objcMembers
public class OnNativeLayoutEvent: NSObject, RCTEvent {
private var size: CGSize
public var viewTag: NSNumber

Check warning on line 6 in packages/react-native-bottom-tabs/ios/Events/OnNativeLayoutEvent.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)

public var eventName: String {
return "onNativeLayout"
"onNativeLayout"
}

public init(reactTag: NSNumber, size: CGSize) {

Check warning on line 12 in packages/react-native-bottom-tabs/ios/Events/OnNativeLayoutEvent.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
self.viewTag = reactTag
self.size = size
super.init()
}

public class func moduleDotMethod() -> String {
return "RCTEventEmitter.receiveEvent"
"RCTEventEmitter.receiveEvent"
}

public func canCoalesce() -> Bool {
return false
false
}

public func arguments() -> [Any] {
return [
[
viewTag,
RCTNormalizeInputEventName(eventName) ?? eventName,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

@objcMembers
public class PageSelectedEvent: NSObject, RCTEvent {
private var key: NSString

Check warning on line 5 in packages/react-native-bottom-tabs/ios/Events/PageSelectedEvent.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
public var viewTag: NSNumber

public var eventName: String {
return "onPageSelected"
"onPageSelected"
}

public init(reactTag: NSNumber, key: NSString) {
self.viewTag = reactTag
self.key = key
super.init()
}

public class func moduleDotMethod() -> String {
return "RCTEventEmitter.receiveEvent"
"RCTEventEmitter.receiveEvent"
}

public func canCoalesce() -> Bool {
return false
false
}

public func arguments() -> [Any] {
return [
[
viewTag,
RCTNormalizeInputEventName(eventName) ?? eventName,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import React
public class TabBarMeasuredEvent: NSObject, RCTEvent {
private var height: NSInteger
public var viewTag: NSNumber

public var eventName: String {
return "onTabBarMeasured"
"onTabBarMeasured"
}

public init(reactTag: NSNumber, height: NSInteger) {
self.viewTag = reactTag
self.height = height
super.init()
}

public class func moduleDotMethod() -> String {
return "RCTEventEmitter.receiveEvent"
"RCTEventEmitter.receiveEvent"
}

public func canCoalesce() -> Bool {
return false
false
}

public func arguments() -> [Any] {
return [
[
viewTag,
RCTNormalizeInputEventName(eventName) ?? eventName,
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import React


// RCTEvent is not defined for new arch.
protocol RCTEvent {}

@objcMembers
public class TabLongPressEvent: NSObject, RCTEvent {
private var key: NSString
public var viewTag: NSNumber

public var eventName: String {
return "onTabLongPress"
"onTabLongPress"
}

public init(reactTag: NSNumber, key: NSString) {
self.viewTag = reactTag
self.key = key
super.init()
}

public class func moduleDotMethod() -> String {
return "RCTEventEmitter.receiveEvent"
"RCTEventEmitter.receiveEvent"
}

public func canCoalesce() -> Bool {
return false
false
}

public func arguments() -> [Any] {
return [
[
viewTag,
RCTNormalizeInputEventName(eventName) ?? eventName,
[
Expand Down
15 changes: 6 additions & 9 deletions packages/react-native-bottom-tabs/ios/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import UIKit
extension Collection {
// Returns the element at the specified index if it is within bounds, otherwise nil.
subscript(safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
indices.contains(index) ? self[index] : nil
}
}

extension Collection where Element == TabInfo {
func findByKey(_ key: String?) -> Element? {
guard let key else { return nil }
guard !isEmpty else { return nil }
return first(where: { $0.key == key })
return first { $0.key == key }
}
}

Expand All @@ -37,25 +37,23 @@ extension PlatformView {
extension PlatformImage {
func resizeImageTo(size: CGSize) -> PlatformImage? {
#if os(macOS)
let newImage = NSImage(size: size, flipped: false) { (rect) -> Bool in
return NSImage(size: size, flipped: false) { rect -> Bool in
self.draw(in: rect,
from: CGRect(origin: .zero, size: self.size),
operation: .copy,
fraction: 1.0)
return true
}
return newImage
#else
let renderer = UIGraphicsImageRenderer(size: size)
return renderer.image { context in
return renderer.image { _ in
self.draw(in: CGRect(origin: .zero, size: size))
}
#endif
}
}

extension View {

#if os(macOS)
@MainActor
@ViewBuilder
Expand All @@ -82,13 +80,12 @@ extension View {
#endif
}
#endif



@MainActor
@ViewBuilder
func measureView(onLayout: @escaping (_ size: CGSize) -> Void) -> some View {
self
.background (
.background(
GeometryReader { geometry in
Color.clear
.onChange(of: geometry.size) { newValue in
Expand Down
18 changes: 9 additions & 9 deletions packages/react-native-bottom-tabs/ios/RepresentableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import SwiftUI
*/
struct RepresentableView: PlatformViewRepresentable {
var view: PlatformView

#if os(macOS)

func makeNSView(context: Context) -> PlatformView {
return view
view
}

func updateNSView(_ nsView: PlatformView, context: Context) {}

#else

func makeUIView(context: Context) -> PlatformView {
return view
view
}

func updateUIView(_ uiView: PlatformView, context: Context) {}

#endif
}
4 changes: 2 additions & 2 deletions packages/react-native-bottom-tabs/ios/TabItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct TabItem: View {
var icon: PlatformImage?
var sfSymbol: String?
var labeled: Bool?

var body: some View {
if let icon {
#if os(macOS)
Expand All @@ -17,7 +17,7 @@ struct TabItem: View {
Image(systemName: sfSymbol)
.noneSymbolVariant()
}
if (labeled != false) {
if labeled != false {
Text(title ?? "")
}
}
Expand Down
Loading
Loading