Skip to content

Methods should not have too many return statements (TooManyReturns)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Minor No 20 brainoverload

Parameters

Name Type Description Default value
maxReturnsCount Integer Maximum allowed return statements per method 3

Description

A large number of returns in a method (procedure or function) increases its complexity and reduces performance and perception.

Examples

Bad method example

Function Example(Condition)
     If Condition = 1 Then
         Return "Check passed";
     ElsIf Condition = 2 Then
         ExecuteSomething();
         Return "Check not passed";
     ElsIf Condition > 7 Then
         Если Validate(Contidtion) Then
             Return "Check passed";
         Else
             Return "Check not passed";
         EndIf;
     EndIf;
     Return "";
EndFunction

Sources

Snippets

Diagnostic ignorance in code

// BSLLS:TooManyReturns-off
// BSLLS:TooManyReturns-on

Parameter for config

"TooManyReturns": {
    "maxReturnsCount": 3
}