Skip to content

Commit

Permalink
Merge pull request #218 from Trivadis/feature/issue-210-highlight
Browse files Browse the repository at this point in the history
Highlight violating lines in bad examples and fixes in good examples
  • Loading branch information
PhilippSalvisberg authored Mar 19, 2024
2 parents 639ea44 + 035aa2b commit 0cb490e
Show file tree
Hide file tree
Showing 124 changed files with 271 additions and 273 deletions.
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1010.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ It's a good alternative for comments to indicate the start and end of a named pr

## Example (bad)

``` sql
``` sql hl_lines="2 4 6 8"
begin
begin
null;
Expand All @@ -24,7 +24,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2 5 7 10"
begin
<<prepare_data>>
begin
Expand Down
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1020.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Use a label directly in front of loops and nested anonymous blocks:

## Example (bad)

``` sql
``` sql hl_lines="10 15 22 27 33"
declare
i integer;
co_min_value constant integer := 1;
Expand Down Expand Up @@ -52,7 +52,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="10 15 22 27 33"
declare
i integer;
co_min_value constant integer := 1;
Expand Down
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1030.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Unused variables decrease the maintainability and readability of your code.

## Example (bad)

``` sql
``` sql hl_lines="4 6"
create or replace package body my_package is
procedure my_proc is
l_last_name employees.last_name%type;
Expand All @@ -33,7 +33,7 @@ end my_package;

## Example (good)

``` sql
``` sql hl_lines="5 12"
create or replace package body my_package is
procedure my_proc is
l_last_name employees.last_name%type;
Expand Down
2 changes: 1 addition & 1 deletion docs/4-language-usage/1-general/g-1040.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Any part of your code, which is no longer used or cannot be reached, should be e

## Example (bad)

``` sql
``` sql hl_lines="4 12 19 31 38"
declare
co_dept_purchasing constant departments.department_id%type := 30;
begin
Expand Down
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1050.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To avoid an extreme plethora of constants or false positives, a literal should n

## Example (bad)

``` sql
``` sql hl_lines="2-4"
begin
some_api.setup(in_department_id => 10);
some_api.process(in_department_id => 10);
Expand All @@ -24,7 +24,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="7-9"
create or replace package constants_up is
co_dept_admin constant departments.department_id%type := 10;
end constants_up;
Expand Down
2 changes: 1 addition & 1 deletion docs/4-language-usage/1-general/g-1060.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Instead of using `rowid` for later reference to the original row one should use

## Example (bad)

