Skip to content

BSL198 — Duplicated conditions in If...Then...ElseIf... statements

Summary

Duplicated conditions in If...Then...ElseIf... statements

Identifiers

Field Value
Rule code BSL198
Compatible alias IfElseDuplicatedCondition
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags suspicious, correctness

Behavior

  • The public identifier BSL198 and alias IfElseDuplicatedCondition are 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.

[tool.onec-hbk-bsl]
select = ["BSL198"]
ignore = ["IfElseDuplicatedCondition"]

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:
Value = "example";  // noqa: BSL198
  • bsl-disable:
Value = "example";  // bsl-disable: BSL198
  • compatible BSLLS form:
Value = "example";  // BSLLS:IfElseDuplicatedCondition-off

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: BSL198
// code without this diagnostic
// noqa-enable: BSL198

// bsl-disable: BSL198
// code without this diagnostic
// bsl-enable: BSL198

// BSLLS:IfElseDuplicatedCondition-off
// code without this diagnostic
// BSLLS:IfElseDuplicatedCondition-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

If...Then...ElseIf... statement should not have duplicated conditions.

Examples

If p = 0 Then
    t = 0;
ElseIf p = 1 Then
    t = 1;
ElseIf p = 1 Then
    t = 2;
Else
    t = -1;
EndIf;