-
Notifications
You must be signed in to change notification settings - Fork 75
Add new rule CSharpFriendlyAsyncOverload #533
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
Conversation
docs/content/how-tos/rules/FL0078.md
Outdated
|
|
||
| # FriendlyAsyncOverload (FL0078) | ||
|
|
||
| *Introduced in `0.20.3`* |
There was a problem hiding this comment.
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
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.
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"
docs/content/how-tos/rules/FL0078.md
Outdated
|
|
||
| ## How To Fix | ||
|
|
||
| Add an `Async` version of the API that returns a `Task<'T>` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
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.
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
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.
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 = [] } |
There was a problem hiding this comment.
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 } | ||
| ) |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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)
ea40418 to
e2a94e0
Compare
| | _ -> None | ||
|
|
||
| let runner (args: AstNodeRuleParams) = | ||
| let hasAsync (syntaxArray: AbstractSyntaxArray.Node []) nodeIndex fnIdent = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 []
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.
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
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