Procedure Can Be Written As Function

Warns about 'Sub' procedures that could be refactored into a 'Function'.

Reasoning

Idiomatic VB code uses 'Function' procedures to return a single value. If the procedure isn't side-effecting, consider writing it as a 'Function' rather than a 'Sub' that returns a result through a 'ByRef' parameter.

Default severity

Suggestion

Inspection type

LanguageOpportunities

Examples

This example should trigger a result

MyModule (StandardModule)
Option Explicit Public Sub DoSomething(ByRef result As Long) ' ... result = 42 End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Option Explicit Public Function DoSomething() As Long ' ... DoSomething = 42 End Function

This example should NOT trigger a result

MyModule (StandardModule)
Option Explicit Public Function DoSomething(ByVal arg As Long) As Long ' ... DoSomething = 42 End Function

Rubberduck.CodeAnalysis.Inspections.Concrete.ProcedureCanBeWrittenAsFunctionInspection.cs (Prerelease-v2.5.9.6289)