rspec/rules/S4586/vbnet/rule.adoc
Martin Strecker f95d517a7c
Modify rule S4586: LaYC format (#2155)
Update rule content and descriptions to LaYC format.
https://sonarsource.github.io/rspec/#/rspec/S4586

## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-06-15 15:08:57 +02:00

48 lines
1.2 KiB
Plaintext

:keyword_null: Nothing
:keyword_async: Async
:concept_method: procedure
:typeparameter_TResult: (Of TResult)
== Why is this an issue?
include::../why-dotnet.adoc[]
[source,vbnet,diff-id=1,diff-type=noncompliant]
----
Public Function DoFooAsync() As Task
Return Nothing ' Noncompliant: Causes a NullReferenceException if awaited.
End Function
Public Async Function Main() As Task
Await DoFooAsync() ' NullReferenceException
End Function
----
[source,vbnet,diff-id=1,diff-type=compliant]
----
Public Function DoFooAsync() As Task
Return Task.CompletedTask ' Compliant: Method can be awaited.
End Function
Public Async Function Main() As Task
Await DoFooAsync()
End Function
----
[source,vbnet,diff-id=2,diff-type=noncompliant]
----
Public Function GetFooAsync() As Task(Of Object)
Return Nothing ' Noncompliant: Causes a NullReferenceException if awaited.
End Function
----
[source,vbnet,diff-id=2,diff-type=compliant]
----
Public Function GetFooAsync() As Task(Of Object)
Return Task.FromResult(Of Object)(Nothing) ' Compliant: Method can be awaited.
End Function
----
include::../resources.adoc[]
include::../rspecator.adoc[]