G-2410
🆓Warning
Try to use boolean data type for values with dual meaning.
Reason
The use of true and false clarifies that this is a boolean value and makes the code easier to read.
Examples
Non-Compliant Example
declare
co_newfile constant pls_integer := 1000;
co_oldfile constant pls_integer := 500;
l_bigger pls_integer;
begin
if co_newfile < co_oldfile then
l_bigger := 1;
else
l_bigger := 0;
end if;
do_something(l_bigger);
end;
/Issues
| Line | Column | Message |
|---|---|---|
| 4 | 15 |
Compliant Solution - ★★★☆☆
declare
co_newfile constant pls_integer := 1000;
co_oldfile constant pls_integer := 500;
l_bigger boolean;
begin
if co_newfile < co_oldfile then
l_bigger := true;
else
l_bigger := false;
end if;
do_something(l_bigger);
end;
/ Compliant Solution - ★★★★★
declare co_newfile constant pls_integer := 1000; co_oldfile constant pls_integer := 500; l_bigger boolean; begin l_bigger := nvl(co_newfile < co_oldfile,false); do_something(l_bigger); end; /
Parameters
Use parameters to customize the rule to your needs.
| Parameter | Description | Default Value |
|---|---|---|
| BooleanValues | Comma-separated list of literals and variable names to be considered as a boolean value. The values are case-insensitive. | true, false, t, f, 0, 1, 2, yes, no, y, n, ja, nein, j, si, s, oui, non, o, l_true, l_false, co_true, co_false, co_numeric_true, co_numeric_false |
References
- same as Trivadis G-2410