Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix/explain violations of unrelated guidelines #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
eb9f896
fix violations of G-7310, G-8310
PhilippSalvisberg Jul 21, 2023
5e150f8
fix violations of G-3210, G-4385, G-7120, G-8310
PhilippSalvisberg Jul 21, 2023
2c11dad
fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
8860d31
fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
49fcd38
Fix violations of G-4385, G-4370, G-4375, G-8310
PhilippSalvisberg Jul 21, 2023
4b69512
Fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
40089f7
Fix violations of G-7110, G-8310
PhilippSalvisberg Jul 21, 2023
7db927d
Fix violoations of G-8310
PhilippSalvisberg Jul 21, 2023
9af7e08
Fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
fc03cfb
Fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
caf9502
Fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
31f7f8a
Fix violations of G-8310
PhilippSalvisberg Jul 21, 2023
932daf7
Fix violations of G-1050
PhilippSalvisberg Jul 21, 2023
588b17d
Fix violations of G-1050
PhilippSalvisberg Jul 21, 2023
5927f4a
Fix violations of G-1050
PhilippSalvisberg Jul 21, 2023
9e113ab
Fix violations of G-7460
PhilippSalvisberg Jul 21, 2023
a9b615e
Fix violations of G-7460
PhilippSalvisberg Jul 21, 2023
4d7d2c6
Fix violations of G-7460
PhilippSalvisberg Jul 21, 2023
7d76702
Fix violations of G-7460
PhilippSalvisberg Jul 21, 2023
8d20e26
Fix violations of G-7460
PhilippSalvisberg Jul 21, 2023
c5ec491
do not report lines with NOSONAR marker
PhilippSalvisberg Jul 21, 2023
d96e724
Fix violations of G-1050, G-4320, G-4390, G-4395
PhilippSalvisberg Jul 21, 2023
0f0e1c1
Fix violations of G-4365
PhilippSalvisberg Jul 28, 2023
f9a9e89
Fix violations of G-4365, explain violations of G-1050
PhilippSalvisberg Jul 28, 2023
4922137
add tvdcc_report.json to .gitignore
PhilippSalvisberg Jul 28, 2023
2ee500c
Fix violations of G-1050
PhilippSalvisberg Jul 28, 2023
7575953
Fix violations of G-2135, explain G-9102, G-9114, G-9113
PhilippSalvisberg Jul 28, 2023
8a6210c
Fx violations of G-2130, G-1050
PhilippSalvisberg Jul 28, 2023
5cb21e7
Fix violations of G-2135, G-1050
PhilippSalvisberg Jul 28, 2023
1f35389
bump version of db* CODECOP CLI, validator
PhilippSalvisberg Jul 28, 2023
305ca21
Fix violations of G-2135, explain G-9114, G-9113
PhilippSalvisberg Jul 28, 2023
be9c151
fix violations of G-7460, G-2130 by using a different example
PhilippSalvisberg Jul 28, 2023
0fbb84f
Fix violations of G-7460, explain G-2130, G-2230 - new example demons…
PhilippSalvisberg Jul 28, 2023
a699407
Explain G-2130, G-2220, new example demonstrating that simple_integer…
PhilippSalvisberg Jul 28, 2023
2adce4e
Fix violations of G-7460, G-2130
PhilippSalvisberg Jul 28, 2023
efd8a13
Fix violations of G-2135
PhilippSalvisberg Jul 28, 2023
93e20f4
Fix violation of G-7230, G-1030 - explain G-2130
PhilippSalvisberg Jul 28, 2023
ab4036b
Fix violations of G-1050
PhilippSalvisberg Jul 28, 2023
e2ee234
Fix violation of G-4330
PhilippSalvisberg Aug 25, 2023
c21ed65
use plural for array name
PhilippSalvisberg Aug 25, 2023
70e6f28
reuse example of G-4120 in G-4120
PhilippSalvisberg Aug 25, 2023
883ae5f
Fix violation of G-2130
PhilippSalvisberg Aug 25, 2023
9c4b16c
Fix violations of G-1050 and G-2130
PhilippSalvisberg Aug 25, 2023
f315157
Fix violations of G-1050
PhilippSalvisberg Aug 25, 2023
a8fca87
Fix violation of G-5070 and explain violation of G-9113
PhilippSalvisberg Aug 25, 2023
349b915
Fix one violation of G-1050 and explain the other
PhilippSalvisberg Aug 25, 2023
87d1aa7
Fix violations of G-7460
PhilippSalvisberg Aug 25, 2023
ea1e447
Fix violations of G-1050
PhilippSalvisberg Aug 25, 2023
9422bf8
Explain violation of G-1050
PhilippSalvisberg Aug 25, 2023
1910766
Put ever parameter using named notation on a dedicated line
PhilippSalvisberg Aug 25, 2023
20387fb
Fix violations of G-7460
PhilippSalvisberg Aug 25, 2023
ffd91be
Fix violations of G-8310 and reformat code
PhilippSalvisberg Aug 25, 2023
aeec9b4
Fix violation of G-8110
PhilippSalvisberg Aug 25, 2023
6f523eb
Fix violations of G-1050, G-5060, G-7460
PhilippSalvisberg Aug 25, 2023
e04603b
Fix violations of G-2130, G-5040, G-7460, G-8310
PhilippSalvisberg Aug 25, 2023
4b3f497
Fix violations of G-1050 and G-4385
PhilippSalvisberg Aug 25, 2023
fbdd65e
Fix violations of G-8310, G-1050, G-9030, explain G-9030
PhilippSalvisberg Aug 25, 2023
4639692
Fix violations of G-1050, G-8310, explain G-9030
PhilippSalvisberg Sep 1, 2023
d2ea4e1
Fix violations of G-1050, G-8310, G-9040
PhilippSalvisberg Sep 1, 2023
db5611e
Fix violations of G-8310, G-9030, explain G-1050
PhilippSalvisberg Sep 1, 2023
590579b
Fix violations of G-9030
PhilippSalvisberg Sep 1, 2023
35b160a
consistent style of NOSONAR marker
PhilippSalvisberg Sep 1, 2023
8877f3f
Fix violation of G-9030
PhilippSalvisberg Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 6 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: db* CODECOP Issues
run: |
export COP=4.3.0
export VALIDATOR=4.3.0
export COP=4.3.1
export VALIDATOR=4.3.1
wget https://github.com/Trivadis/plsql-cop-cli/releases/download/v$COP/tvdcc-$COP.zip
unzip tvdcc-$COP.zip -d .
wget -P tvdcc-$COP/plugin/ https://github.com/Trivadis/plsql-cop-validators/releases/download/v$VALIDATOR/sonar-plsql-cop-custom-validators-plugin-$VALIDATOR.jar
echo $TVDCC_LIC | base64 -d > tvdcc-$COP/tvdcc.lic
tvdcc-$COP/tvdcc.sh path=docs skip=none html=false excel=false validator=com.trivadis.tvdcc.validators.TrivadisGuidelines3Plus
tvdcc-$COP/tvdcc.sh path=docs skip=0 html=false excel=false validator=com.trivadis.tvdcc.validators.TrivadisGuidelines3Plus
env:
TVDCC_LIC: ${{ secrets.TVDCC_LIC }}
- name: SonarCloud Scan
Expand Down
3 changes: 3 additions & 0 deletions 3 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
/pdf
/docs/9-appendix/PLSQL-and-SQL-Coding-Guidelines.pdf

