Skip to content
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

Remove nullability of -subscribe* return value #2004

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Jan 7, 2025

There’s no reason for these to be nullable (it just makes it harder to call the -unsubscribe methods, which take a nonnull listener), and the return type of the underlying methods is nonnull.

Summary by CodeRabbit

  • Type Safety Improvements

    • Updated method signatures in ARTRealtimeChannel and ARTRealtimePresence to ensure non-nullable event listener returns.
    • Removed nullable return types for subscription methods to enhance code robustness.
  • New Method

    • Added newWithPresenceSyncState: class method to ARTEvent.
  • Test Enhancements

    • Improved safety in presence listener tests by removing forced unwrapping of listeners.

The changes focus on improving type safety and method consistency across the Ably realtime channel and presence APIs.

Copy link

coderabbitai bot commented Jan 7, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 SwiftLint (0.57.0)
Test/Tests/RealtimeClientPresenceTests.swift

[
{
"character" : 47,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 83,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 134,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 1137,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 40,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 1368,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 1394,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 55,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2119,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2161,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2655,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 54,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2700,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 44,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2868,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 40,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 3204,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 55,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 3382,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 41,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 3642,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 45,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 3659,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 51,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 3694,
"reason" : "Force casts should be avoided",
"rule_id" : "force_cast",
"severity" : "Error",
"type" : "Force Cast"
},
{
"character" : 10,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2797,
"reason" : "Type name 'TestCase_ReusableTestsTestPresencePerformMethod' should only contain alphanumeric and other allowed characters",
"rule_id" : "type_name",
"severity" : "Error",
"type" : "Type Name"
},
{
"character" : 39,
"file" : "/Test/Tests/RealtimeClientPresenceTests.swift",
"line" : 2669,
"reason" : "Unused parameter in a closure should be replaced with _",
"rule_id" : "unused_closure_parameter",
"severity" : "Warning",
"type" : "Unused Closure Parameter"
}
]

Walkthrough

The pull request involves systematic modifications to method signatures across multiple Objective-C files in the Ably SDK. The primary change is updating the return type of various subscribe methods in ARTRealtimeChannel and ARTRealtimePresence classes from ARTEventListener *_Nullable to ARTEventListener *. This modification ensures that these methods always return a non-nullable event listener, enhancing type safety and potentially simplifying error handling in the codebase. Additionally, a new method for instantiating ARTEvent with a specific presence sync state has been introduced.

Changes

File Changes
Source/ARTRealtimeChannel.m Updated return types for multiple subscribe methods from _Nullable to non-nullable
Source/ARTRealtimePresence.m Updated return types for multiple subscribe methods from _Nullable to non-nullable; Added new class method + (instancetype)newWithPresenceSyncState: to ARTEvent
Source/include/Ably/ARTRealtimeChannel.h Updated method signatures in ARTRealtimeChannelProtocol to remove nullability
Source/include/Ably/ARTRealtimePresence.h Updated method signatures in ARTRealtimePresenceProtocol to remove nullability
Test/Tests/RealtimeClientPresenceTests.swift Removed forced unwrapping from listener assignments in test methods to enhance safety

Poem

🐰 Hop, hop, through the code we go,
Nullable types, now they're set to flow!
No more question marks in our sight,
Listeners return, clean and bright!
A rabbit's leap of type safety's might! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c8eceb and cb143de.

📒 Files selected for processing (5)
  • Source/ARTRealtimeChannel.m (1 hunks)
  • Source/ARTRealtimePresence.m (1 hunks)
  • Source/include/Ably/ARTRealtimeChannel.h (4 hunks)
  • Source/include/Ably/ARTRealtimePresence.h (4 hunks)
  • Test/Tests/RealtimeClientPresenceTests.swift (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • Source/ARTRealtimeChannel.m
  • Source/include/Ably/ARTRealtimeChannel.h
  • Source/include/Ably/ARTRealtimePresence.h
  • Source/ARTRealtimePresence.m
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: check
  • GitHub Check: build
  • GitHub Check: check
🔇 Additional comments (3)
Test/Tests/RealtimeClientPresenceTests.swift (3)

500-500: Improved safety by removing force unwrapping

The removal of force unwrapping (!) from the listener assignment makes the code safer, as it aligns with the updated API where subscribe now returns a non-nullable ARTEventListener.


881-881: Improved safety by removing force unwrapping

Similarly, the removal of force unwrapping (!) from the action-specific subscription makes the code safer, as it aligns with the updated API where subscribe(.present) now returns a non-nullable ARTEventListener.


Line range hint 500-881: Verify test coverage for subscription error cases

While the changes improve safety by removing force unwrapping, it would be good to add test cases that verify error handling when subscriptions fail.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/2004/features January 7, 2025 12:33 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/2004/jazzydoc January 7, 2025 12:36 Inactive
lawrence-forooghian added a commit to ably/ably-chat-swift that referenced this pull request Jan 7, 2025
Create SubscriptionStorage type for helping with common activities (TODO
document)

Namely, managing a list of subscriptions and emitting values on all of
these subscriptions.

TODO what about example app?
TODO need to do MessageSubscriptions too

TODO handle nullability of returned listeners once
ably/ably-cocoa#2004 merged and released
There’s no reason for these to be nullable (it just makes it harder to
call the -unsubscribe methods, which take a nonnull listener), and the
return type of the underlying methods is nonnull.
@lawrence-forooghian lawrence-forooghian force-pushed the return-non-nil-event-handler branch from 7c8eceb to cb143de Compare January 7, 2025 12:50
lawrence-forooghian added a commit to ably/ably-chat-swift that referenced this pull request Jan 7, 2025
Create SubscriptionStorage type for helping with common activities (TODO
document)

Namely, managing a list of subscriptions and emitting values on all of
these subscriptions.

TODO what about example app?
TODO need to do MessageSubscriptions too

TODO handle nullability of returned listeners once
ably/ably-cocoa#2004 merged and released
lawrence-forooghian added a commit to ably/ably-chat-swift that referenced this pull request Jan 7, 2025
Create SubscriptionStorage type for helping with common activities (TODO
document)

Namely, managing a list of subscriptions and emitting values on all of
these subscriptions.

TODO what about example app?
TODO need to do MessageSubscriptions too

TODO handle nullability of returned listeners once
ably/ably-cocoa#2004 merged and released
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant