Skip to content

Commit

Permalink
Fix # 50 - Added new rule G-4325: Never reuse labels in inner scopes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kibeha committed Nov 11, 2020
1 parent 60166ce commit 4baf7e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# G-4325: Never reuse labels in inner scopes.

!!! warning "Major"
Maintainability, Reliability, Testability

## Reason

Reusing labels inside the scope of another label with the same name leads to confusion, less chance of understanding the code, and could lead to bugs (for example if using `exit my_label` exits at a different nesting level than expected.)

## Example (bad)

``` sql
<<my_label>>
declare
co_min_value constant simple_integer := 1;
co_max_value constant simple_integer := 8;
begin
<<my_label>>
for i in co_min_value..co_max_value
loop
sys.dbms_output.put_line(i);
end loop;
end;
/
```

## Example (good)

``` sql
<<output_values>>
declare
co_min_value constant simple_integer := 1;
co_max_value constant simple_integer := 8;
begin
<<process_values>>
for i in co_min_value..co_max_value
loop
sys.dbms_output.put_line(i);
end loop process_values;
end output_values;
/
```
1 change: 1 addition & 0 deletions docs/9-appendix/appendix.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ n/a | 4260 | Avoid inverting boolean conditions with NOT. | Minor | | | &#1000
n/a | 4270 | Avoid comparing boolean values to boolean literals. | Minor | | | &#10008; | | | | | &#10008;
39 | 4310 | Never use GOTO statements in your code. | Major | | | &#10008; | | | | | &#10008;
40 | 4320 | Always label your loops. | Minor | | | &#10008; | | | | |
n/a | 4325 | Never reuse labels in inner scopes. | Major | | | &#10008; | | &#10008; | | | &#10008;
41 | 4330 | Always use a CURSOR FOR loop to process the complete cursor results unless you are using bulk operations. | Minor | | | &#10008; | | | | |
42 | 4340 | Always use a NUMERIC FOR loop to process a dense array. | Minor | | | &#10008; | | | | |
43 | 4350 | Always use 1 as lower and COUNT() as upper bound when looping through a dense array. | Major | | | | | &#10008; | | |
Expand Down

1 comment on commit 4baf7e3

@kibeha
Copy link
Collaborator Author

@kibeha kibeha commented on 4baf7e3 Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #50

Please sign in to comment.