Skip to content

BSL032 — The function should have return

Summary

The function should have return

Identifiers

Field Value
Rule code BSL032
Compatible alias FunctionShouldHaveReturn
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags suspicious, design

Behavior

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

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

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

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

Function differs from a Procedure only that it necessarily returns a value and can be used in expressions.

Based on the above-mentioned, a function which does not contain a return is itself erroneous. Corrections required:

  • implement return if the implemented method is a function
  • rewrite function to procedure if return is not needed