# Files generated by tvdcc
/tvdcc_report.json

# Distribution files
/dist
/mkdocs_material.egg-info
Expand Down
58 changes: 31 additions & 27 deletions 58 docs/3-coding-style/coding-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,37 @@ Rule | Description
### Example

``` sql
create or replace procedure set_salary(in_employee_id in employees.employee_id%type) is
cursor c_employees(p_employee_id in employees.employee_id%type) is
select last_name
,first_name
,salary
from employees
where employee_id = p_employee_id
order by last_name
,first_name;

r_employee c_employees%rowtype;
l_new_salary employees.salary%type;
begin
open c_employees(p_employee_id => in_employee_id);
fetch c_employees into r_employee;
close c_employees;

new_salary(in_employee_id => in_employee_id
,out_salary => l_new_salary);

-- Check whether salary has changed
if r_employee.salary <> l_new_salary then
update employees
set salary = l_new_salary
where employee_id = in_employee_id;
end if;
end set_salary;
create or replace package body employee_api is
procedure set_salary(in_employee_id in integer) is
co_employee_id constant employees.employee_id%type := in_employee_id;

cursor c_employees(p_employee_id in employees.employee_id%type) is
select last_name
,first_name
,salary
from employees
where employee_id = p_employee_id
order by last_name
,first_name;

r_employee c_employees%rowtype;
l_new_salary employees.salary%type;
begin
open c_employees(p_employee_id => co_employee_id);
fetch c_employees into r_employee;
close c_employees;

new_salary(in_employee_id => in_employee_id
,out_salary => l_new_salary);

-- Check whether salary has changed
if r_employee.salary <> l_new_salary then
update employees
set salary = l_new_salary
where employee_id = in_employee_id;
end if;
end set_salary;
end employee_api;
```

## Code Commenting
Expand Down
4 changes: 2 additions & 2 deletions 4 docs/4-language-usage/1-general/g-1020.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ begin

<<basic_loop>>
loop
exit basic_loop;
exit basic_loop when true;
end loop;

<<for_loop>>
Expand Down Expand Up @@ -78,7 +78,7 @@ begin

<<basic_loop>>
loop
exit basic_loop;
exit basic_loop when true;
end loop basic_loop;

<<for_loop>>
Expand Down
8 changes: 4 additions & 4 deletions 8 docs/4-language-usage/1-general/g-1040.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ Any part of your code, which is no longer used or cannot be reached, should be e
declare
co_dept_purchasing constant departments.department_id%type := 30;
begin
if 2 = 3 then
if 2 = 3 then -- G-1050 violated, dead code detection works with literals only
null; -- some dead code here
end if;

null; -- some enabled code here

<<my_loop>>
loop
exit my_loop;
exit my_loop when true;
null; -- some dead code here
end loop my_loop;

null; -- some other enabled code here

case
when 1 = 1 and 'x' = 'y' then
when 1 = 1 and 'x' = 'y' then -- G-1050 violated, dead code detection works with literals only
null; -- some dead code here
else
null; -- some further enabled code here
Expand All @@ -40,7 +40,7 @@ begin
from employees
where department_id = co_dept_purchasing
or commission_pct is not null
and 5 = 6
and 5 = 6 -- G-1050 violated, dead code detection works with literals only
)
-- "or commission_pct is not null" is dead code
loop
Expand Down
40 changes: 25 additions & 15 deletions 40 docs/4-language-usage/1-general/g-1080.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,34 @@ This rule ignores operators `+`, `*` and `||`, and expressions: `1=1`, `1<>1`, `
## Example (bad)

``` sql
select emp.first_name
,emp.last_name
,emp.salary
,emp.hire_date
from employees emp
where emp.salary > 3000
or emp.salary > 3000
order by emp.last_name,emp.first_name;
declare
co_max_salary constant emp.salary%type := 3000;
begin
select emp.first_name
,emp.last_name
,emp.salary
,emp.hire_date
from employees emp
where emp.salary > co_max_salary
or emp.salary > co_max_salary
order by emp.last_name,emp.first_name;
end;
/
```

## Example (good)

``` sql
select emp.first_name
,emp.last_name
,emp.salary
,emp.hire_date
from employees emp
where emp.salary > 3000
order by emp.last_name,emp.first_name;
declare
co_max_salary constant emp.salary%type := 3000;
begin
select emp.first_name
,emp.last_name
,emp.salary
,emp.hire_date
from employees emp
where emp.salary > co_max_salary
order by emp.last_name,emp.first_name;
end;
/
```
10 changes: 6 additions & 4 deletions 10 docs/4-language-usage/2-variables-and-types/1-general/g-2135.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ Expending resources calculating and assigning values to a local variable and nev
create or replace package body my_package is
procedure my_proc is
co_employee_id constant employees.employee_id%type := 1042;
co_hello constant type_up.text := 'Hello, ';
l_last_name employees.last_name%type;
l_message varchar2(100 char);
l_message types_up.text;
begin
select emp.last_name
into l_last_name
from employees emp
where emp.employee_id = co_employee_id;

l_message := 'Hello, ' || l_last_name;
l_message := co_hello || l_last_name;
exception
when no_data_found then
null; -- handle_no_data_found;
Expand All @@ -38,15 +39,16 @@ end my_package;
create or replace package body my_package is
procedure my_proc is
co_employee_id constant employees.employee_id%type := 1042;
co_hello constant type_up.text := 'Hello, ';
l_last_name employees.last_name%type;
l_message varchar2(100 char);
l_message types_up.text;
begin
select emp.last_name
into l_last_name
from employees emp
where emp.employee_id = co_employee_id;

l_message := 'Hello, ' || l_last_name;
l_message := co_hello || l_last_name;

message_api.send_message(l_message);
exception
Expand Down
26 changes: 16 additions & 10 deletions 26 docs/4-language-usage/2-variables-and-types/1-general/g-2145.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ There is no reason to assign a variable to itself. It is either a redundant stat

``` sql
declare
l_function_result pls_integer;
l_parallel_degree pls_integer;
co_parallel_degree constant types_up.name%type := 'parallel_degree';
l_function_result pls_integer;
l_parallel_degree pls_integer;
begin
l_function_result := maintenance.get_config('parallel_degree');
l_parallel_degree := l_parallel_degree;
do_something(l_parallel_degree);
l_function_result := maintenance.get_config(co_parallel_degree);
if l_function_result is not null then
l_parallel_degree := l_parallel_degree;
do_something(l_parallel_degree);
end if;
end;
/
```
Expand All @@ -25,12 +28,15 @@ end;

``` sql
declare
l_function_result pls_integer;
l_parallel_degree pls_integer;
co_parallel_degree constant types_up.name%type := 'parallel_degree';
l_function_result pls_integer;
l_parallel_degree pls_integer;
begin
l_function_result := maintenance.get_config('parallel_degree');
l_parallel_degree := l_function_result;
do_something(l_parallel_degree);
l_function_result := maintenance.get_config(co_parallel_degree);
if l_function_result is not null then
l_parallel_degree := l_function_result;
do_something(l_parallel_degree);
end if;
end;
/
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Quoted identifiers make your code hard to read and maintain.

