Skip to content

Commit 42a86a1

Browse files
committed
Fix #93 - Created awk script to generate appendix table. Generated fresh appendix.
1 parent c25b7e2 commit 42a86a1

File tree

9 files changed

+233
-25
lines changed

9 files changed

+233
-25
lines changed

docs/4-language-usage/4-control-structures/3-flow-control/g-4380.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# G-4380 Try to label your EXIT WHEN statements.
1+
# G-4380: Try to label your EXIT WHEN statements.
22

33
!!! tip "Minor"
44
Maintainability

docs/4-language-usage/7-stored-objects/4-functions/g-7430.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# G-7430: Try to use no more than one RETURN statement within a function.
22

33
!!! warning "Major"
4-
Will have a medium/potential impact on the maintenance cost.
54
Maintainability, Testability
65

76
## Reason

docs/9-appendix/appendix.md

Lines changed: 41 additions & 23 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## A - PL/SQL & SQL Coding Guidelines as PDF
2+
3+
These guidelines are primarily produced in [HTML](https://trivadis.github.io/plsql-and-sql-coding-guidelines/) using [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/).
4+
5+
However, we provide these guidelines also as [PDF](PLSQL-and-SQL-Coding-Guidelines.pdf) produced by [wkhtmltopdf](https://wkhtmltopdf.org/).
6+
7+
[![Trivadis PL/SQL & SQl Coding Guidelines in PDF format](../images/pdf-thumbnail.png)](PLSQL-and-SQL-Coding-Guidelines.pdf)
8+
9+
The formatting is not perfect, but it should be adequate for those who want to work with offline documents.
10+

docs/_appendixdata/appendix_b.map

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#Whitespace separated (for example tab) conversion table between OLD ID and NEW ID
2+
1 1010
3+
2 1020
4+
3 1030
5+
4 1040
6+
5 1050
7+
6 1060
8+
7 1070
9+
8 2110
10+
9 2120
11+
10 2130
12+
11 2140
13+
12 2150
14+
13 2160
15+
14 2170
16+
15 2180
17+
16 2185
18+
17 2190
19+
18 2210
20+
19 2220
21+
20 2310
22+
21 2320
23+
22 2330
24+
23 2340
25+
24 2410
26+
25 2510
27+
26 3110
28+
27 3120
29+
28 3130
30+
29 3140
31+
30 3210
32+
31 4110
33+
32 4120
34+
33 4130
35+
34 4140
36+
35 4210
37+
36 4220
38+
37 4230
39+
38 4240
40+
39 4310
41+
40 4320
42+
41 4330
43+
42 4340
44+
43 4350
45+
44 4360
46+
45 4370
47+
46 4375
48+
47 4380
49+
48 4385
50+
49 4390
51+
50 4395
52+
51 5020
53+
52 5030
54+
53 5040
55+
55 5050
56+
56 5060
57+
57 5070
58+
58 6010
59+
59 6020
60+
60 7110
61+
61 7120
62+
62 7130
63+
63 7140
64+
64 7150
65+
65 7210
66+
66 7220
67+
67 7230
68+
68 7240
69+
69 7310
70+
70 7320
71+
71 7410
72+
73 7420
73+
72 7430
74+
74 7440
75+
75 7450
76+
76 7510
77+
77 7710
78+
78 8110
79+
79 8210
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## B - Mapping new guidelines to prior versions
2+
3+
Old<br/>Id | New<br/>Id | Text | Severity | Change-<br/>ability | Effi-<br/>ciency | Maintain-<br/>ability | Port-<br/>ability | Reli-<br/>ability | Reus-<br/>ability | Secu-<br/>rity | Test-<br/>ability
4+
:---: | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---:

tools/genappendix.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
DATA_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
4+
docker run -v ${DATA_DIR}:/data --rm -it trivadis/mktools bash -c "cd /data; ./tools/run-in-container/genappendix.sh docs/9-appendix/appendix.md"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
OUTFILE=$1
4+
5+
cd /data
6+
7+
echo "# Appendix " > $OUTFILE
8+
echo "" >> $OUTFILE
9+
10+
cat docs/_appendixdata/appendix_a.md.template >> $OUTFILE
11+
cat docs/_appendixdata/appendix_b.md.template >> $OUTFILE
12+
13+
find docs/4-language-usage/ -name g-*.md | xargs head -n 4 -q | tools/run-in-container/genappendix_b_table.awk >> $OUTFILE
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/gawk -f
2+
BEGIN {
3+
# Set output field separator
4+
OFS=" | ";
5+
# Initialize mapping associative array
6+
while ((getline < "docs/_appendixdata/appendix_b.map") > 0) {
7+
if ($1 ~ /^[[:digit:]]+$/ && $2 ~ /^[[:digit:]]+$/) {
8+
old_id_array[$2]=$1;
9+
}
10+
}
11+
}
12+
{
13+
# Input is a stream of the first 4 lines of every .md file in section 4-language-usage
14+
if ($1 == "#" && $2 ~ /^G-[[:digit:]]+/ ) {
15+
# From the first of the 4 lines we grab the G- new id
16+
new_id=substr($2,3,length($2)-3);
17+
# Get old id from mapping array
18+
old_id=old_id_array[new_id];
19+
# Default to n/a
20+
if (old_id == "") {old_id="n/a"}
21+
# The text of the rule is most of the first line
22+
text=$0;
23+
# We just remove the # G-<id>: from the beginning of the text
24+
dummy=sub(/^# G-[[:digit:]]+: /,"",text);
25+
26+
# Get the second of the 4 lines and ignore it, it's empty
27+
getline;
28+
29+
# Get the third of the 4 lines
30+
getline;
31+
# Retrieve the severity field from the third line
32+
severity=substr($3,2,length($3)-2);
33+
34+
# Get the fourth and last of the 4 lines
35+
getline;
36+
# If the char array was filled from the last iteration, we need to empty it here
37+
char[1]="";
38+
char[2]="";
39+
char[3]="";
40+
char[4]="";
41+
char[5]="";
42+
char[6]="";
43+
char[7]="";
44+
char[8]="";
45+
46+
# The fourth line is a comma-separated list of characteristics - split them into an array
47+
no_of_characteristics=split($0,characteristics,",");
48+
for (i in characteristics) {
49+
# If the characteristics array value is one of 8 values, we put a mark in the corresponding value of char array
50+
if (characteristics[i] ~ /Changeability/ ) {char[1]="&#10008;"}
51+
if (characteristics[i] ~ /Efficiency/ ) {char[2]="&#10008;"}
52+
if (characteristics[i] ~ /Maintainability/ ) {char[3]="&#10008;"}
53+
if (characteristics[i] ~ /Portability/ ) {char[4]="&#10008;"}
54+
if (characteristics[i] ~ /Reliability/ ) {char[5]="&#10008;"}
55+
if (characteristics[i] ~ /Reusability/ ) {char[6]="&#10008;"}
56+
if (characteristics[i] ~ /Security/ ) {char[7]="&#10008;"}
57+
if (characteristics[i] ~ /Testability/ ) {char[8]="&#10008;"}
58+
59+
# If the characteristics value is something other than these 8 values, we output an error in the text so it'll be noticed
60+
if (!(characteristics[i] ~ /Changeability/ || \
61+
characteristics[i] ~ /Efficiency/ || \
62+
characteristics[i] ~ /Maintainability/ || \
63+
characteristics[i] ~ /Portability/ || \
64+
characteristics[i] ~ /Reliability/ || \
65+
characteristics[i] ~ /Reusability/ || \
66+
characteristics[i] ~ /Security/ || \
67+
characteristics[i] ~ /Testability/ )) {text="!!!CHARACTERISTIC ERROR!!!"}
68+
}
69+
70+
# Output the fields of the markdown table in appendix B
71+
print old_id, new_id, text, severity, char[1], char[2], char[3], char[4], char[5], char[6], char[7], char[8];
72+
73+
# Special handling - between rule G-5040 and G-5050 we output the old rule 54 that is not mapped to any new rule
74+
if (new_id == "5040") {
75+
print "54 | n/a | Avoid use of EXCEPTION_INIT pragma for a 20nnn error. | Major | | | | | &#10008; | | | ";
76+
}
77+
78+
# Done handling the 4 lines of one .md file. Next 4 lines will be from another .md file and be handled in the next iteration.
79+
}
80+
}
81+

0 commit comments

Comments
 (0)