Skip to content

Commit 525d40f

Browse files
Merge pull request #119 from Trivadis/feature/issue-111-formatter
Feature/issue 111 formatter
2 parents 60175aa + 9531eca commit 525d40f

File tree

94 files changed

+5453
-735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+5453
-735
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
# temporary files
2121
~$SQL-and-SQL-Coding-Guidelines.doc
22+
23+
# Visual Studio Code project folder
24+
.vscode

docs/3-coding-style/coding-style.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ Rule | Description
2020

2121
``` sql
2222
procedure set_salary(in_employee_id in employees.employee_id%type) is
23-
cursor c_employees(p_employee_id in employees.employee_id%type) is
23+
cursor c_employees(p_employee_id in employees.employee_id%type) is
2424
select last_name
2525
,first_name
2626
,salary
2727
from employees
2828
where employee_id = p_employee_id
2929
order by last_name
30-
,first_name;
30+
,first_name;
3131

32-
r_employee c_employees%rowtype;
33-
l_new_salary employees.salary%type;
32+
r_employee c_employees%rowtype;
33+
l_new_salary employees.salary%type;
3434
begin
35-
open c_employees(p_employee_id => in_employee_id);
35+
open c_employees(p_employee_id => in_employee_id);
3636
fetch c_employees into r_employee;
3737
close c_employees;
3838

39-
new_salary (in_employee_id => in_employee_id
40-
,out_salary => l_new_salary);
39+
new_salary(in_employee_id => in_employee_id
40+
,out_salary => l_new_salary);
4141

4242
-- Check whether salary has changed
4343
if r_employee.salary <> l_new_salary then

docs/4-language-usage/1-general/g-1010.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It's a good alternative for comments to indicate the start and end of a named pr
1111

1212
``` sql
1313
begin
14-
begin
14+
begin
1515
null;
1616
end;
1717

@@ -27,7 +27,7 @@ end;
2727
``` sql
2828
begin
2929
<<prepare_data>>
30-
begin
30+
begin
3131
null;
3232
end prepare_data;
3333

docs/4-language-usage/1-general/g-1020.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Use a label directly in front of loops and nested anonymous blocks:
1414

1515
``` sql
1616
declare
17-
i integer;
17+
i integer;
1818
co_min_value constant integer := 1;
1919
co_max_value constant integer := 10;
2020
co_increment constant integer := 1;
2121
begin
2222
<<prepare_data>>
23-
begin
23+
begin
2424
null;
2525
end;
2626

@@ -31,19 +31,19 @@ begin
3131

3232
i := co_min_value;
3333
<<while_loop>>
34-
while (i <= co_max_value)
35-
loop
36-
i := i + co_increment;
34+
while (i <= co_max_value)
35+
loop
36+
i := i + co_increment;
3737
end loop;
3838

3939
<<basic_loop>>
40-
loop
40+
loop
4141
exit basic_loop;
4242
end loop;
4343

4444
<<for_loop>>
4545
for i in co_min_value..co_max_value
46-
loop
46+
loop
4747
sys.dbms_output.put_line(i);
4848
end loop;
4949
end;
@@ -54,13 +54,13 @@ end;
5454

5555
``` sql
5656
declare
57-
i integer;
57+
i integer;
5858
co_min_value constant integer := 1;
5959
co_max_value constant integer := 10;
6060
co_increment constant integer := 1;
6161
begin
6262
<<prepare_data>>
63-
begin
63+
begin
6464
null;
6565
end prepare_data;
6666

@@ -71,20 +71,20 @@ begin
7171

7272
i := co_min_value;
7373
<<while_loop>>
74-
while (i <= co_max_value)
75-
loop
76-
i := i + co_increment;
74+
while (i <= co_max_value)
75+
loop
76+
i := i + co_increment;
7777
end loop while_loop;
7878

7979
<<basic_loop>>
80-
loop
80+
loop
8181
exit basic_loop;
8282
end loop basic_loop;
8383

8484
<<for_loop>>
8585
for i in co_min_value..co_max_value
86-
loop
87-
sys.dbms_output.put_line(i);
86+
loop
87+
sys.dbms_output.put_line(i);
8888
end loop for_loop;
8989
end;
9090
/

docs/4-language-usage/1-general/g-1030.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ Unused variables decrease the maintainability and readability of your code.
1212
``` sql
1313
create or replace package body my_package is
1414
procedure my_proc is
15-
l_last_name employees.last_name%type;
16-
l_first_name employees.first_name%type;
15+
l_last_name employees.last_name%type;
16+
l_first_name employees.first_name%type;
1717
co_department_id constant departments.department_id%type := 10;
18-
e_good exception;
18+
e_good exception;
1919
begin
2020
select e.last_name
2121
into l_last_name
2222
from employees e
2323
where e.department_id = co_department_id;
2424
exception
25-
when no_data_found then null; -- handle_no_data_found;
26-
when too_many_rows then null; -- handle_too_many_rows;
25+
when no_data_found then
26+
null; -- handle_no_data_found;
27+
when too_many_rows then
28+
null; -- handle_too_many_rows;
2729
end my_proc;
2830
end my_package;
2931
/
@@ -34,9 +36,9 @@ end my_package;
3436
``` sql
3537
create or replace package body my_package is
3638
procedure my_proc is
37-
l_last_name employees.last_name%type;
39+
l_last_name employees.last_name%type;
3840
co_department_id constant departments.department_id%type := 10;
39-
e_good exception;
41+
e_good exception;
4042
begin
4143
select e.last_name
4244
into l_last_name
@@ -45,8 +47,10 @@ create or replace package body my_package is
4547

4648
raise e_good;
4749
exception
48-
when no_data_found then null; -- handle_no_data_found;
49-
when too_many_rows then null; -- handle_too_many_rows;
50+
when no_data_found then
51+
null; -- handle_no_data_found;
52+
when too_many_rows then
53+
null; -- handle_too_many_rows;
5054
end my_proc;
5155
end my_package;
5256
/

docs/4-language-usage/1-general/g-1040.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,40 @@ Any part of your code, which is no longer used or cannot be reached, should be e
1313
declare
1414
co_dept_purchasing constant departments.department_id%type := 30;
1515
begin
16-
if 2=3 then
16+
if 2 = 3 then
1717
null; -- some dead code here
1818
end if;
19-
19+
2020
null; -- some enabled code here
21-
21+
2222
<<my_loop>>
2323
loop
24-
exit my_loop;
24+
exit my_loop;
2525
null; -- some dead code here
2626
end loop my_loop;
2727

2828
null; -- some other enabled code here
2929

30-
case
30+
case
3131
when 1 = 1 and 'x' = 'y' then
3232
null; -- some dead code here
3333
else
3434
null; -- some further enabled code here
3535
end case;
36-
36+
3737
<<my_loop2>>
38-
for r_emp in (select last_name
39-
from employees
40-
where department_id = co_dept_purchasing
41-
or commission_pct is not null
42-
and 5=6)
43-
-- "or commission_pct is not null" is dead code
38+
for r_emp in (
39+
select last_name
40+
from employees
41+
where department_id = co_dept_purchasing
42+
or commission_pct is not null
43+
and 5 = 6
44+
)
45+
-- "or commission_pct is not null" is dead code
4446
loop
4547
sys.dbms_output.put_line(r_emp.last_name);
4648
end loop my_loop2;
47-
49+
4850
return;
4951
null; -- some dead code here
5052
end;
@@ -62,10 +64,12 @@ begin
6264
null; -- some further enabled code here
6365

6466
<<my_loop2>>
65-
for r_emp in (select last_name
66-
from employees
67-
where department_id = co_dept_admin
68-
or commission_pct is not null)
67+
for r_emp in (
68+
select last_name
69+
from employees
70+
where department_id = co_dept_admin
71+
or commission_pct is not null
72+
)
6973
loop
7074
sys.dbms_output.put_line(r_emp.last_name);
7175
end loop my_loop2;

docs/4-language-usage/1-general/g-1050.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ begin
2121
into l_job
2222
from employees e
2323
where e.manager_id is null;
24-
24+
2525
if l_job = 'AD_PRES' then
2626
null;
2727
end if;
2828
exception
29-
when no_data_found then
29+
when no_data_found then
3030
null; -- handle_no_data_found;
31-
when too_many_rows then
31+
when too_many_rows then
3232
null; -- handle_too_many_rows;
3333
end;
3434
/
@@ -54,9 +54,9 @@ begin
5454
null;
5555
end if;
5656
exception
57-
when no_data_found then
57+
when no_data_found then
5858
null; -- handle_no_data_found;
59-
when too_many_rows then
59+
when too_many_rows then
6060
null; -- handle_too_many_rows;
6161
end;
6262
/

docs/4-language-usage/1-general/g-1060.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ Instead of using `rowid` for later reference to the original row one should use
1313

1414
``` sql
1515
begin
16-
insert into employees_log (employee_id
17-
,last_name
18-
,first_name
19-
,rid)
20-
select employee_id
16+
insert into employees_log (
17+
employee_id
18+
,last_name
19+
,first_name
20+
,rid
21+
)
22+
select employee_id
2123
,last_name
2224
,first_name
2325
,rowid
@@ -31,9 +33,9 @@ end;
3133
``` sql
3234
begin
3335
insert into employees_log (employee_id
34-
,last_name
35-
,first_name)
36-
select employee_id
36+
,last_name
37+
,first_name)
38+
select employee_id
3739
,last_name
3840
,first_name
3941
from employees;

docs/4-language-usage/1-general/g-1080.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ This rule ignores operators `+`, `*` and `||`, and expressions: `1=1`, `1<>1`, `
1414
``` sql
1515
select emp.first_name
1616
,emp.last_name
17-
,emp.salary
17+
,emp.salary
1818
,emp.hire_date
1919
from employees emp
20-
where emp.salary > 3000 or emp.salary > 3000
21-
order by emp.last_name, emp.first_name;
20+
where emp.salary > 3000
21+
or emp.salary > 3000
22+
order by emp.last_name,emp.first_name;
2223
```
2324

2425
## Example (good)
2526

2627
``` sql
2728
select emp.first_name
2829
,emp.last_name
29-
,emp.salary
30+
,emp.salary
3031
,emp.hire_date
3132
from employees emp
3233
where emp.salary > 3000
33-
order by emp.last_name, emp.first_name;
34+
order by emp.last_name,emp.first_name;
3435
```

docs/4-language-usage/2-variables-and-types/1-general/g-2110.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ create or replace package body my_package is
2020
from employees e
2121
where rownum = co_first_row;
2222
exception
23-
when no_data_found then null; -- handle no_data_found
24-
when too_many_rows then null; -- handle too_many_rows (impossible)
23+
when no_data_found then
24+
null; -- handle no_data_found
25+
when too_many_rows then
26+
null; -- handle too_many_rows (impossible)
2527
end my_proc;
2628
end my_package;
2729
/
@@ -40,8 +42,10 @@ create or replace package body my_package is
4042
from employees e
4143
where rownum = co_first_row;
4244
exception
43-
when no_data_found then null; -- handle no_data_found
44-
when too_many_rows then null; -- handle too_many_rows (impossible)
45+
when no_data_found then
46+
null; -- handle no_data_found
47+
when too_many_rows then
48+
null; -- handle too_many_rows (impossible)
4549
end my_proc;
4650
end my_package;
4751
/

0 commit comments

Comments
 (0)