``` sql
declare
"sal+comm" integer;
"my constant" constant integer := 1;
"my exception" exception;
"sal+comm" integer; -- violates also naming conventions (G-9102)
"my constant" constant integer := 1; -- violates also naming conventions (G-9114)
"my exception" exception; -- violates also naming conventsion (G-9113)
begin
"sal+comm" := "my constant";
do_something("sal+comm");
exception
when "my exception" then
null;
Expand All @@ -32,6 +33,7 @@ declare
e_my_exception exception;
begin
l_sal_comm := co_my_constant;
do_something(l_sal_comm);
exception
when e_my_exception then
null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ You should ensure that the name you have chosen well defines its purpose and usa
``` sql
declare
i integer;
c constant integer := 1;
e exception;
c constant integer := 1; -- violates also naming conventions (G-9114)
e exception; -- violates also naming conventions (G-9113)
begin
i := c;
do_something(i);
exception
when e then
null;
Expand All @@ -32,6 +33,7 @@ declare
e_my_exception exception;
begin
l_sal_comm := co_my_constant;
do_something(l_sal_comm);
exception
when e_my_exception then
null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@ If you do not specify precision `number` is defaulted to 38 or the maximum suppo
## Example (bad)

``` sql
create or replace package body constants_up is
co_small_increase constant number := 0.1;

function small_increase return number is
begin
return co_small_increase;
end small_increase;
end constants_up;
create or replace package types_up is
subtype salary_type is number;
end types_up;
/
```

## Example (good)

``` sql
create or replace package body constants_up is
co_small_increase constant number(5,1) := 0.1;

function small_increase return number is
begin
return co_small_increase;
end small_increase;
end constants_up;
create or replace package types_up is
subtype salary_type is number(5,1);
end types_up;
/
```
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.