@neralabs/rerail-pack-sql 0.1.3 → 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.
@@ -0,0 +1,405 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-st02-structure-simple-case",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Replace a single-branch SQL CASE that only returns TRUE/FALSE or fills in a NULL with the condition itself or COALESCE.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "boolean-case",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "rule": {
20
+ "kind": "case",
21
+ "all": [
22
+ {
23
+ "has": {
24
+ "kind": "keyword_when",
25
+ "follows": {
26
+ "kind": "keyword_case",
27
+ "stopBy": {
28
+ "not": {
29
+ "kind": "comment"
30
+ }
31
+ }
32
+ }
33
+ }
34
+ },
35
+ {
36
+ "not": {
37
+ "has": {
38
+ "kind": "keyword_when",
39
+ "precedes": {
40
+ "stopBy": "end",
41
+ "kind": "keyword_when"
42
+ }
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "has": {
48
+ "kind": "keyword_when",
49
+ "precedes": {
50
+ "pattern": "$C",
51
+ "stopBy": {
52
+ "not": {
53
+ "kind": "comment"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ },
59
+ {
60
+ "has": {
61
+ "kind": "keyword_then",
62
+ "precedes": {
63
+ "kind": "literal",
64
+ "regex": "^(?i:true|false)$",
65
+ "pattern": "$T",
66
+ "stopBy": {
67
+ "not": {
68
+ "kind": "comment"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ },
74
+ {
75
+ "has": {
76
+ "kind": "keyword_else",
77
+ "precedes": {
78
+ "kind": "literal",
79
+ "regex": "^(?i:true|false)$",
80
+ "pattern": "$E",
81
+ "stopBy": {
82
+ "not": {
83
+ "kind": "comment"
84
+ }
85
+ }
86
+ }
87
+ }
88
+ },
89
+ {
90
+ "compare": {
91
+ "left": "T",
92
+ "op": "ne",
93
+ "right": "E",
94
+ "collation": "fold-upper"
95
+ }
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ },
101
+ "violation": {
102
+ "anchor": "capture.C",
103
+ "code": "ST02",
104
+ "message": "Replace this CASE with COALESCE($C, FALSE), prefixed with NOT if its THEN value is FALSE.",
105
+ "suppress": {
106
+ "sqlfluff": {
107
+ "rules": [
108
+ "ST02",
109
+ "L043",
110
+ "all",
111
+ "structure",
112
+ "structure.simple_case"
113
+ ]
114
+ }
115
+ }
116
+ }
117
+ },
118
+ {
119
+ "id": "is-null-else-operand",
120
+ "forbid": {
121
+ "ast": {
122
+ "language": "sql",
123
+ "rule": {
124
+ "kind": "case",
125
+ "all": [
126
+ {
127
+ "has": {
128
+ "kind": "keyword_when",
129
+ "follows": {
130
+ "kind": "keyword_case",
131
+ "stopBy": {
132
+ "not": {
133
+ "kind": "comment"
134
+ }
135
+ }
136
+ }
137
+ }
138
+ },
139
+ {
140
+ "not": {
141
+ "has": {
142
+ "kind": "keyword_when",
143
+ "precedes": {
144
+ "stopBy": "end",
145
+ "kind": "keyword_when"
146
+ }
147
+ }
148
+ }
149
+ },
150
+ {
151
+ "has": {
152
+ "kind": "keyword_when",
153
+ "precedes": {
154
+ "kind": "binary_expression",
155
+ "pattern": "$C",
156
+ "all": [
157
+ {
158
+ "has": {
159
+ "field": "operator",
160
+ "kind": "keyword_is"
161
+ }
162
+ },
163
+ {
164
+ "has": {
165
+ "field": "right",
166
+ "kind": "literal",
167
+ "regex": "^(?i:null)$"
168
+ }
169
+ },
170
+ {
171
+ "has": {
172
+ "field": "left",
173
+ "pattern": "$X",
174
+ "any": [
175
+ {
176
+ "kind": "field"
177
+ },
178
+ {
179
+ "kind": "subscript",
180
+ "not": {
181
+ "has": {
182
+ "stopBy": "end",
183
+ "any": [
184
+ { "inside": { "kind": "subscript", "field": "expression" }, "not": { "any": [{ "kind": "field" }, { "kind": "subscript" }] } },
185
+ { "inside": { "kind": "subscript", "field": "subscript" }, "not": { "kind": "literal" } },
186
+ { "inside": { "kind": "subscript", "field": "lower" }, "not": { "kind": "literal" } },
187
+ { "inside": { "kind": "subscript", "field": "upper" }, "not": { "kind": "literal" } }
188
+ ]
189
+ }
190
+ }
191
+ }
192
+ ]
193
+ }
194
+ }
195
+ ],
196
+ "stopBy": {
197
+ "not": {
198
+ "kind": "comment"
199
+ }
200
+ }
201
+ }
202
+ }
203
+ },
204
+ {
205
+ "has": {
206
+ "kind": "keyword_else",
207
+ "precedes": {
208
+ "pattern": "$E",
209
+ "stopBy": {
210
+ "not": {
211
+ "kind": "comment"
212
+ }
213
+ }
214
+ }
215
+ }
216
+ },
217
+ {
218
+ "compare": {
219
+ "left": "XQ",
220
+ "op": "eq",
221
+ "right": "EQ",
222
+ "text": "source"
223
+ }
224
+ },
225
+ {
226
+ "compare": {
227
+ "left": "XU",
228
+ "op": "eq",
229
+ "right": "EU",
230
+ "text": "source",
231
+ "collation": "fold-upper"
232
+ }
233
+ }
234
+ ]
235
+ },
236
+ "transform": {
237
+ "XQ": { "replace": { "source": "$X", "replace": "(\"[^\"]*\")|[^\"]", "by": "$1" } },
238
+ "XU": { "replace": { "source": "$X", "replace": "\"[^\"]*\"", "by": "\"\"" } },
239
+ "EQ": { "replace": { "source": "$E", "replace": "(\"[^\"]*\")|[^\"]", "by": "$1" } },
240
+ "EU": { "replace": { "source": "$E", "replace": "\"[^\"]*\"", "by": "\"\"" } }
241
+ }
242
+ }
243
+ },
244
+ "violation": {
245
+ "anchor": "capture.C",
246
+ "code": "ST02",
247
+ "message": "Replace this CASE with COALESCE($X, <its THEN value>), or just $X if the THEN value is NULL.",
248
+ "suppress": {
249
+ "sqlfluff": {
250
+ "rules": [
251
+ "ST02",
252
+ "L043",
253
+ "all",
254
+ "structure",
255
+ "structure.simple_case"
256
+ ]
257
+ }
258
+ }
259
+ }
260
+ },
261
+ {
262
+ "id": "is-not-null-then-operand",
263
+ "forbid": {
264
+ "ast": {
265
+ "language": "sql",
266
+ "rule": {
267
+ "kind": "case",
268
+ "all": [
269
+ {
270
+ "has": {
271
+ "kind": "keyword_when",
272
+ "follows": {
273
+ "kind": "keyword_case",
274
+ "stopBy": {
275
+ "not": {
276
+ "kind": "comment"
277
+ }
278
+ }
279
+ }
280
+ }
281
+ },
282
+ {
283
+ "not": {
284
+ "has": {
285
+ "kind": "keyword_when",
286
+ "precedes": {
287
+ "stopBy": "end",
288
+ "kind": "keyword_when"
289
+ }
290
+ }
291
+ }
292
+ },
293
+ {
294
+ "has": {
295
+ "kind": "keyword_when",
296
+ "precedes": {
297
+ "kind": "binary_expression",
298
+ "pattern": "$C",
299
+ "all": [
300
+ {
301
+ "has": {
302
+ "field": "operator",
303
+ "kind": "is_not"
304
+ }
305
+ },
306
+ {
307
+ "has": {
308
+ "field": "right",
309
+ "kind": "literal",
310
+ "regex": "^(?i:null)$"
311
+ }
312
+ },
313
+ {
314
+ "has": {
315
+ "field": "left",
316
+ "pattern": "$X",
317
+ "any": [
318
+ {
319
+ "kind": "field"
320
+ },
321
+ {
322
+ "kind": "subscript",
323
+ "not": {
324
+ "has": {
325
+ "stopBy": "end",
326
+ "any": [
327
+ { "inside": { "kind": "subscript", "field": "expression" }, "not": { "any": [{ "kind": "field" }, { "kind": "subscript" }] } },
328
+ { "inside": { "kind": "subscript", "field": "subscript" }, "not": { "kind": "literal" } },
329
+ { "inside": { "kind": "subscript", "field": "lower" }, "not": { "kind": "literal" } },
330
+ { "inside": { "kind": "subscript", "field": "upper" }, "not": { "kind": "literal" } }
331
+ ]
332
+ }
333
+ }
334
+ }
335
+ ]
336
+ }
337
+ }
338
+ ],
339
+ "stopBy": {
340
+ "not": {
341
+ "kind": "comment"
342
+ }
343
+ }
344
+ }
345
+ }
346
+ },
347
+ {
348
+ "has": {
349
+ "kind": "keyword_then",
350
+ "precedes": {
351
+ "pattern": "$T",
352
+ "stopBy": {
353
+ "not": {
354
+ "kind": "comment"
355
+ }
356
+ }
357
+ }
358
+ }
359
+ },
360
+ {
361
+ "compare": {
362
+ "left": "XQ",
363
+ "op": "eq",
364
+ "right": "TQ",
365
+ "text": "source"
366
+ }
367
+ },
368
+ {
369
+ "compare": {
370
+ "left": "XU",
371
+ "op": "eq",
372
+ "right": "TU",
373
+ "text": "source",
374
+ "collation": "fold-upper"
375
+ }
376
+ }
377
+ ]
378
+ },
379
+ "transform": {
380
+ "XQ": { "replace": { "source": "$X", "replace": "(\"[^\"]*\")|[^\"]", "by": "$1" } },
381
+ "XU": { "replace": { "source": "$X", "replace": "\"[^\"]*\"", "by": "\"\"" } },
382
+ "TQ": { "replace": { "source": "$T", "replace": "(\"[^\"]*\")|[^\"]", "by": "$1" } },
383
+ "TU": { "replace": { "source": "$T", "replace": "\"[^\"]*\"", "by": "\"\"" } }
384
+ }
385
+ }
386
+ },
387
+ "violation": {
388
+ "anchor": "capture.C",
389
+ "code": "ST02",
390
+ "message": "Replace this CASE with COALESCE($X, <its ELSE value>), or just $X if it has no ELSE.",
391
+ "suppress": {
392
+ "sqlfluff": {
393
+ "rules": [
394
+ "ST02",
395
+ "L043",
396
+ "all",
397
+ "structure",
398
+ "structure.simple_case"
399
+ ]
400
+ }
401
+ }
402
+ }
403
+ }
404
+ ]
405
+ }
@@ -0,0 +1,168 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-st08-structure-distinct",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Don't put parentheses after DISTINCT in SQL as if it were a function; DISTINCT is a keyword, and the parentheses mislead about what it applies to.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "distinct-select-parentheses",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "rule": {
20
+ "kind": "parenthesized_expression",
21
+ "inside": {
22
+ "kind": "term",
23
+ "field": "value",
24
+ "nthChild": 1,
25
+ "inside": {
26
+ "kind": "select_expression",
27
+ "follows": {
28
+ "kind": "keyword_distinct"
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ },
35
+ "violation": {
36
+ "anchor": "witness.start",
37
+ "code": "ST08",
38
+ "message": "DISTINCT used with parentheses.",
39
+ "suppress": {
40
+ "sqlfluff": {
41
+ "rules": [
42
+ "ST08",
43
+ "L015",
44
+ "all",
45
+ "core",
46
+ "structure",
47
+ "structure.distinct"
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ },
53
+ {
54
+ "id": "distinct-before-parenthesized-operand",
55
+ "forbid": {
56
+ "ast": {
57
+ "language": "sql",
58
+ "rule": {
59
+ "kind": "keyword_distinct",
60
+ "inside": {
61
+ "kind": "select",
62
+ "regex": "^(?is:select\\s+distinct\\()"
63
+ },
64
+ "precedes": {
65
+ "kind": "select_expression",
66
+ "has": {
67
+ "kind": "term",
68
+ "nthChild": 1,
69
+ "has": {
70
+ "field": "value",
71
+ "kind": "binary_expression",
72
+ "has": {
73
+ "field": "left",
74
+ "kind": "parenthesized_expression"
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ },
82
+ "violation": {
83
+ "anchor": "witness.start",
84
+ "code": "ST08",
85
+ "message": "DISTINCT used with parentheses.",
86
+ "suppress": {
87
+ "sqlfluff": {
88
+ "rules": [
89
+ "ST08",
90
+ "L015",
91
+ "all",
92
+ "core",
93
+ "structure",
94
+ "structure.distinct"
95
+ ]
96
+ }
97
+ }
98
+ }
99
+ },
100
+ {
101
+ "id": "distinct-function-parentheses",
102
+ "forbid": {
103
+ "ast": {
104
+ "language": "sql",
105
+ "rule": {
106
+ "kind": "keyword_distinct",
107
+ "inside": {
108
+ "kind": "invocation"
109
+ },
110
+ "precedes": {
111
+ "kind": "term",
112
+ "not": {
113
+ "any": [
114
+ {
115
+ "has": {
116
+ "field": "alias",
117
+ "regex": "(?s)."
118
+ }
119
+ },
120
+ {
121
+ "precedes": {
122
+ "stopBy": "end",
123
+ "regex": "^,$"
124
+ }
125
+ }
126
+ ]
127
+ },
128
+ "has": {
129
+ "field": "value",
130
+ "kind": "parenthesized_expression",
131
+ "not": {
132
+ "has": {
133
+ "stopBy": "end",
134
+ "any": [
135
+ {
136
+ "kind": "subquery"
137
+ },
138
+ {
139
+ "kind": "select"
140
+ }
141
+ ]
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ },
149
+ "violation": {
150
+ "anchor": "witness.start",
151
+ "code": "ST08",
152
+ "message": "DISTINCT used with parentheses.",
153
+ "suppress": {
154
+ "sqlfluff": {
155
+ "rules": [
156
+ "ST08",
157
+ "L015",
158
+ "all",
159
+ "core",
160
+ "structure",
161
+ "structure.distinct"
162
+ ]
163
+ }
164
+ }
165
+ }
166
+ }
167
+ ]
168
+ }