Skip to content

BSL194 — The function always returns the same primitive value

Summary

The function always returns the same primitive value

Identifiers

Field Value
Rule code BSL194
Compatible alias FunctionReturnsSamePrimitive
Severity ERROR
Enabled by default Yes
Implemented Yes
Tags redundant, design

Behavior

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

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

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

// BSLLS:FunctionReturnsSamePrimitive-off
// code without this diagnostic
// BSLLS:FunctionReturnsSamePrimitive-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 function should not return the same primitive value. If the result of the function isn't use into code, then you need the function rewrite to the procedure.

Examples

Bad:

Function CheckString(Val RowTable)

    If ItsGoodString(RowTable) Then
        ActionGood();
        Return True;
    ElsIf ItsNodBadString(RowTable) Then
        ActionNoBad();
        Return True;
     Else
        Return True;
    EndIf;

EndFunction

Good:

Function CheckString(Val RowTable)

    If ItsGoodString(RowTable) Then
        ActionGood();
    ElsIf ItsNodBadString(RowTable) Then
        ActionNoBad();
    Else
        ActionElse();
    EndIf;

EndFunction

Nuances

Attachable functions excluded from the scan. Example:

Function Attachable_RandomAction(Command)

    If ValueIsFilled(CurrentDate) Then
        Return Undefined;
    EndIf;

    Return Undefined;

EndFunction

Sources