@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,365 @@
1
+ {
2
+ "format": "rerail.policy/v1",
3
+ "id": "sqlfluff-st10-structure-constant-expression",
4
+ "revision": 1,
5
+ "mode": "steer",
6
+ "description": "Remove SQL comparisons that are always true or false, such as an expression compared to itself or two literals; 1 = 1 and 1 = 0 are allowed.",
7
+ "scope": {
8
+ "include": [
9
+ "**/*.sql"
10
+ ],
11
+ "exclude": []
12
+ },
13
+ "clauses": [
14
+ {
15
+ "id": "identical-nonliteral-operands",
16
+ "forbid": {
17
+ "ast": {
18
+ "language": "sql",
19
+ "utils": {
20
+ "constant": {
21
+ "any": [
22
+ {
23
+ "kind": "literal",
24
+ "not": {
25
+ "has": {
26
+ "any": [
27
+ {
28
+ "kind": "identifier"
29
+ },
30
+ {
31
+ "kind": "timestamp"
32
+ },
33
+ {
34
+ "kind": "time"
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ },
40
+ {
41
+ "kind": "parameter",
42
+ "regex": "^\\$[0-9]+$"
43
+ }
44
+ ]
45
+ },
46
+ "typed-string": {
47
+ "kind": "literal",
48
+ "has": {
49
+ "kind": "identifier",
50
+ "not": {
51
+ "regex": "(?i)^(?:date|timetz|timestamptz)$"
52
+ }
53
+ }
54
+ },
55
+ "adjacent": {
56
+ "not": {
57
+ "any": [
58
+ {
59
+ "kind": "binary_expression"
60
+ },
61
+ {
62
+ "kind": "collate_expression"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ },
68
+ "rule": {
69
+ "kind": "binary_expression",
70
+ "all": [
71
+ {
72
+ "has": {
73
+ "field": "operator",
74
+ "regex": "^(?:=|!=|<>)$",
75
+ "pattern": "$$OP"
76
+ }
77
+ },
78
+ {
79
+ "has": {
80
+ "field": "left",
81
+ "pattern": "$L",
82
+ "all": [
83
+ {
84
+ "matches": "adjacent"
85
+ },
86
+ {
87
+ "not": {
88
+ "any": [
89
+ {
90
+ "matches": "constant"
91
+ },
92
+ {
93
+ "matches": "typed-string"
94
+ }
95
+ ]
96
+ }
97
+ }
98
+ ]
99
+ }
100
+ },
101
+ {
102
+ "has": {
103
+ "field": "right",
104
+ "any": [
105
+ {
106
+ "all": [
107
+ {
108
+ "matches": "adjacent"
109
+ },
110
+ {
111
+ "pattern": "$R",
112
+ "not": {
113
+ "any": [
114
+ {
115
+ "matches": "constant"
116
+ },
117
+ {
118
+ "matches": "typed-string"
119
+ }
120
+ ]
121
+ }
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ "kind": "collate_expression",
127
+ "has": {
128
+ "field": "expression",
129
+ "all": [
130
+ {
131
+ "matches": "adjacent"
132
+ },
133
+ {
134
+ "pattern": "$R",
135
+ "not": {
136
+ "any": [
137
+ {
138
+ "matches": "constant"
139
+ },
140
+ {
141
+ "matches": "typed-string"
142
+ }
143
+ ]
144
+ }
145
+ }
146
+ ]
147
+ }
148
+ }
149
+ ]
150
+ }
151
+ },
152
+ {
153
+ "compare": {
154
+ "left": "L",
155
+ "op": "eq",
156
+ "right": "R",
157
+ "text": "source"
158
+ }
159
+ }
160
+ ]
161
+ }
162
+ }
163
+ },
164
+ "violation": {
165
+ "anchor": "capture.OP",
166
+ "code": "ST10",
167
+ "message": "Remove or correct this comparison of $L with itself; it is always true or always false.",
168
+ "suppress": {
169
+ "sqlfluff": {
170
+ "rules": [
171
+ "ST10",
172
+ "all",
173
+ "structure",
174
+ "structure.constant_expression"
175
+ ]
176
+ }
177
+ }
178
+ }
179
+ },
180
+ {
181
+ "id": "disallowed-literal-comparison",
182
+ "forbid": {
183
+ "ast": {
184
+ "language": "sql",
185
+ "utils": {
186
+ "constant": {
187
+ "any": [
188
+ {
189
+ "kind": "literal",
190
+ "not": {
191
+ "has": {
192
+ "any": [
193
+ {
194
+ "kind": "identifier"
195
+ },
196
+ {
197
+ "kind": "timestamp"
198
+ },
199
+ {
200
+ "kind": "time"
201
+ }
202
+ ]
203
+ }
204
+ }
205
+ },
206
+ {
207
+ "kind": "parameter",
208
+ "regex": "^\\$[0-9]+$"
209
+ }
210
+ ]
211
+ },
212
+ "typed-string": {
213
+ "kind": "literal",
214
+ "has": {
215
+ "kind": "identifier",
216
+ "not": {
217
+ "regex": "(?i)^(?:date|timetz|timestamptz)$"
218
+ }
219
+ }
220
+ },
221
+ "adjacent": {
222
+ "not": {
223
+ "any": [
224
+ {
225
+ "kind": "binary_expression"
226
+ },
227
+ {
228
+ "kind": "collate_expression"
229
+ }
230
+ ]
231
+ }
232
+ }
233
+ },
234
+ "rule": {
235
+ "kind": "binary_expression",
236
+ "all": [
237
+ {
238
+ "has": {
239
+ "field": "operator",
240
+ "regex": "^(?:=|!=|<>)$",
241
+ "pattern": "$$OP"
242
+ }
243
+ },
244
+ {
245
+ "has": {
246
+ "field": "left",
247
+ "all": [
248
+ {
249
+ "matches": "adjacent"
250
+ },
251
+ {
252
+ "any": [
253
+ {
254
+ "matches": "constant"
255
+ },
256
+ {
257
+ "matches": "typed-string"
258
+ }
259
+ ]
260
+ }
261
+ ]
262
+ }
263
+ },
264
+ {
265
+ "has": {
266
+ "field": "right",
267
+ "any": [
268
+ {
269
+ "all": [
270
+ {
271
+ "matches": "adjacent"
272
+ },
273
+ {
274
+ "matches": "constant"
275
+ }
276
+ ]
277
+ },
278
+ {
279
+ "kind": "collate_expression",
280
+ "has": {
281
+ "field": "expression",
282
+ "all": [
283
+ {
284
+ "matches": "adjacent"
285
+ },
286
+ {
287
+ "matches": "constant"
288
+ }
289
+ ]
290
+ }
291
+ }
292
+ ]
293
+ }
294
+ },
295
+ {
296
+ "not": {
297
+ "all": [
298
+ {
299
+ "has": {
300
+ "field": "left",
301
+ "regex": "(?:^1|(?:^|\\s)'1')$"
302
+ }
303
+ },
304
+ {
305
+ "has": {
306
+ "field": "operator",
307
+ "regex": "^=$"
308
+ }
309
+ },
310
+ {
311
+ "has": {
312
+ "field": "right",
313
+ "any": [
314
+ {
315
+ "all": [
316
+ {
317
+ "matches": "adjacent"
318
+ },
319
+ {
320
+ "regex": "^(?:[01]|'[01]')$"
321
+ }
322
+ ]
323
+ },
324
+ {
325
+ "kind": "collate_expression",
326
+ "has": {
327
+ "field": "expression",
328
+ "all": [
329
+ {
330
+ "matches": "adjacent"
331
+ },
332
+ {
333
+ "regex": "^(?:[01]|'[01]')$"
334
+ }
335
+ ]
336
+ }
337
+ }
338
+ ]
339
+ }
340
+ }
341
+ ]
342
+ }
343
+ }
344
+ ]
345
+ }
346
+ }
347
+ },
348
+ "violation": {
349
+ "anchor": "capture.OP",
350
+ "code": "ST10",
351
+ "message": "Remove this comparison of two literals; it always has the same result (1 = 1 and 1 = 0 are allowed).",
352
+ "suppress": {
353
+ "sqlfluff": {
354
+ "rules": [
355
+ "ST10",
356
+ "all",
357
+ "structure",
358
+ "structure.constant_expression"
359
+ ]
360
+ }
361
+ }
362
+ }
363
+ }
364
+ ]
365
+ }