Skip to content

Commit cb2ff5b

Browse files
committed
Fix #45 - Created rule G-4270: Avoid comparing boolean values to boolean literals.
1 parent 16d67a4 commit cb2ff5b

File tree

1 file changed

+38
-0
lines changed
  • docs/4-language-usage/4-control-structures/2-case-if-decode-nvl-nvl2-coalesce

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# G-4270: Avoid comparing boolean values to boolean literals.
2+
3+
!!! tip "Minor"
4+
Maintainability, Testability
5+
6+
## Reason
7+
8+
It is more readable to simply use the boolean value as a condition itself, rather than use a comparison condition comparing the boolean value to the literals `true` or `false`.
9+
10+
## Example (bad)
11+
12+
``` sql
13+
declare
14+
l_string varchar2(10 char) := '42';
15+
l_is_valid boolean;
16+
begin
17+
l_is_valid := my_package.is_valid_number(l_string);
18+
if l_is_valid = true then
19+
my_package.convert_number(l_string);
20+
end if;
21+
end;
22+
/
23+
```
24+
25+
## Example (good)
26+
27+
``` sql
28+
declare
29+
l_string varchar2(10 char) := '42';
30+
l_is_valid boolean;
31+
begin
32+
l_is_valid := my_package.is_valid_number(l_string);
33+
if l_is_valid then
34+
my_package.convert_number(l_string);
35+
end if;
36+
end;
37+
/
38+
```

0 commit comments

Comments
 (0)