``` sql
``` sql hl_lines="6 11"
begin
insert into employees_log (
employee_id
Expand Down
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1070.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Having an end-of-comment within a block comment will end that block-comment. Thi

## Example (bad)

``` sql
``` sql hl_lines="2 4"
begin
/* comment one -- nested comment two */
null;
Expand All @@ -21,7 +21,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2 4"
begin
/* comment one, comment two */
null;
Expand Down
4 changes: 2 additions & 2 deletions docs/4-language-usage/1-general/g-1080.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This rule ignores operators `+`, `*` and `||`, and expressions: `1=1`, `1<>1`, `

## Example (bad)

``` sql
``` sql hl_lines="9 10"
declare
co_max_salary constant emp.salary%type := 3000;
begin
Expand All @@ -29,7 +29,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="9"
declare
co_max_salary constant emp.salary%type := 3000;
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Changing the size of the database column last_name in the employees table from `

## Example (bad)

``` sql
``` sql hl_lines="3"
create or replace package body my_package is
procedure my_proc is
l_last_name varchar2(20 char);
Expand All @@ -31,7 +31,7 @@ end my_package;

## Example (good)

``` sql
``` sql hl_lines="3"
create or replace package body my_package is
procedure my_proc is
l_last_name employees.last_name%type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A single location could be either a type specification package or the database (

## Example (bad)

``` sql
``` sql hl_lines="3"
create or replace package body my_package is
procedure my_proc is
subtype big_string_type is varchar2(1000 char);
Expand All @@ -26,7 +26,7 @@ end my_package;

## Example (good)

``` sql
``` sql hl_lines="8"
create or replace package types_up is
subtype big_string_type is varchar2(1000 char);
end types_up;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Type | Usage

## Example (bad)

``` sql
``` sql hl_lines="3"
create or replace package body my_package is
procedure my_proc is
l_note varchar2(1000 char);
Expand All @@ -34,7 +34,7 @@ end my_package;

## Example (good)

``` sql
``` sql hl_lines="8"
create or replace package types_up is
subtype big_string_type is varchar2(1000 char);
end types_up;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Expending resources calculating and assigning values to a local variable and nev

## Example (bad)

``` sql
``` sql hl_lines="13"
create or replace package body my_package is
procedure my_proc is
co_employee_id constant employees.employee_id%type := 1042;
Expand All @@ -35,7 +35,7 @@ end my_package;

## Example (good)

``` sql
``` sql hl_lines="13 15"
create or replace package body my_package is
procedure my_proc is
co_employee_id constant employees.employee_id%type := 1042;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Variables are initialized to `null` by default.

## Example (bad)

``` sql
``` sql hl_lines="2"
declare
l_note big_string_type := null;
begin
Expand All @@ -20,7 +20,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2"
declare
l_note big_string_type;
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ There is no reason to assign a variable to itself. It is either a redundant stat

## Example (bad)

``` sql
``` sql hl_lines="8"
declare
co_parallel_degree constant types_up.name%type := 'parallel_degree';
l_function_result pls_integer;
Expand All @@ -26,7 +26,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="8"
declare
co_parallel_degree constant types_up.name%type := 'parallel_degree';
l_function_result pls_integer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `null` value can cause confusion both from the standpoint of code review and

## Example (bad)

``` sql
``` sql hl_lines="4"
declare
l_value integer;
begin
Expand All @@ -22,7 +22,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="4"
declare
l_value integer;
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If your initialization fails, you will not be able to handle the error in your e

## Example (bad)

``` sql
``` sql hl_lines="3 4"
declare
co_department_id constant integer := 100;
l_department_name departments.department_name%type :=
Expand All @@ -22,7 +22,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="8"
declare
co_department_id constant integer := 100;
co_unkown_name constant departments.department_name%type := 'unknown';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The readability of your code will be higher when you do not overload variables.

## Example (bad)

``` sql
``` sql hl_lines="7 11"
begin
<<main>>
declare
Expand All @@ -33,7 +33,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="7 11"
begin
<<main>>
declare
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Quoted identifiers make your code hard to read and maintain.

## Example (bad)

``` sql
``` sql hl_lines="2-4"
declare
"sal+comm" integer; -- violates also naming conventions (G-9102)
"my constant" constant integer := 1; -- violates also naming conventions (G-9114)
Expand All @@ -26,7 +26,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2-4"
declare
l_sal_comm integer;
co_my_constant constant integer := 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You should ensure that the name you have chosen well defines its purpose and usa

## Example (bad)

``` sql
``` sql hl_lines="2-4"
declare
i integer;
c constant integer := 1; -- violates also naming conventions (G-9114)
Expand All @@ -26,7 +26,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2-4"
declare
l_sal_comm integer;
co_my_constant constant integer := 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Use of `rowid` or `urowid` means that your SQL statement will not be portable to

## Example (bad)

``` sql
``` sql hl_lines="7"
declare
l_department_name departments.department_name%type;
l_rowid rowid;
Expand All @@ -25,7 +25,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="7"
declare
l_department_name departments.department_name%type;
l_department_id departments.department_id%type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If you do not specify precision `number` is defaulted to 38 or the maximum suppo

## Example (bad)

``` sql
``` sql hl_lines="2"
create or replace package types_up is
subtype salary_type is number;
end types_up;
Expand All @@ -18,7 +18,7 @@ end types_up;

## Example (good)

``` sql
``` sql hl_lines="2"
create or replace package types_up is
subtype salary_type is number(5,1);
end types_up;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are many reasons to use `pls_integer` instead of `number`:

## Example (bad)

``` sql
``` sql hl_lines="2"
declare
l_result number(9,0) := 0; -- violates also G-2130, G-2230
co_upper_bound constant pls_integer := 1e8;
Expand All @@ -33,7 +33,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2"
declare
l_result pls_integer := 0;
co_upper_bound constant pls_integer := 1e8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ With Oracle Database 11g, the new data type `simple_integer` has been introduced

## Example (bad)

``` sql
``` sql hl_lines="2"
declare
l_result number(9,0) := 0; -- violates also G-2130, G-2220
co_upper_bound constant pls_integer := 1e8;
Expand All @@ -31,7 +31,7 @@ end;

## Example (good)

``` sql
``` sql hl_lines="2"
declare
l_result simple_integer := 0;
co_upper_bound constant pls_integer := 1e8;
Expand Down
Loading

0 comments on commit 0cb490e

Please sign in to comment.