Skip to content

BSL052 — There are identical sub-expressions to the left and to the right of the "foo" operator

Summary

There are identical sub-expressions to the left and to the right of the "foo" operator

Identifiers

Field Value
Rule code BSL052
Compatible alias IdenticalExpressions
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags suspicious, logic

Behavior

  • The public identifier BSL052 and alias IdenticalExpressions 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 = ["BSL052"]
ignore = ["IdenticalExpressions"]

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: BSL052
  • bsl-disable:
Value = "example";  // bsl-disable: BSL052
  • compatible BSLLS form:
Value = "example";  // BSLLS:IdenticalExpressions-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: BSL052
// code without this diagnostic
// noqa-enable: BSL052

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

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

The analyzer found a code fragment that most probably has a logic error. There is an operator (, <=, >=, =, <>, AND, OR, -, /) in the program text to the left and to the right of which there are identical subexpressions.

Examples

If Summ <> 0 AND Summ <> 0 Then

    // TODO

EndIf;

In this case, the AND operator is surrounded by identical subexpressions Summ <> 0 and it allows us to detect an error made through inattention. The correct code that will not look suspicious to the analyzer looks in the following way:

If Summ <> 0 AND SummNDS <> 0 Then

    // TODO

EndIf;

OR

If Summ <> 0 Then

    // TODO

EndIf;