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

Best practice around naming asynchronous methods/functions #517

Open
knocte opened this issue Oct 19, 2021 · 0 comments · May be fixed by #586
Open

Best practice around naming asynchronous methods/functions #517

knocte opened this issue Oct 19, 2021 · 0 comments · May be fixed by #586

Comments

@knocte
Copy link
Collaborator

knocte commented Oct 19, 2021

Description

When dealing with F#-async workflows and exposing these APIs as public, we often forget about our C#-dev friends (that prefer Task-based alternatives, which should be suffixed with "Async").

Now, if there's already a FooAsync(): Task<'Bar> method, this rule should also suggest adding F#-friendly AsyncFoo(): Async<'Bar>.

Testcases

module Foo =
    let AsyncBar(): Async<int> =
        async { return 0 }

Should give linter warning offering creation of BarAsync(): Task<int>.

module Foo =
    let private AsyncBar(): Async<int> =
        async { return 0 }

Should not give any linter warnings (because it's not public).

module Foo =
    let internal AsyncBar(): Async<int> =
        async { return 0 }

Should not give any linter warnings (because it's not public).

module Foo =
    let AsyncBar(): Async<int> =
        async { return 0 }
    let BarAsync(): Task<int> =
        null

Should not give any linter warnings (because it complies with conventions).

module Foo =
    let Bar(): Async<int> =
        { return 1 }

Should give linter warning offering creation of BarAsync(): Task<int> and rename Bar to AsyncBar.

module Foo =
    let Bar(): Async<int> =
        async { return 0 }
    let BarAsync(): Task<int> =
        null

Should give linter warning offering renaming Bar to AsyncBar.

module Foo =
    let AsyncBar(): int =
        1
    let BarAsync(): Task<int> =
        null

Should give linter warning offering renaming AsyncBar to Bar.

module Foo =
    let AsyncBar(): Async<int> =
        async { return 0 }
    let Bar(): Task<int> =
        null

Should give linter warning offering renaming Bar to BarAsync.

module Foo =
    let AsyncBar(): Async<unit> =
        Async.Sleep 5.0

Should give linter warning offering creation of BarAsync(): Task (because unit in C# doesn't exist).

module Foo =
    let Bar(): Async<unit> =
        Async.Sleep 5.0

Should give linter warning offering creation of BarAsync(): Task (because unit in C# doesn't exist), and rename Bar to AsyncBar.

@knocte knocte changed the title Feature: rule to suggest adding a C#-friendly async overloads Feature: rule to suggest adding C#-friendly async overloads Oct 19, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Nov 2, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Nov 2, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Nov 3, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Nov 3, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
su8898 added a commit to su8898/FSharpLint that referenced this issue Dec 20, 2021
parhamsaremi pushed a commit to parhamsaremi/FSharpLint that referenced this issue Nov 18, 2022
@parhamsaremi parhamsaremi linked a pull request Nov 18, 2022 that will close this issue
@knocte knocte changed the title Feature: rule to suggest adding C#-friendly async overloads Best practice around naming asynchronous methods/functions Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant