Skip to content

Conversation

@su8898
Copy link
Contributor

@su8898 su8898 commented Dec 20, 2021

Fixes #517


# FriendlyAsyncOverload (FL0078)

*Introduced in `0.20.3`*
Copy link
Collaborator

Choose a reason for hiding this comment

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

that ship has already sailed, please update version number


## Rationale

Exposing public F#-async APIs in a C#-friendly manner for better C# interoperability.
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's say "async APIs" here, not "F#-async APIs"


## How To Fix

Add an `Async` version of the API that returns a `Task<'T>`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add an Async-suffixed*

let FavourTypedIgnore = identifier 70
let CyclomaticComplexity = identifier 71
let FailwithBadUsage = identifier 72
let FriendlyAsyncOverload = identifier 77
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like the PR needs a rebase

<value>Bad usage of failwith: {0}.</value>
</data>
<data name="RulesFriendlyAsyncOverload" xml:space="preserve">
<value>Consider using a friendly async overload for {0}.</value>
Copy link
Collaborator

Choose a reason for hiding this comment

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

a C#-friendly* async overload

"invalidArgWithTwoArguments": { "enabled": true },
"failwithfWithArgumentsMatchingFormatString": { "enabled": true },
"failwithBadUsage": { "enabled": true },
"friendlyAsyncOverload": { "enabled": false },
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's rename it to csharpFriendlyAsyncOverload

{ Range = range
Message = String.Format(Resources.GetString "RulesFriendlyAsyncOverload", ident)
SuggestedFix = None
TypeChecks = [] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

use List.Empty here pls

Some(
{ Ident = fnIdent
Range = range }
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use |> Some here to save 1 line of code and to not need parenthesis

| head::_ when head.idText = "Async" ->
let idents = getIdentFromSynPat pattern
match idents with
| Some ident when ident.EndsWith("Async") = false ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for parenthesis here (and let's use the operator not instead of = false)

@su8898 su8898 force-pushed the CSharpFriendlyAsyncOverloads branch 3 times, most recently from ea40418 to e2a94e0 Compare December 20, 2021 15:31
| _ -> None

let runner (args: AstNodeRuleParams) =
let hasAsync (syntaxArray: AbstractSyntaxArray.Node []) nodeIndex fnIdent =
Copy link
Collaborator

Choose a reason for hiding this comment

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

use List<AbstractSyntaxArray.Node> here

Copy link
Collaborator

@knocte knocte Dec 20, 2021

Choose a reason for hiding this comment

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

I mean array<AbstractSyntaxArray.Node> not AbstractSyntaxArray.Node []

@su8898 su8898 force-pushed the CSharpFriendlyAsyncOverloads branch from e2a94e0 to 590708e Compare December 20, 2021 15:33
| AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, _, pattern, _, _, range, _)) ->
match getIdentFromSynPat pattern with
| Some ident when ident = fnIdent + "Async" ->
{ Ident = fnIdent
Copy link
Collaborator

Choose a reason for hiding this comment

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

4 space indentation, not 8

@su8898 su8898 force-pushed the CSharpFriendlyAsyncOverloads branch from 590708e to afe40c9 Compare December 20, 2021 15:40
@su8898 su8898 force-pushed the CSharpFriendlyAsyncOverloads branch from afe40c9 to ede5c57 Compare December 20, 2021 15:43
@su8898
Copy link
Contributor Author

su8898 commented Dec 20, 2021

@knocte I've addressed your review comments and updated the PR. Please have a look. thanks.

@knocte knocte changed the title Add new rule FriendlyAsyncOverload Add new rule CSharpFriendlyAsyncOverload Mar 1, 2022
@knocte
Copy link
Collaborator

knocte commented Nov 18, 2022

Superseded by #586

@knocte knocte closed this Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Best practice around naming asynchronous methods/functions

2 participants