forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CP02.yml
283 lines (244 loc) · 8.45 KB
/
CP02.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
rule: CP02
test_pass_consistent_capitalisation_1:
pass_str: SELECT a, b
test_pass_consistent_capitalisation_2:
pass_str: SELECT A, B
test_pass_consistent_capitalisation_with_null:
# Test that NULL is classed as a keyword and not an identifier
pass_str: SELECT NULL, a
test_pass_consistent_capitalisation_with_single_letter_upper:
# Single-letter ambiguity: Upper vs Capitalise
pass_str: SELECT A, Boo
test_pass_consistent_capitalisation_with_single_word_snake:
# Single-word ambiguity: Pascal vs Capitalise
pass_str: SELECT Apple, Banana_split
test_pass_consistent_capitalisation_with_single_word_pascal:
# Single-word ambiguity: Pascal vs Capitalise
pass_str: SELECT AppleFritter, Banana
test_pass_consistent_capitalisation_with_multiple_words_with_numbers:
# Numbers count as part of words so following letter can be upper or lower
pass_str: SELECT AppleFritter, Apple123fritter, Apple123Fritter
test_pass_consistent_capitalisation_with_leading_underscore:
pass_str: SELECT _a, b
test_fail_inconsistent_capitalisation_lower_case:
# Test that fixes are consistent
fail_str: SELECT a, B
fix_str: SELECT a, b
test_fail_inconsistent_capitalisation_2:
fail_str: SELECT B, a
fix_str: SELECT B, A
# PascalCase tests are based on this comment by @alanmcruickshank:
# https://github.com/sqlfluff/sqlfluff/issues/820#issuecomment-787050507
test_pass_consistent_capitalisation_policy_pascal_1:
pass_str: SELECT PascalCase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_pass_consistent_capitalisation_policy_pascal_2:
pass_str: SELECT Pascalcase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_pass_consistent_capitalisation_policy_pascal_3:
fail_str: SELECT pascalCase
fix_str: SELECT PascalCase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_pass_consistent_capitalisation_policy_pascal_4:
pass_str: SELECT PasCalCaSe
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_pass_consistent_capitalisation_policy_pascal_5:
pass_str: SELECT PAscalcase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_pass_consistent_capitalisation_policy_pascal_6:
# This could be argued as not PascalCase but technically it is
# unless we introduce a full dictionarry of words to recognise
# where word breaks are (an impossible task!). Also what about
# abbreviations (e.g. NASA)?
pass_str: SELECT PASCALCASE
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_fail_inconsistent_capitalisation_policy_pascal_1:
fail_str: SELECT pascalcase
fix_str: SELECT Pascalcase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_fail_inconsistent_capitalisation_policy_pascal_2:
fail_str: SELECT pascal_case
fix_str: SELECT Pascal_Case
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_fail_inconsistent_capitalisation_policy_pascal_3:
# Similar to above, you could argue the fixed string is
# Not really Pascal Case, but it's closer than it was!
fail_str: SELECT pASCAL_CASE
fix_str: SELECT PASCAL_CASE
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
test_fail_inconsistent_capitalisation_policy_pascal_4:
fail_str: SELECT PasCalCase
fix_str: SELECT pascalcase
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: lower
test_fail_consistent_capitalisation_policy_pascal_5:
fail_str: SELECT PascalCaseNAME
fix_str: SELECT PASCALCASENAME
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: upper
test_fail_inconsistent_capitalisation_pascal_v_capitalise:
# Pascal vs Capitalise
fail_str: SELECT AppleFritter, Banana_split
fix_str: SELECT AppleFritter, Banana_Split
test_pass_policy_unquoted_identifiers_aliases_1:
pass_str: SELECT a, B
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_pass_policy_unquoted_identifiers_aliases_2:
pass_str: SELECT B, a
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_pass_policy_unquoted_identifiers_aliases_3:
# See above commentsin regards to whether this should
# really be considered PascalCase (we treat as yes)
pass_str: SELECT PASCAL_CASE
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: pascal
unquoted_identifiers_policy: aliases
test_pass_policy_unquoted_identifiers_aliases_4:
pass_str: SELECT UPPER_CASE AS low_case, PascalCase AS low_case
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_policy_unquoted_identifiers_aliases_5:
fail_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS lower_case
fix_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS Lower_Case
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_policy_unquoted_identifiers_aliases_6:
fail_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS lower_case
fix_str: SELECT UPPER_CASE AS PASCALCASE, PascalCase AS LOWER_CASE
configs:
rules:
capitalisation.identifiers:
extended_capitalisation_policy: upper
unquoted_identifiers_policy: aliases
test_policy_unquoted_identifiers_aliases_7:
fail_str: SELECT UPPER_CASE AS low_case, PascalCase AS low_case FROM UPPER_CASE AS UPPER_CASE
fix_str: SELECT UPPER_CASE AS low_case, PascalCase AS low_case FROM UPPER_CASE AS upper_case
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_policy_unquoted_identifiers_aliases_8:
fail_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS lower_case FROM lower_case AS lower_case
fix_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS Lower_Case FROM lower_case AS Lower_Case
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: aliases
test_policy_unquoted_identifiers_column_aliases_1:
pass_str: SELECT UPPER_CASE AS low_case, PascalCase AS low_case FROM UPPER_CASE AS UPPER_CASE
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: column_aliases
test_policy_unquoted_identifiers_aliases_2:
fail_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS lower_case FROM lower_case AS lower_case
fix_str: SELECT UPPER_CASE AS PascalCase, PascalCase AS Lower_Case FROM lower_case AS lower_case
configs:
rules:
capitalisation.identifiers:
unquoted_identifiers_policy: column_aliases
test_pass_ignore_word:
pass_str: SELECT A, b
configs:
rules:
capitalisation.identifiers:
capitalisation_policy: upper
ignore_words: b
test_pass_consistent_capitalisation_properties_naked_identifier:
pass_str: SHOW TBLPROPERTIES customer (created.by.user)
configs:
core:
dialect: sparksql
test_fail_inconsistent_capitalisation_properties_naked_identifier:
# Test that fixes are consistent
fail_str: SHOW TBLPROPERTIES customer (created.BY.user)
fix_str: SHOW TBLPROPERTIES customer (created.by.user)
configs:
core:
dialect: sparksql
test_fail_inconsistent_capitalisation_properties_naked_identifier_2:
fail_str: SHOW TBLPROPERTIES customer (Created.By.User)
fix_str: SHOW TBLPROPERTIES customer (created.by.user)
configs:
core:
dialect: sparksql
test_pass_bigquery_safe_does_not_trigger:
pass_str: SELECT SAFE.myFunction(1) AS col1
configs:
core:
dialect: bigquery
test_pass_databricks_case_sensitive_property:
pass_str: SET spark.databricks.delta.properties.defaults.enableChangeDataFeed = true;
configs:
core:
dialect: databricks
test_fail_snake_aliases:
# Test for issue #5470
# similar to PascalCase, case logic defined in CP01, but tested in CP02
fail_str: |
SELECT
test1,
test_2,
testColumn3,
TestColumn4,
TESTCOLUMN5,
TEST_COLUMN6,
test_column_7_
fix_str: |
SELECT
test_1,
test_2,
test_column_3,
test_column_4,
testcolumn_5,
test_column_6,
test_column_7_
configs:
core:
dialect: tsql
rules:
capitalisation.identifiers:
extended_capitalisation_policy: snake