@neralabs/rerail-pack-sql 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/pack.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "sql",
4
4
  "name": "SQL",
5
5
  "category": "language",
6
- "covers": "No rules yet: its 22 SQLFluff 4.4.0 ports are candidates until they pass the V1 rule validation gates.",
6
+ "covers": "19 SQLFluff 4.4.0 rules ported to Rerail, 17 of them on and 2 off until turned on, each scored against SQLFluff's own recorded findings on its tests; 3 more ports are candidates until they pass the port readiness gates.",
7
7
  "reason": "matches SQL",
8
8
  "match": {
9
9
  "any": [
@@ -15,5 +15,122 @@
15
15
  }
16
16
  ]
17
17
  },
18
- "rules": []
18
+ "rules": [
19
+ {
20
+ "id": "sqlfluff-al04-aliasing-unique-table",
21
+ "document": "rules/sqlfluff-al04-aliasing-unique-table.json",
22
+ "title": "SQLFluff AL04: Aliasing unique table",
23
+ "group": "SQLFluff"
24
+ },
25
+ {
26
+ "id": "sqlfluff-al08-aliasing-unique-column",
27
+ "document": "rules/sqlfluff-al08-aliasing-unique-column.json",
28
+ "title": "SQLFluff AL08: Aliasing unique column",
29
+ "group": "SQLFluff"
30
+ },
31
+ {
32
+ "id": "sqlfluff-al09-aliasing-self-alias-column",
33
+ "document": "rules/sqlfluff-al09-aliasing-self-alias-column.json",
34
+ "title": "SQLFluff AL09: Aliasing self alias column",
35
+ "group": "SQLFluff"
36
+ },
37
+ {
38
+ "id": "sqlfluff-am01-ambiguous-distinct",
39
+ "document": "rules/sqlfluff-am01-ambiguous-distinct.json",
40
+ "title": "SQLFluff AM01: Ambiguous distinct",
41
+ "group": "SQLFluff"
42
+ },
43
+ {
44
+ "id": "sqlfluff-am05-ambiguous-join",
45
+ "document": "rules/sqlfluff-am05-ambiguous-join.json",
46
+ "title": "SQLFluff AM05: Ambiguous join",
47
+ "group": "SQLFluff"
48
+ },
49
+ {
50
+ "id": "sqlfluff-am09-ambiguous-order-by-limit",
51
+ "document": "rules/sqlfluff-am09-ambiguous-order-by-limit.json",
52
+ "title": "SQLFluff AM09: Ambiguous order by limit",
53
+ "group": "SQLFluff"
54
+ },
55
+ {
56
+ "id": "sqlfluff-cv02-convention-coalesce",
57
+ "document": "rules/sqlfluff-cv02-convention-coalesce.json",
58
+ "title": "SQLFluff CV02: Convention coalesce",
59
+ "group": "SQLFluff"
60
+ },
61
+ {
62
+ "id": "sqlfluff-cv04-convention-count-rows",
63
+ "document": "rules/sqlfluff-cv04-convention-count-rows.json",
64
+ "title": "SQLFluff CV04: Convention count rows",
65
+ "group": "SQLFluff"
66
+ },
67
+ {
68
+ "id": "sqlfluff-cv05-convention-is-null",
69
+ "document": "rules/sqlfluff-cv05-convention-is-null.json",
70
+ "title": "SQLFluff CV05: Convention is null",
71
+ "group": "SQLFluff"
72
+ },
73
+ {
74
+ "id": "sqlfluff-cv08-convention-left-join",
75
+ "document": "rules/sqlfluff-cv08-convention-left-join.json",
76
+ "title": "SQLFluff CV08: Convention left join",
77
+ "group": "SQLFluff"
78
+ },
79
+ {
80
+ "id": "sqlfluff-pg01-postgres-excessive-locks",
81
+ "document": "rules/sqlfluff-pg01-postgres-excessive-locks.json",
82
+ "title": "SQLFluff PG01: Postgres excessive locks",
83
+ "group": "SQLFluff",
84
+ "on": false
85
+ },
86
+ {
87
+ "id": "sqlfluff-pg02-postgres-not-valid-foreign-key",
88
+ "document": "rules/sqlfluff-pg02-postgres-not-valid-foreign-key.json",
89
+ "title": "SQLFluff PG02: Postgres not valid foreign key",
90
+ "group": "SQLFluff",
91
+ "on": false
92
+ },
93
+ {
94
+ "id": "sqlfluff-rf04-references-keywords",
95
+ "document": "rules/sqlfluff-rf04-references-keywords.json",
96
+ "title": "SQLFluff RF04: References keywords",
97
+ "group": "SQLFluff"
98
+ },
99
+ {
100
+ "id": "sqlfluff-rf05-references-special-chars",
101
+ "document": "rules/sqlfluff-rf05-references-special-chars.json",
102
+ "title": "SQLFluff RF05: References special chars",
103
+ "group": "SQLFluff"
104
+ },
105
+ {
106
+ "id": "sqlfluff-rf06-references-quoting",
107
+ "document": "rules/sqlfluff-rf06-references-quoting.json",
108
+ "title": "SQLFluff RF06: References quoting",
109
+ "group": "SQLFluff"
110
+ },
111
+ {
112
+ "id": "sqlfluff-st01-structure-else-null",
113
+ "document": "rules/sqlfluff-st01-structure-else-null.json",
114
+ "title": "SQLFluff ST01: Structure else null",
115
+ "group": "SQLFluff"
116
+ },
117
+ {
118
+ "id": "sqlfluff-st02-structure-simple-case",
119
+ "document": "rules/sqlfluff-st02-structure-simple-case.json",
120
+ "title": "SQLFluff ST02: Structure simple case",
121
+ "group": "SQLFluff"
122
+ },
123
+ {
124
+ "id": "sqlfluff-st08-structure-distinct",
125
+ "document": "rules/sqlfluff-st08-structure-distinct.json",
126
+ "title": "SQLFluff ST08: Structure distinct",
127
+ "group": "SQLFluff"
128
+ },
129
+ {
130
+ "id": "sqlfluff-st10-structure-constant-expression",
131
+ "document": "rules/sqlfluff-st10-structure-constant-expression.json",
132
+ "title": "SQLFluff ST10: Structure constant expression",
133
+ "group": "SQLFluff"
134
+ }
135
+ ]
19
136
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neralabs/rerail-pack-sql",
3
- "version": "0.1.2",
4
- "description": "Rerail rule pack: no rules yet; its SQLFluff ports are candidates until they pass the V1 rule validation gates.",
3
+ "version": "0.1.4",
4
+ "description": "Rerail rule pack: SQLFluff rules ported to Rerail code rules.",
5
5
  "license": "Apache-2.0 AND MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -0,0 +1,252 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-al04-aliasing-unique-table",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Give every table in a SQL FROM clause a unique alias; a repeated alias makes column references ambiguous.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "duplicate-explicit-alias",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "utils": {
20
+ "value-table-function": {
21
+ "has": {
22
+ "kind": "invocation",
23
+ "stopBy": {
24
+ "kind": "subquery"
25
+ },
26
+ "has": {
27
+ "kind": "object_reference",
28
+ "stopBy": "neighbor",
29
+ "regex": "(?i)^(?:unnest|generate_series)$"
30
+ }
31
+ }
32
+ },
33
+ "named-b": {
34
+ "not": {
35
+ "matches": "value-table-function"
36
+ },
37
+ "any": [
38
+ {
39
+ "has": {
40
+ "field": "alias",
41
+ "kind": "identifier",
42
+ "pattern": "$B"
43
+ }
44
+ },
45
+ {
46
+ "not": {
47
+ "has": {
48
+ "field": "alias",
49
+ "regex": "."
50
+ }
51
+ },
52
+ "has": {
53
+ "kind": "object_reference",
54
+ "stopBy": "neighbor",
55
+ "has": {
56
+ "field": "name",
57
+ "kind": "identifier",
58
+ "pattern": "$B"
59
+ }
60
+ }
61
+ }
62
+ ]
63
+ },
64
+ "from-item-b": {
65
+ "any": [
66
+ {
67
+ "kind": "relation",
68
+ "matches": "named-b"
69
+ },
70
+ {
71
+ "kind": "join",
72
+ "has": {
73
+ "kind": "relation",
74
+ "stopBy": "neighbor",
75
+ "matches": "named-b"
76
+ }
77
+ }
78
+ ]
79
+ },
80
+ "duplicated-entry": {
81
+ "inside": {
82
+ "kind": "from",
83
+ "stopBy": "neighbor",
84
+ "follows": {
85
+ "kind": "select",
86
+ "stopBy": "end"
87
+ }
88
+ },
89
+ "any": [
90
+ {
91
+ "follows": {
92
+ "stopBy": "end",
93
+ "matches": "from-item-b",
94
+ "compare": {
95
+ "left": "AN",
96
+ "op": "eq",
97
+ "right": "BN",
98
+ "text": "source"
99
+ }
100
+ }
101
+ },
102
+ {
103
+ "inside": {
104
+ "kind": "from",
105
+ "stopBy": "neighbor",
106
+ "inside": {
107
+ "stopBy": "neighbor",
108
+ "has": {
109
+ "kind": "subquery",
110
+ "stopBy": {
111
+ "kind": "subquery"
112
+ },
113
+ "not": {
114
+ "inside": {
115
+ "kind": "relation",
116
+ "stopBy": "neighbor",
117
+ "pattern": "$R2",
118
+ "compare": {
119
+ "left": "R",
120
+ "op": "eq",
121
+ "right": "R2",
122
+ "text": "node"
123
+ }
124
+ }
125
+ },
126
+ "has": {
127
+ "kind": "from",
128
+ "stopBy": "neighbor",
129
+ "has": {
130
+ "stopBy": "neighbor",
131
+ "matches": "from-item-b",
132
+ "compare": {
133
+ "left": "AN",
134
+ "op": "eq",
135
+ "right": "BN",
136
+ "text": "source"
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ ]
145
+ }
146
+ },
147
+ "rule": {
148
+ "kind": "relation",
149
+ "pattern": "$R",
150
+ "all": [
151
+ {
152
+ "any": [
153
+ {
154
+ "has": {
155
+ "field": "alias",
156
+ "kind": "identifier",
157
+ "pattern": "$A"
158
+ }
159
+ },
160
+ {
161
+ "not": {
162
+ "has": {
163
+ "field": "alias",
164
+ "regex": "."
165
+ }
166
+ },
167
+ "has": {
168
+ "kind": "object_reference",
169
+ "stopBy": "neighbor",
170
+ "has": {
171
+ "field": "name",
172
+ "kind": "identifier",
173
+ "pattern": "$A"
174
+ }
175
+ }
176
+ }
177
+ ]
178
+ },
179
+ {
180
+ "not": {
181
+ "matches": "value-table-function"
182
+ }
183
+ },
184
+ {
185
+ "any": [
186
+ {
187
+ "matches": "duplicated-entry"
188
+ },
189
+ {
190
+ "inside": {
191
+ "kind": "join",
192
+ "stopBy": "neighbor",
193
+ "matches": "duplicated-entry"
194
+ }
195
+ }
196
+ ]
197
+ }
198
+ ]
199
+ },
200
+ "transform": {
201
+ "AQ": {
202
+ "replace": {
203
+ "source": "$A",
204
+ "replace": "^\"([\\s\\S]*)\"$",
205
+ "by": "$1"
206
+ }
207
+ },
208
+ "AN": {
209
+ "replace": {
210
+ "source": "$AQ",
211
+ "replace": "\"\"",
212
+ "by": "\""
213
+ }
214
+ },
215
+ "BQ": {
216
+ "replace": {
217
+ "source": "$B",
218
+ "replace": "^\"([\\s\\S]*)\"$",
219
+ "by": "$1"
220
+ }
221
+ },
222
+ "BN": {
223
+ "replace": {
224
+ "source": "$BQ",
225
+ "replace": "\"\"",
226
+ "by": "\""
227
+ }
228
+ }
229
+ }
230
+ }
231
+ },
232
+ "violation": {
233
+ "anchor": "capture.A",
234
+ "code": "AL04",
235
+ "message": "Give this table a different alias; '$A' already names another table in this query.",
236
+ "suppress": {
237
+ "sqlfluff": {
238
+ "rules": [
239
+ "AL04",
240
+ "L020",
241
+ "aliasing",
242
+ "aliasing.unique",
243
+ "aliasing.unique.table",
244
+ "all",
245
+ "core"
246
+ ]
247
+ }
248
+ }
249
+ }
250
+ }
251
+ ]
252
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-al08-aliasing-unique-column",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Keep column names and aliases unique within a SQL SELECT list, ignoring case and quotes; duplicate output columns are ambiguous.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "duplicate-column-name",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "rule": {
20
+ "kind": "term",
21
+ "inside": {
22
+ "kind": "select_expression",
23
+ "stopBy": "neighbor"
24
+ },
25
+ "all": [
26
+ {
27
+ "any": [
28
+ {
29
+ "has": {
30
+ "field": "alias",
31
+ "kind": "identifier",
32
+ "pattern": "$A"
33
+ }
34
+ },
35
+ {
36
+ "not": {
37
+ "has": {
38
+ "field": "alias",
39
+ "regex": "."
40
+ }
41
+ },
42
+ "has": {
43
+ "field": "value",
44
+ "kind": "field",
45
+ "has": {
46
+ "field": "name",
47
+ "kind": "identifier",
48
+ "pattern": "$A"
49
+ }
50
+ }
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "follows": {
56
+ "kind": "term",
57
+ "stopBy": "end",
58
+ "compare": {
59
+ "left": "A",
60
+ "op": "eq",
61
+ "right": "B",
62
+ "text": "unquoted",
63
+ "collation": "fold-upper"
64
+ },
65
+ "any": [
66
+ {
67
+ "has": {
68
+ "field": "alias",
69
+ "kind": "identifier",
70
+ "pattern": "$B"
71
+ }
72
+ },
73
+ {
74
+ "not": {
75
+ "has": {
76
+ "field": "alias",
77
+ "regex": "."
78
+ }
79
+ },
80
+ "has": {
81
+ "field": "value",
82
+ "kind": "field",
83
+ "has": {
84
+ "field": "name",
85
+ "kind": "identifier",
86
+ "pattern": "$B"
87
+ }
88
+ }
89
+ }
90
+ ]
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ },
97
+ "violation": {
98
+ "anchor": "capture.A",
99
+ "code": "AL08",
100
+ "message": "Reuse of column alias.",
101
+ "suppress": {
102
+ "sqlfluff": {
103
+ "rules": [
104
+ "AL08",
105
+ "aliasing",
106
+ "aliasing.unique",
107
+ "aliasing.unique.column",
108
+ "all",
109
+ "core"
110
+ ]
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ]
116
+ }
@@ -0,0 +1,162 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-al09-aliasing-self-alias-column",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Don't alias a SQL column to its own name; if the alias is meant to change the name's case, quote it to make that explicit.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "exact-self-alias",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "rule": {
20
+ "kind": "term",
21
+ "inside": {
22
+ "kind": "select_expression",
23
+ "stopBy": "neighbor"
24
+ },
25
+ "all": [
26
+ {
27
+ "has": {
28
+ "field": "value",
29
+ "kind": "field",
30
+ "has": {
31
+ "field": "name",
32
+ "kind": "identifier",
33
+ "pattern": "$C"
34
+ }
35
+ }
36
+ },
37
+ {
38
+ "has": {
39
+ "field": "alias",
40
+ "kind": "identifier",
41
+ "pattern": "$A"
42
+ }
43
+ },
44
+ {
45
+ "compare": {
46
+ "left": "C",
47
+ "op": "eq",
48
+ "right": "A",
49
+ "text": "source"
50
+ }
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ },
56
+ "violation": {
57
+ "anchor": "witness.start",
58
+ "code": "AL09",
59
+ "message": "Column should not be self-aliased.",
60
+ "suppress": {
61
+ "sqlfluff": {
62
+ "rules": [
63
+ "AL09",
64
+ "aliasing",
65
+ "aliasing.self_alias.column",
66
+ "all",
67
+ "core"
68
+ ]
69
+ }
70
+ }
71
+ }
72
+ },
73
+ {
74
+ "id": "ambiguous-unquoted-self-alias",
75
+ "forbid": {
76
+ "ast": {
77
+ "language": "sql",
78
+ "rule": {
79
+ "kind": "term",
80
+ "inside": {
81
+ "kind": "select_expression",
82
+ "stopBy": "neighbor"
83
+ },
84
+ "all": [
85
+ {
86
+ "has": {
87
+ "field": "value",
88
+ "kind": "field",
89
+ "has": {
90
+ "field": "name",
91
+ "kind": "identifier",
92
+ "pattern": "$C"
93
+ }
94
+ }
95
+ },
96
+ {
97
+ "has": {
98
+ "field": "alias",
99
+ "kind": "identifier",
100
+ "pattern": "$A"
101
+ }
102
+ },
103
+ {
104
+ "compare": {
105
+ "left": "C",
106
+ "op": "ne",
107
+ "right": "A",
108
+ "text": "source"
109
+ }
110
+ },
111
+ {
112
+ "compare": {
113
+ "left": "C",
114
+ "op": "eq",
115
+ "right": "A",
116
+ "text": "source",
117
+ "collation": "fold-upper"
118
+ }
119
+ },
120
+ {
121
+ "not": {
122
+ "has": {
123
+ "field": "value",
124
+ "kind": "field",
125
+ "has": {
126
+ "field": "name",
127
+ "regex": "^[\"`\\[]"
128
+ }
129
+ }
130
+ }
131
+ },
132
+ {
133
+ "not": {
134
+ "has": {
135
+ "field": "alias",
136
+ "regex": "^[\"`\\[]"
137
+ }
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ }
143
+ },
144
+ "violation": {
145
+ "anchor": "witness.start",
146
+ "code": "AL09",
147
+ "message": "Ambiguous self alias. Either remove unnecessary alias, or quote alias/reference to make case change explicit.",
148
+ "suppress": {
149
+ "sqlfluff": {
150
+ "rules": [
151
+ "AL09",
152
+ "aliasing",
153
+ "aliasing.self_alias.column",
154
+ "all",
155
+ "core"
156
+ ]
157
+ }
158
+ }
159
+ }
160
+ }
161
+ ]
162
+ }