BSL008 — Methods should not have too many return statements¶
Summary¶
Methods should not have too many return statements
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL008 |
| Compatible alias | TooManyReturns |
| Severity | WARNING |
| Enabled by default | Yes |
| Implemented | Yes |
| Tags | brain-overload |
Behavior¶
- The public identifier
BSL008and aliasTooManyReturnsare stable. - The rule reports the cases documented on this page.
- Suppressions and project configuration are applied before publication.
- The rule requires neither an external analyzer nor network access.
Configuration and suppression¶
BSL### is the primary stable identifier. The compatible alias is accepted
in select, ignore, and compatible block suppression comments.
All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:
noqa:
bsl-disable:
- compatible
BSLLSform:
When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:
// noqa: BSL008
// code without this diagnostic
// noqa-enable: BSL008
// bsl-disable: BSL008
// code without this diagnostic
// bsl-enable: BSL008
// BSLLS:TooManyReturns-off
// code without this diagnostic
// BSLLS:TooManyReturns-on
To disable the rule until the end of the file, omit the closing
noqa-enable, bsl-enable, or BSLLS:…-on marker.
Opening and closing markers must belong to the same family.
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