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

Allow unit return type for suspend functions #293

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oguzcelik
Copy link

Summary

This pr aims to fix the lint rule for retrofit usage. Solves this issue

For suspend functions it's a valid case to return Unit.

Requirements (place an x in each [ ])

Unfortunately the contributing guidelines and Contributor license agreement links are not working.

The following point can be removed after setting up CI (such as Travis) with coverage reports (such as Codecov)

  • I've written tests to cover the new code and functionality included in this PR.

The following point can be removed after setting up a CLA reporting tool such as cla-assistant.io

Copy link

salesforce-cla bot commented Jul 8, 2024

Thanks for the contribution! Before we can merge this, we need @oguzcelik to sign the Salesforce Inc. Contributor License Agreement.

@ZacSweers
Copy link
Collaborator

Let's make this more intentional. Could we either add an opt-in annotation like @AllowUnitResponse with a doc on it explaining contexts where it makes sense? Blanket disabling this feels like the wrong move when the goal is to make developers more intentional.

import slack.lint.BaseSlackLintTest

class RetrofitUsageDetectorTest : BaseSlackLintTest() {

private companion object {
private val allowUnitResponse =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed other examples of how to make the test recognise this import. Don't know if there is a better way.

* to have a return type of Unit, which otherwise will be flagged as an issue.
*/
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marked as Binary retention as we don't need this at runtime.

@oguzcelik
Copy link
Author

Would you want to make the docs more explicit ? Something like:

/**
 * Annotation to allow suspend Retrofit functions to return Unit.
 * 
 * This annotation is used to indicate that a suspend Retrofit function is allowed to have 
 * a return type of [Unit]. This might be necessary for certain HTTP methods where the 
 * response body is not significant. For instance:
 * 
 * - Methods like `@POST`, `@PUT`, or `@DELETE` may logically return `Unit` if 
 *    the client is only concerned with the success/failure of the operation and not the 
 *    actual response body.
 * 
 * Invalid Use Cases:
 * - `@GET`: Typically, `@GET` methods should return a meaningful response object as 
 *    they are intended to retrieve data.
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants