@@ -101,7 +101,7 @@ def __str__(self):
101
101
return self .__repr__ ()
102
102
103
103
104
- def unique_names (yaml_chunk , tsv_keyword ):
104
+ def unique_names (yaml_chunk , tsv_keyword , level = Level . ERROR ):
105
105
"""Make sure that each name in the block is only used once.
106
106
107
107
block content level lint
@@ -116,15 +116,15 @@ def unique_names(yaml_chunk, tsv_keyword):
116
116
if count > 1 :
117
117
errors .append (
118
118
LintViolation (
119
- Level . ERROR ,
119
+ level ,
120
120
"unique_names" ,
121
121
f"Name '{ name } ' occurs { count } times. Names have to be unique." ,
122
122
)
123
123
)
124
124
return errors
125
125
126
126
127
- def block_content_is_list (yaml_chunk ):
127
+ def block_content_is_list (yaml_chunk , level = Level . ERROR ):
128
128
"""Make sure that the yaml chunk is a list.
129
129
130
130
block content level lint
@@ -134,14 +134,14 @@ def block_content_is_list(yaml_chunk):
134
134
else :
135
135
return [
136
136
LintViolation (
137
- Level . ERROR ,
137
+ level ,
138
138
"block_content_is_list" ,
139
139
"Entry is not a list" ,
140
140
)
141
141
]
142
142
143
143
144
- def top_level_keywords_valid (keywords ):
144
+ def top_level_keywords_valid (keywords , level = Level . ERROR ):
145
145
"""Ensure top-level keywords are spelled correctly and no additonal ones are present.
146
146
147
147
top-level keyword level lint
@@ -154,14 +154,14 @@ def top_level_keywords_valid(keywords):
154
154
else :
155
155
return [
156
156
LintViolation (
157
- Level . ERROR ,
157
+ level ,
158
158
"top_level_keywords_valid" ,
159
159
f"Keyword list '{ keywords } ' differs from '{ PERMISSIBLE_KEYWORDS } ' or '{ REQUIRED_TOP_LEVEL_KEYWORDS } '" ,
160
160
)
161
161
]
162
162
163
163
164
- def top_level_keywords_unique (keywords ):
164
+ def top_level_keywords_unique (keywords , level = Level . ERROR ):
165
165
"""Make sure no keyword is specified twice.
166
166
167
167
NOTE: This is most likely also enforced by the YAML parser,
@@ -175,14 +175,14 @@ def top_level_keywords_unique(keywords):
175
175
else :
176
176
return [
177
177
LintViolation (
178
- Level . ERROR ,
178
+ level ,
179
179
"top_level_keywords_unique" ,
180
180
f"Keyword list '{ keywords } ' contains duplicate keys." ,
181
181
)
182
182
]
183
183
184
184
185
- def required_keys_present (list_item , tsv_keyword ):
185
+ def required_keys_present (list_item , tsv_keyword , level = Level . ERROR ):
186
186
"""Make sure the keywords required for the current top-level item are present.
187
187
188
188
second-level list entry lint
@@ -193,7 +193,7 @@ def required_keys_present(list_item, tsv_keyword):
193
193
except KeyError :
194
194
return [
195
195
LintViolation (
196
- Level . ERROR ,
196
+ level ,
197
197
"required_keys_present" ,
198
198
f"Cannot check entry for invalid keyword '{ tsv_keyword } '. Skipping entry." ,
199
199
)
@@ -204,14 +204,14 @@ def required_keys_present(list_item, tsv_keyword):
204
204
else :
205
205
return [
206
206
LintViolation (
207
- Level . ERROR ,
207
+ level ,
208
208
"required_keys_present" ,
209
209
f"List of required keys '{ required } ' and found keys '{ found_keys } ' differ." ,
210
210
)
211
211
]
212
212
213
213
214
- def no_invalid_keys_present (list_item , tsv_keyword ):
214
+ def no_invalid_keys_present (list_item , tsv_keyword , level = Level . ERROR ):
215
215
"""Make sure no invalid keys are present.
216
216
217
217
second-level list entry lint
@@ -221,7 +221,7 @@ def no_invalid_keys_present(list_item, tsv_keyword):
221
221
except KeyError :
222
222
return [
223
223
LintViolation (
224
- Level . ERROR ,
224
+ level ,
225
225
"no_invalid_keys_present" ,
226
226
f"Cannot check entry for invalid keyword '{ tsv_keyword } '. Skipping entry." ,
227
227
)
@@ -232,15 +232,15 @@ def no_invalid_keys_present(list_item, tsv_keyword):
232
232
if key not in permissible :
233
233
violations .append (
234
234
LintViolation (
235
- Level . ERROR ,
235
+ level ,
236
236
"no_invalid_keys_present" ,
237
237
f"Invalid key { key } present for { list_item } in block { tsv_keyword } ." ,
238
238
)
239
239
)
240
240
return violations
241
241
242
242
243
- def no_substructures_present (list_item , tsv_keyword ):
243
+ def no_substructures_present (list_item , tsv_keyword , level = Level . ERROR ):
244
244
"""Make sure list items do not contain dicts, tuples lists etc.
245
245
246
246
second-level list entry lint
@@ -250,15 +250,15 @@ def no_substructures_present(list_item, tsv_keyword):
250
250
if type (value ) in (dict , tuple , list ):
251
251
violations .append (
252
252
LintViolation (
253
- Level . ERROR ,
253
+ level ,
254
254
"no_substructures_present" ,
255
255
f"Key { key } in block { tsv_keyword } has a subtructure of type { type (value )} . Only strings, booleans, an numericals are allowed here." ,
256
256
)
257
257
)
258
258
return violations
259
259
260
260
261
- def no_trailing_white_spaces (list_item , tsv_keyword ):
261
+ def no_trailing_white_spaces (list_item , tsv_keyword , level = Level . ERROR ):
262
262
"""Make sure the entries do not contain trailing white spaces.
263
263
264
264
second-level list entry lint
@@ -294,7 +294,7 @@ def no_trailing_white_spaces(list_item, tsv_keyword):
294
294
# Regex matches one or more spaces at the end of strings
295
295
violations .append (
296
296
LintViolation (
297
- Level . ERROR ,
297
+ level ,
298
298
"no_trailing_white_spaces" ,
299
299
f"The entry '{ value } ' has one or more trailing spaces." ,
300
300
)
0 commit comments