Skip to content

Usage of complex expressions in the "If" condition (IfConditionComplexity)

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

Parameters

Name Type Description Default value
maxIfConditionComplexity Integer Acceptable number of logical expressions in operator If condition 3

Description

Complex expressions (with more than 3 boolean constructs) must be extracted to separated method or variable.

Examples

Bad:

If Id = "Expr1"
    Or Id = "Expr2"
    Or Id = "Expr3"
    Or Id = "Expr4"
    Or Id = "Expr5"
    Or Id = "Expr6"
    Or Id = "Expr7"
    Or Id = "Expr8"
    Or Id = "Expr9" Then

   doSomeWork();

EndIf; 

Good:

If IsCorrectId(Id) Then
   doSomeWork();
КонецЕсли;

Function IsCorrectId(Id)

    Return Id = "Expr1"
            Or Id = "Expr2"
            Or Id = "Expr3"
            Or Id = "Expr4"
            Or Id = "Expr5"
            Or Id = "Expr6"
            Or Id = "Expr7"
            Or Id = "Expr8"
            Or Id = "Expr9";

EndFunction

Snippets

Diagnostic ignorance in code

// BSLLS:IfConditionComplexity-off
// BSLLS:IfConditionComplexity-on

Parameter for config

"IfConditionComplexity": {
    "maxIfConditionComplexity": 3
}