Skip to content

Else...The...ElseIf... statement should end with Else branch (IfElseIfEndsWithElse)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Major Yes 10 badpractice

Description

The rule is applied whenever the conditional operator If Then ElseIf contains one or more blocks ElseIf . After block ElseIf must be followed by block Else.

The requirement to the final blockElse - it protective programming. Such constructions are resistant to possible changes and do not mask possible errors.

The construct Else must either take appropriate action or contain a suitable comment as to why no action is being taken.

Examples

Incorrect:

If TypeOf(InputParameter) = Type("Structure") Then
    Result = FillByStructure(InputParameter);
ElsIf TypeOf(InputParameter) = Type("Document.Ref.MajorDocument") Then
    Result = FillByDocument(InputParameter);
EndIf;

Correct:

If TypeOf(InputParameter) = Type("Structure") Then
    Result = FillByStructure(InputParameter);
ElsIf TypeOf(InputParameter) = Type("Document.Ref.MajorDocument") Then
    Result = FillByDocument(InputParameter);
Else
    Raise "Parameter of invalid type passed";
EndIf;

Snippets

Diagnostic ignorance in code

// BSLLS:IfElseIfEndsWithElse-off
// BSLLS:IfElseIfEndsWithElse-on

Parameter for config

"IfElseIfEndsWithElse": false