Add new rule CSharpFriendlyAsyncOverload#533
Add new rule CSharpFriendlyAsyncOverload#533su8898 wants to merge 1 commit intofsprojects:masterfrom
Conversation
docs/content/how-tos/rules/FL0078.md
Outdated
|
|
||
| # FriendlyAsyncOverload (FL0078) | ||
|
|
||
| *Introduced in `0.20.3`* |
There was a problem hiding this comment.
that ship has already sailed, please update version number
docs/content/how-tos/rules/FL0078.md
Outdated
|
|
||
| ## Rationale | ||
|
|
||
| Exposing public F#-async APIs in a C#-friendly manner for better C# interoperability. |
There was a problem hiding this comment.
let's say "async APIs" here, not "F#-async APIs"
docs/content/how-tos/rules/FL0078.md
Outdated
|
|
||
| ## How To Fix | ||
|
|
||
| Add an `Async` version of the API that returns a `Task<'T>` |
| let FavourTypedIgnore = identifier 70 | ||
| let CyclomaticComplexity = identifier 71 | ||
| let FailwithBadUsage = identifier 72 | ||
| let FriendlyAsyncOverload = identifier 77 |
There was a problem hiding this comment.
this looks like the PR needs a rebase
src/FSharpLint.Core/Text.resx
Outdated
| <value>Bad usage of failwith: {0}.</value> | ||
| </data> | ||
| <data name="RulesFriendlyAsyncOverload" xml:space="preserve"> | ||
| <value>Consider using a friendly async overload for {0}.</value> |
There was a problem hiding this comment.
a C#-friendly* async overload
src/FSharpLint.Core/fsharplint.json
Outdated
| "invalidArgWithTwoArguments": { "enabled": true }, | ||
| "failwithfWithArgumentsMatchingFormatString": { "enabled": true }, | ||
| "failwithBadUsage": { "enabled": true }, | ||
| "friendlyAsyncOverload": { "enabled": false }, |
There was a problem hiding this comment.
let's rename it to csharpFriendlyAsyncOverload
| { Range = range | ||
| Message = String.Format(Resources.GetString "RulesFriendlyAsyncOverload", ident) | ||
| SuggestedFix = None | ||
| TypeChecks = [] } |
| Some( | ||
| { Ident = fnIdent | ||
| Range = range } | ||
| ) |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
no need for parenthesis here (and let's use the operator not instead of = false)
ea40418 to
e2a94e0
Compare
| | _ -> None | ||
|
|
||
| let runner (args: AstNodeRuleParams) = | ||
| let hasAsync (syntaxArray: AbstractSyntaxArray.Node []) nodeIndex fnIdent = |
There was a problem hiding this comment.
use List<AbstractSyntaxArray.Node> here
There was a problem hiding this comment.
I mean array<AbstractSyntaxArray.Node> not AbstractSyntaxArray.Node []
e2a94e0 to
590708e
Compare
| | AstNode.Binding (SynBinding (_, _, _, _, _attributes, _, _, pattern, _, _, range, _)) -> | ||
| match getIdentFromSynPat pattern with | ||
| | Some ident when ident = fnIdent + "Async" -> | ||
| { Ident = fnIdent |
There was a problem hiding this comment.
4 space indentation, not 8
590708e to
afe40c9
Compare
afe40c9 to
ede5c57
Compare
|
@knocte I've addressed your review comments and updated the PR. Please have a look. thanks. |
|
Superseded by #586 |
Fixes #517