leftovers 0.5.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/README.md +21 -1
- data/docs/Configuration.md +188 -20
- data/leftovers.gemspec +8 -5
- data/lib/config/actionmailer.yml +11 -11
- data/lib/config/actionpack.yml +11 -0
- data/lib/config/activesupport.yml +1 -1
- data/lib/config/rails.yml +1 -1
- data/lib/config/railties.yml +11 -0
- data/lib/config/ruby.yml +79 -0
- data/lib/leftovers/ast/node.rb +16 -11
- data/lib/leftovers/collector.rb +3 -1
- data/lib/leftovers/config.rb +9 -28
- data/lib/leftovers/config_loader/argument_position_schema.rb +11 -0
- data/lib/leftovers/config_loader/argumentless_transform_schema.rb +21 -0
- data/lib/leftovers/config_loader/attribute.rb +30 -0
- data/lib/leftovers/config_loader/document_schema.rb +21 -0
- data/lib/leftovers/config_loader/dynamic_schema.rb +17 -0
- data/lib/leftovers/config_loader/has_argument_schema.rb +13 -0
- data/lib/leftovers/config_loader/has_value_schema.rb +18 -0
- data/lib/leftovers/config_loader/keep_test_only_schema.rb +13 -0
- data/lib/leftovers/config_loader/node.rb +106 -0
- data/lib/leftovers/config_loader/object_schema.rb +189 -0
- data/lib/leftovers/config_loader/privacy_processor_schema.rb +12 -0
- data/lib/leftovers/config_loader/privacy_schema.rb +15 -0
- data/lib/leftovers/config_loader/require_schema.rb +11 -0
- data/lib/leftovers/config_loader/rule_pattern_schema.rb +18 -0
- data/lib/leftovers/config_loader/scalar_argument_schema.rb +14 -0
- data/lib/leftovers/config_loader/scalar_value_schema.rb +14 -0
- data/lib/leftovers/config_loader/schema.rb +21 -0
- data/lib/leftovers/config_loader/string_enum_schema.rb +62 -0
- data/lib/leftovers/config_loader/string_pattern_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_schema.rb +14 -0
- data/lib/leftovers/config_loader/string_value_processor_schema.rb +11 -0
- data/lib/leftovers/config_loader/suggester.rb +22 -0
- data/lib/leftovers/config_loader/transform_schema.rb +28 -0
- data/lib/leftovers/config_loader/true_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_matcher_schema.rb +18 -0
- data/lib/leftovers/config_loader/value_or_array_schema.rb +64 -0
- data/lib/leftovers/config_loader/value_processor_schema.rb +14 -0
- data/lib/leftovers/config_loader/value_type_schema.rb +17 -0
- data/lib/leftovers/config_loader.rb +82 -0
- data/lib/leftovers/definition.rb +1 -1
- data/lib/leftovers/definition_node.rb +6 -17
- data/lib/leftovers/definition_node_set.rb +11 -0
- data/lib/leftovers/definition_to_add.rb +31 -0
- data/lib/leftovers/dynamic_processors/call.rb +4 -7
- data/lib/leftovers/dynamic_processors/call_definition.rb +14 -11
- data/lib/leftovers/dynamic_processors/definition.rb +8 -7
- data/lib/leftovers/dynamic_processors/set_default_privacy.rb +18 -0
- data/lib/leftovers/dynamic_processors/set_privacy.rb +23 -0
- data/lib/leftovers/dynamic_processors.rb +2 -0
- data/lib/leftovers/file.rb +57 -11
- data/lib/leftovers/file_collector.rb +77 -19
- data/lib/leftovers/json.rb +28 -0
- data/lib/leftovers/matcher_builders/document.rb +13 -0
- data/lib/leftovers/matcher_builders/node.rb +7 -1
- data/lib/leftovers/matcher_builders/node_has_argument.rb +3 -4
- data/lib/leftovers/matcher_builders/node_has_keyword_argument.rb +1 -1
- data/lib/leftovers/matcher_builders/node_has_positional_argument.rb +1 -1
- data/lib/leftovers/matcher_builders/node_privacy.rb +13 -0
- data/lib/leftovers/matcher_builders/node_type.rb +4 -4
- data/lib/leftovers/matcher_builders/node_value.rb +1 -1
- data/lib/leftovers/matcher_builders/string_pattern.rb +14 -5
- data/lib/leftovers/matcher_builders.rb +2 -0
- data/lib/leftovers/matchers/all.rb +0 -4
- data/lib/leftovers/matchers/and.rb +0 -4
- data/lib/leftovers/matchers/any.rb +0 -4
- data/lib/leftovers/matchers/node_has_any_keyword_argument.rb +1 -7
- data/lib/leftovers/matchers/node_has_any_positional_argument_with_value.rb +1 -7
- data/lib/leftovers/matchers/node_has_positional_argument_with_value.rb +0 -4
- data/lib/leftovers/matchers/node_name.rb +0 -4
- data/lib/leftovers/matchers/node_pair_value.rb +0 -4
- data/lib/leftovers/matchers/node_path.rb +0 -4
- data/lib/leftovers/matchers/node_privacy.rb +19 -0
- data/lib/leftovers/matchers/node_scalar_value.rb +0 -4
- data/lib/leftovers/matchers/node_type.rb +0 -4
- data/lib/leftovers/matchers/not.rb +0 -4
- data/lib/leftovers/matchers/or.rb +0 -4
- data/lib/leftovers/matchers.rb +1 -0
- data/lib/leftovers/merged_config.rb +25 -23
- data/lib/leftovers/processor_builders/add_prefix.rb +1 -1
- data/lib/leftovers/processor_builders/add_suffix.rb +1 -1
- data/lib/leftovers/processor_builders/dynamic.rb +51 -16
- data/lib/leftovers/processor_builders/transform.rb +2 -2
- data/lib/leftovers/processor_builders/transform_set.rb +8 -8
- data/lib/leftovers/todo_reporter.rb +10 -35
- data/lib/leftovers/value_processors/delete_prefix.rb +0 -6
- data/lib/leftovers/value_processors/delete_suffix.rb +0 -6
- data/lib/leftovers/value_processors/each_for_definition_set.rb +2 -5
- data/lib/leftovers/value_processors/each_positional_argument.rb +1 -1
- data/lib/leftovers/value_processors/keyword.rb +0 -4
- data/lib/leftovers/value_processors/keyword_argument.rb +0 -4
- data/lib/leftovers/value_processors/return_definition_node.rb +14 -0
- data/lib/leftovers/value_processors/{return_string.rb → return_sym.rb} +1 -1
- data/lib/leftovers/value_processors.rb +2 -2
- data/lib/leftovers/version.rb +1 -1
- data/lib/leftovers/yaml.rb +73 -0
- data/lib/leftovers.rb +29 -21
- metadata +85 -36
- data/lib/config/actioncable.yml +0 -4
- data/lib/leftovers/backports.rb +0 -40
- data/lib/leftovers/config_validator/error_processor.rb +0 -196
- data/lib/leftovers/config_validator/schema_hash.rb +0 -530
- data/lib/leftovers/config_validator.rb +0 -60
- data/lib/leftovers/value_processors/return_definition.rb +0 -26
@@ -1,530 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
module Leftovers
|
4
|
-
module ConfigValidator # rubocop:disable Metrics/ModuleLength
|
5
|
-
SCHEMA_HASH = {
|
6
|
-
'$schema' => 'http://json-schema.org/draft-06/schema#',
|
7
|
-
'type' => 'object',
|
8
|
-
'definitions' => {
|
9
|
-
'true' => { 'enum' => [true, 'true'] },
|
10
|
-
'string' => {
|
11
|
-
'type' => 'string',
|
12
|
-
'minLength' => 1
|
13
|
-
},
|
14
|
-
'stringPattern' => {
|
15
|
-
'type' => 'object',
|
16
|
-
'properties' => {
|
17
|
-
'match' => { '$ref' => '#/definitions/string' },
|
18
|
-
'matches' => { '$ref' => '#/definitions/string' },
|
19
|
-
'has_prefix' => { '$ref' => '#/definitions/string' },
|
20
|
-
'has_suffix' => { '$ref' => '#/definitions/string' }
|
21
|
-
},
|
22
|
-
'minProperties' => 0,
|
23
|
-
'additionalProperties' => true,
|
24
|
-
'allOf' => [
|
25
|
-
# synonyms
|
26
|
-
{ 'not' => { 'required' => %w{match matches} } },
|
27
|
-
# incompatible groups
|
28
|
-
{ 'not' => { 'required' => %w{match has_prefix} } },
|
29
|
-
{ 'not' => { 'required' => %w{match has_suffix} } },
|
30
|
-
{ 'not' => { 'required' => %w{matches has_prefix} } },
|
31
|
-
{ 'not' => { 'required' => %w{matches has_suffix} } }
|
32
|
-
]
|
33
|
-
},
|
34
|
-
'stringList' => {
|
35
|
-
'anyOf' => [
|
36
|
-
{
|
37
|
-
'type' => 'array',
|
38
|
-
'items' => { '$ref' => '#/definitions/string' },
|
39
|
-
'minItems' => 1
|
40
|
-
},
|
41
|
-
{ '$ref' => '#/definitions/string' }
|
42
|
-
]
|
43
|
-
},
|
44
|
-
'name' => {
|
45
|
-
'anyOf' => [
|
46
|
-
{ '$ref' => '#/definitions/string' },
|
47
|
-
{ 'allOf' => [
|
48
|
-
{ '$ref' => '#/definitions/stringPattern' },
|
49
|
-
{
|
50
|
-
'type' => 'object',
|
51
|
-
'properties' => {
|
52
|
-
'match' => true, 'matches' => true,
|
53
|
-
'has_prefix' => true, 'has_suffix' => true,
|
54
|
-
'unless' => { '$ref' => '#/definitions/nameList' }
|
55
|
-
},
|
56
|
-
'minProperties' => 1,
|
57
|
-
'additionalProperties' => false
|
58
|
-
}
|
59
|
-
] }
|
60
|
-
]
|
61
|
-
},
|
62
|
-
'nameList' => {
|
63
|
-
'anyOf' => [
|
64
|
-
{
|
65
|
-
'type' => 'array',
|
66
|
-
'items' => { '$ref' => '#/definitions/name' },
|
67
|
-
'minItems' => 1
|
68
|
-
},
|
69
|
-
{ '$ref' => '#/definitions/name' }
|
70
|
-
]
|
71
|
-
},
|
72
|
-
'argumentPosition' => {
|
73
|
-
'anyOf' => [
|
74
|
-
{ '$ref' => '#/definitions/string' },
|
75
|
-
{ 'type' => 'integer', 'minimum' => 0 },
|
76
|
-
{ '$ref' => '#/definitions/name' }
|
77
|
-
]
|
78
|
-
},
|
79
|
-
'argumentPositionList' => {
|
80
|
-
'anyOf' => [
|
81
|
-
{ '$ref' => '#/definitions/argumentPosition' },
|
82
|
-
{
|
83
|
-
'type' => 'array',
|
84
|
-
'items' => { '$ref' => '#/definitions/argumentPosition' },
|
85
|
-
'minItems' => 1
|
86
|
-
}
|
87
|
-
]
|
88
|
-
},
|
89
|
-
'valueType' => {
|
90
|
-
'type' => 'string',
|
91
|
-
'enum' => %w{String Symbol Integer Float Array Hash Proc}
|
92
|
-
},
|
93
|
-
'valueTypeList' => {
|
94
|
-
'anyOf' => [
|
95
|
-
{ '$ref' => '#/definitions/valueType' },
|
96
|
-
{
|
97
|
-
'type' => 'array',
|
98
|
-
'items' => { '$ref' => '#/definitions/valueType' },
|
99
|
-
'minItems' => 1
|
100
|
-
}
|
101
|
-
]
|
102
|
-
},
|
103
|
-
'hasValue' => {
|
104
|
-
'anyOf' => [
|
105
|
-
{ 'type' => 'string' },
|
106
|
-
{ 'type' => 'integer' },
|
107
|
-
{ 'type' => 'number' },
|
108
|
-
{ 'type' => 'boolean' },
|
109
|
-
{ 'type' => 'null' },
|
110
|
-
{ 'allOf' => [
|
111
|
-
{ '$ref' => '#/definitions/stringPattern' },
|
112
|
-
{
|
113
|
-
'type' => 'object',
|
114
|
-
'properties' => {
|
115
|
-
'match' => true, 'matches' => true,
|
116
|
-
'has_prefix' => true, 'has_suffix' => true,
|
117
|
-
'at' => { '$ref' => '#/definitions/argumentPositionList' },
|
118
|
-
'has_value' => { '$ref' => '#/definitions/hasValueList' },
|
119
|
-
'has_receiver' => { '$ref' => '#/definitions/hasValueList' },
|
120
|
-
'type' => { '$ref' => '#/definitions/valueTypeList' },
|
121
|
-
'unless' => { '$ref' => '#/definitions/hasValueList' }
|
122
|
-
},
|
123
|
-
'minProperties' => 1,
|
124
|
-
'additionalProperties' => false,
|
125
|
-
'allOf' => [
|
126
|
-
# incompatible groups
|
127
|
-
{ 'not' => { 'required' => %w{match at} } },
|
128
|
-
{ 'not' => { 'required' => %w{match has_value} } },
|
129
|
-
{ 'not' => { 'required' => %w{match type} } },
|
130
|
-
{ 'not' => { 'required' => %w{matches at} } },
|
131
|
-
{ 'not' => { 'required' => %w{matches has_value} } },
|
132
|
-
{ 'not' => { 'required' => %w{matches type} } },
|
133
|
-
{ 'not' => { 'required' => %w{has_prefix at} } },
|
134
|
-
{ 'not' => { 'required' => %w{has_prefix has_value} } },
|
135
|
-
{ 'not' => { 'required' => %w{has_prefix type} } },
|
136
|
-
{ 'not' => { 'required' => %w{has_suffix at} } },
|
137
|
-
{ 'not' => { 'required' => %w{has_suffix has_value} } },
|
138
|
-
{ 'not' => { 'required' => %w{has_suffix type} } },
|
139
|
-
{ 'not' => { 'required' => %w{at type} } },
|
140
|
-
{ 'not' => { 'required' => %w{has_value type} } }
|
141
|
-
]
|
142
|
-
}
|
143
|
-
] }
|
144
|
-
]
|
145
|
-
},
|
146
|
-
'hasValueList' => {
|
147
|
-
'anyOf' => [
|
148
|
-
{ '$ref' => '#/definitions/hasValue' },
|
149
|
-
{
|
150
|
-
'type' => 'array',
|
151
|
-
'items' => { '$ref' => '#/definitions/hasValue' },
|
152
|
-
'minItems' => 1
|
153
|
-
}
|
154
|
-
]
|
155
|
-
},
|
156
|
-
'hasArgument' => {
|
157
|
-
'anyOf' => [
|
158
|
-
{ '$ref' => '#/definitions/string' },
|
159
|
-
{ 'type' => 'integer', 'minimum' => 0 },
|
160
|
-
{
|
161
|
-
'type' => 'object',
|
162
|
-
'properties' => {
|
163
|
-
'at' => { '$ref' => '#/definitions/argumentPositionList' },
|
164
|
-
'has_value' => { '$ref' => '#/definitions/hasValueList' },
|
165
|
-
'unless' => { '$ref' => '#/definitions/hasArgumentList' }
|
166
|
-
},
|
167
|
-
'minProperties' => 1,
|
168
|
-
'additionalProperties' => false,
|
169
|
-
'allOf' => [
|
170
|
-
# synonyms
|
171
|
-
{ 'not' => { 'required' => %w{has_argument has_arguments} } }
|
172
|
-
]
|
173
|
-
}
|
174
|
-
]
|
175
|
-
},
|
176
|
-
'hasArgumentList' => {
|
177
|
-
'anyOf' => [
|
178
|
-
{ '$ref' => '#/definitions/hasArgument' },
|
179
|
-
{
|
180
|
-
'type' => 'array',
|
181
|
-
'items' => { '$ref' => '#/definitions/hasArgument' },
|
182
|
-
'minItems' => 1
|
183
|
-
}
|
184
|
-
]
|
185
|
-
},
|
186
|
-
'rulePattern' => {
|
187
|
-
'type' => 'object',
|
188
|
-
'properties' => {
|
189
|
-
'name' => { '$ref' => '#/definitions/nameList' },
|
190
|
-
'names' => { '$ref' => '#/definitions/nameList' },
|
191
|
-
'path' => { '$ref' => '#/definitions/stringList' },
|
192
|
-
'paths' => { '$ref' => '#/definitions/stringList' },
|
193
|
-
'has_argument' => { '$ref' => '#/definitions/hasArgumentList' },
|
194
|
-
'has_arguments' => { '$ref' => '#/definitions/hasArgumentList' },
|
195
|
-
'has_receiver' => { '$ref' => '#/definitions/hasValueList' }
|
196
|
-
},
|
197
|
-
'minProperties' => 1,
|
198
|
-
'allOf' => [
|
199
|
-
# synonyms
|
200
|
-
{ 'not' => { 'required' => %w{name names} } },
|
201
|
-
{ 'not' => { 'required' => %w{path paths} } },
|
202
|
-
{ 'not' => { 'required' => %w{has_argument has_arguments} } }
|
203
|
-
]
|
204
|
-
},
|
205
|
-
'transformProperties' => {
|
206
|
-
'type' => 'object',
|
207
|
-
'properties' => {
|
208
|
-
'original' => { '$ref' => '#/definitions/true' },
|
209
|
-
'pluralize' => { '$ref' => '#/definitions/true' },
|
210
|
-
'singularize' => { '$ref' => '#/definitions/true' },
|
211
|
-
'camelize' => { '$ref' => '#/definitions/true' },
|
212
|
-
'camelcase' => { '$ref' => '#/definitions/true' },
|
213
|
-
'underscore' => { '$ref' => '#/definitions/true' },
|
214
|
-
'titleize' => { '$ref' => '#/definitions/true' },
|
215
|
-
'titlecase' => { '$ref' => '#/definitions/true' },
|
216
|
-
'demodulize' => { '$ref' => '#/definitions/true' },
|
217
|
-
'deconstantize' => { '$ref' => '#/definitions/true' },
|
218
|
-
'parameterize' => { '$ref' => '#/definitions/true' },
|
219
|
-
'downcase' => { '$ref' => '#/definitions/true' },
|
220
|
-
'upcase' => { '$ref' => '#/definitions/true' },
|
221
|
-
'capitalize' => { '$ref' => '#/definitions/true' },
|
222
|
-
'swapcase' => { '$ref' => '#/definitions/true' },
|
223
|
-
|
224
|
-
'add_prefix' => { '$ref' => '#/definitions/actionList' },
|
225
|
-
'add_suffix' => { '$ref' => '#/definitions/actionList' },
|
226
|
-
|
227
|
-
'split' => { '$ref' => '#/definitions/string' },
|
228
|
-
'delete_prefix' => { '$ref' => '#/definitions/string' },
|
229
|
-
'delete_suffix' => { '$ref' => '#/definitions/string' },
|
230
|
-
'delete_before' => { '$ref' => '#/definitions/string' },
|
231
|
-
'delete_after' => { '$ref' => '#/definitions/string' }
|
232
|
-
}
|
233
|
-
},
|
234
|
-
'transform' => {
|
235
|
-
'anyOf' => [
|
236
|
-
{
|
237
|
-
'type' => 'string',
|
238
|
-
'enum' => %w{
|
239
|
-
original
|
240
|
-
pluralize
|
241
|
-
singularize
|
242
|
-
camelize
|
243
|
-
camelcase
|
244
|
-
underscore
|
245
|
-
titleize
|
246
|
-
titlecase
|
247
|
-
demodulize
|
248
|
-
deconstantize
|
249
|
-
parameterize
|
250
|
-
downcase
|
251
|
-
upcase
|
252
|
-
capitalize
|
253
|
-
swapcase
|
254
|
-
}
|
255
|
-
},
|
256
|
-
{ 'allOf' => [
|
257
|
-
{ '$ref' => '#/definitions/transformProperties' },
|
258
|
-
{
|
259
|
-
'type' => 'object',
|
260
|
-
'properties' => {
|
261
|
-
'original' => true,
|
262
|
-
'pluralize' => true,
|
263
|
-
'singularize' => true,
|
264
|
-
'camelize' => true,
|
265
|
-
'camelcase' => true,
|
266
|
-
'underscore' => true,
|
267
|
-
'titleize' => true,
|
268
|
-
'titlecase' => true,
|
269
|
-
'demodulize' => true,
|
270
|
-
'deconstantize' => true,
|
271
|
-
'parameterize' => true,
|
272
|
-
'downcase' => true,
|
273
|
-
'upcase' => true,
|
274
|
-
'capitalize' => true,
|
275
|
-
'swapcase' => true,
|
276
|
-
'add_prefix' => true,
|
277
|
-
'add_suffix' => true,
|
278
|
-
'split' => true,
|
279
|
-
'delete_prefix' => true,
|
280
|
-
'delete_suffix' => true,
|
281
|
-
'delete_before' => true,
|
282
|
-
'delete_after' => true
|
283
|
-
},
|
284
|
-
'additionalProperties' => false
|
285
|
-
}
|
286
|
-
] }
|
287
|
-
]
|
288
|
-
},
|
289
|
-
'transformList' => {
|
290
|
-
'anyOf' => [
|
291
|
-
{ '$ref' => '#/definitions/transform' },
|
292
|
-
{
|
293
|
-
'type' => 'array',
|
294
|
-
'items' => { '$ref' => '#/definitions/transform' },
|
295
|
-
'minItems' => 1
|
296
|
-
}
|
297
|
-
]
|
298
|
-
},
|
299
|
-
'keyword' => {
|
300
|
-
'anyOf' => [
|
301
|
-
{ '$ref' => '#/definitions/name' }
|
302
|
-
]
|
303
|
-
},
|
304
|
-
'keywordList' => {
|
305
|
-
'anyOf' => [
|
306
|
-
{ '$ref' => '#/definitions/keyword' },
|
307
|
-
{
|
308
|
-
'type' => 'array',
|
309
|
-
'items' => { '$ref' => '#/definitions/keyword' },
|
310
|
-
'minItems' => 1
|
311
|
-
}
|
312
|
-
]
|
313
|
-
},
|
314
|
-
'action' => {
|
315
|
-
'anyOf' => [
|
316
|
-
{ '$ref' => '#/definitions/string' },
|
317
|
-
{ 'type' => 'integer', 'minimum' => 0 },
|
318
|
-
{ 'allOf' => [
|
319
|
-
{ '$ref' => '#/definitions/transformProperties' },
|
320
|
-
{
|
321
|
-
'type' => 'object',
|
322
|
-
'properties' => {
|
323
|
-
'argument' => { '$ref' => '#/definitions/argumentPositionList' },
|
324
|
-
'arguments' => { '$ref' => '#/definitions/argumentPositionList' },
|
325
|
-
'keyword' => { '$ref' => '#/definitions/keywordList' },
|
326
|
-
'keywords' => { '$ref' => '#/definitions/keywordList' },
|
327
|
-
'itself' => { '$ref' => '#/definitions/true' },
|
328
|
-
'value' => { '$ref' => '#/definitions/string' },
|
329
|
-
'nested' => { '$ref' => '#/definitions/actionList' },
|
330
|
-
'recursive' => { '$ref' => '#/definitions/true' },
|
331
|
-
'transforms' => { '$ref' => '#/definitions/transformList' },
|
332
|
-
'pluralize' => true,
|
333
|
-
'singularize' => true,
|
334
|
-
'camelize' => true,
|
335
|
-
'camelcase' => true,
|
336
|
-
'underscore' => true,
|
337
|
-
'titleize' => true,
|
338
|
-
'titlecase' => true,
|
339
|
-
'demodulize' => true,
|
340
|
-
'deconstantize' => true,
|
341
|
-
'parameterize' => true,
|
342
|
-
'downcase' => true,
|
343
|
-
'upcase' => true,
|
344
|
-
'capitalize' => true,
|
345
|
-
'swapcase' => true,
|
346
|
-
'add_prefix' => true,
|
347
|
-
'add_suffix' => true,
|
348
|
-
'split' => true,
|
349
|
-
'delete_prefix' => true,
|
350
|
-
'delete_suffix' => true,
|
351
|
-
'delete_before' => true,
|
352
|
-
'delete_after' => true
|
353
|
-
},
|
354
|
-
'additionalProperties' => false,
|
355
|
-
'allOf' => [
|
356
|
-
# synonyms
|
357
|
-
{ 'not' => { 'required' => %w{keyword keywords} } },
|
358
|
-
{ 'not' => { 'required' => %w{argument arguments} } },
|
359
|
-
# any of
|
360
|
-
{ 'anyOf' => [
|
361
|
-
{ 'required' => ['argument'] },
|
362
|
-
{ 'required' => ['arguments'] },
|
363
|
-
{ 'required' => ['keyword'] },
|
364
|
-
{ 'required' => ['keywords'] },
|
365
|
-
{ 'required' => ['itself'] },
|
366
|
-
{ 'required' => ['value'] }
|
367
|
-
] }
|
368
|
-
]
|
369
|
-
}
|
370
|
-
] }
|
371
|
-
]
|
372
|
-
},
|
373
|
-
'actionList' => {
|
374
|
-
'anyOf' => [
|
375
|
-
{ '$ref' => '#/definitions/action' },
|
376
|
-
{
|
377
|
-
'type' => 'array',
|
378
|
-
'items' => { '$ref' => '#/definitions/action' },
|
379
|
-
'minItems' => 1
|
380
|
-
}
|
381
|
-
]
|
382
|
-
},
|
383
|
-
'dynamicAction' => {
|
384
|
-
'type' => 'object',
|
385
|
-
'properties' => {
|
386
|
-
'call' => { '$ref' => '#/definitions/actionList' },
|
387
|
-
'calls' => { '$ref' => '#/definitions/actionList' },
|
388
|
-
'define' => { '$ref' => '#/definitions/actionList' },
|
389
|
-
'defines' => { '$ref' => '#/definitions/actionList' }
|
390
|
-
},
|
391
|
-
'additionalProperties' => true,
|
392
|
-
'minProperties' => 1,
|
393
|
-
'allOf' => [
|
394
|
-
# synonyms
|
395
|
-
{ 'not' => { 'required' => %w{call calls} } },
|
396
|
-
{ 'not' => { 'required' => %w{define defines} } },
|
397
|
-
# At least one of
|
398
|
-
{ 'anyOf' => [
|
399
|
-
{ 'required' => ['call'] }, { 'required' => ['calls'] },
|
400
|
-
{ 'required' => ['define'] }, { 'required' => ['defines'] }
|
401
|
-
] }
|
402
|
-
]
|
403
|
-
},
|
404
|
-
'ruleMatcherList' => {
|
405
|
-
'anyOf' => [
|
406
|
-
{
|
407
|
-
'type' => 'array',
|
408
|
-
'items' => { '$ref' => '#/definitions/ruleMatcher' },
|
409
|
-
'minItems' => 1
|
410
|
-
},
|
411
|
-
{ '$ref' => '#/definitions/ruleMatcher' }
|
412
|
-
]
|
413
|
-
},
|
414
|
-
'ruleMatcher' => {
|
415
|
-
'allOf' => [
|
416
|
-
{ '$ref' => '#/definitions/rulePattern' },
|
417
|
-
{ 'anyOf' => [
|
418
|
-
{ 'required' => ['name'] }, { 'required' => ['names'] },
|
419
|
-
{ 'required' => ['path'] }, { 'required' => ['paths'] },
|
420
|
-
{ 'required' => ['has_argument'] }, { 'required' => ['has_arguments'] },
|
421
|
-
{ 'required' => ['has_receiver'] },
|
422
|
-
{ 'required' => ['unless'] }
|
423
|
-
] },
|
424
|
-
{
|
425
|
-
'type' => 'object',
|
426
|
-
'properties' => {
|
427
|
-
# unfortunately this repetition is necessary to use additionalProperties: false
|
428
|
-
'name' => true, 'names' => true,
|
429
|
-
'path' => true, 'paths' => true,
|
430
|
-
'has_argument' => true, 'has_arguments' => true,
|
431
|
-
'has_receiver' => true,
|
432
|
-
'unless' => { '$ref' => '#/definitions/ruleMatcherList' }
|
433
|
-
|
434
|
-
},
|
435
|
-
'additionalProperties' => false,
|
436
|
-
'minProperties' => 1
|
437
|
-
}
|
438
|
-
]
|
439
|
-
},
|
440
|
-
'dynamic' => {
|
441
|
-
'allOf' => [
|
442
|
-
{ '$ref' => '#/definitions/rulePattern' },
|
443
|
-
{ '$ref' => '#/definitions/dynamicAction' },
|
444
|
-
{ 'anyOf' => [
|
445
|
-
{ 'required' => ['name'] }, { 'required' => ['names'] },
|
446
|
-
{ 'required' => ['path'] }, { 'required' => ['paths'] },
|
447
|
-
{ 'required' => ['has_argument'] }, { 'required' => ['has_arguments'] },
|
448
|
-
{ 'required' => ['has_receiver'] },
|
449
|
-
{ 'required' => ['unless'] }
|
450
|
-
] },
|
451
|
-
{
|
452
|
-
'type' => 'object',
|
453
|
-
'properties' => {
|
454
|
-
# unfortunately this repetition is necessary to use additionalProperties: false
|
455
|
-
'name' => true, 'names' => true,
|
456
|
-
'path' => true, 'paths' => true,
|
457
|
-
'has_argument' => true, 'has_arguments' => true,
|
458
|
-
'has_receiver' => true,
|
459
|
-
'unless' => { '$ref' => '#/definitions/ruleMatcherList' },
|
460
|
-
|
461
|
-
'call' => true, 'calls' => true,
|
462
|
-
'define' => true, 'defines' => true
|
463
|
-
},
|
464
|
-
'additionalProperties' => false,
|
465
|
-
'minProperties' => 1
|
466
|
-
}
|
467
|
-
]
|
468
|
-
},
|
469
|
-
'dynamicList' => {
|
470
|
-
'anyOf' => [
|
471
|
-
{
|
472
|
-
'type' => 'array',
|
473
|
-
'items' => { '$ref' => '#/definitions/dynamic' },
|
474
|
-
'minItems' => 1
|
475
|
-
},
|
476
|
-
{ '$ref' => '#/definitions/dynamic' }
|
477
|
-
]
|
478
|
-
},
|
479
|
-
'keepTestOnly' => {
|
480
|
-
'anyOf' => [
|
481
|
-
{ '$ref' => '#/definitions/string' },
|
482
|
-
{
|
483
|
-
'allOf' => [
|
484
|
-
{ '$ref' => '#/definitions/stringPattern' },
|
485
|
-
{ '$ref' => '#/definitions/rulePattern' },
|
486
|
-
{
|
487
|
-
'type' => 'object',
|
488
|
-
'properties' => {
|
489
|
-
# unfortunately this repetition is necessary to use additionalProperties: false
|
490
|
-
'name' => true, 'names' => true,
|
491
|
-
'has_prefix' => true, 'has_suffix' => true, 'matches' => true,
|
492
|
-
'path' => true, 'paths' => true,
|
493
|
-
'has_argument' => true, 'has_arguments' => true,
|
494
|
-
'has_receiver' => true,
|
495
|
-
'unless' => { '$ref' => '#/definitions/keepTestOnlyList' }
|
496
|
-
},
|
497
|
-
'additionalProperties' => false,
|
498
|
-
'minProperties' => 1
|
499
|
-
}
|
500
|
-
]
|
501
|
-
}
|
502
|
-
]
|
503
|
-
},
|
504
|
-
'keepTestOnlyList' => {
|
505
|
-
'anyOf' => [
|
506
|
-
{
|
507
|
-
'type' => 'array',
|
508
|
-
'items' => { '$ref' => '#/definitions/keepTestOnly' },
|
509
|
-
'minItems' => 1
|
510
|
-
},
|
511
|
-
{ '$ref' => '#/definitions/keepTestOnly' }
|
512
|
-
]
|
513
|
-
}
|
514
|
-
},
|
515
|
-
'properties' => {
|
516
|
-
'include_paths' => { '$ref' => '#/definitions/stringList' },
|
517
|
-
'exclude_paths' => { '$ref' => '#/definitions/stringList' },
|
518
|
-
'test_paths' => { '$ref' => '#/definitions/stringList' },
|
519
|
-
'haml_paths' => { '$ref' => '#/definitions/stringList' },
|
520
|
-
'slim_paths' => { '$ref' => '#/definitions/stringList' },
|
521
|
-
'erb_paths' => { '$ref' => '#/definitions/stringList' },
|
522
|
-
'requires' => { '$ref' => '#/definitions/stringList' },
|
523
|
-
'gems' => { '$ref' => '#/definitions/stringList' },
|
524
|
-
'keep' => { '$ref' => '#/definitions/keepTestOnlyList' },
|
525
|
-
'test_only' => { '$ref' => '#/definitions/keepTestOnlyList' },
|
526
|
-
'dynamic' => { '$ref' => '#/definitions/dynamicList' }
|
527
|
-
}
|
528
|
-
}.freeze
|
529
|
-
end
|
530
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
require 'json_schemer'
|
4
|
-
|
5
|
-
module Leftovers
|
6
|
-
module ConfigValidator
|
7
|
-
autoload(:ErrorProcessor, "#{__dir__}/config_validator/error_processor")
|
8
|
-
autoload(:SCHEMA_HASH, "#{__dir__}/config_validator/schema_hash")
|
9
|
-
|
10
|
-
def self.default_schema
|
11
|
-
@default_schema ||= ::JSONSchemer.schema(::Leftovers::ConfigValidator::SCHEMA_HASH)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.validate(obj, validator = default_schema)
|
15
|
-
validator.validate(obj)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.validate_and_process!(yaml, path)
|
19
|
-
errors = validate(yaml)
|
20
|
-
print_validation_errors_and_exit(errors, path) unless errors.first.nil?
|
21
|
-
post_process!(yaml)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.print_validation_errors_and_exit(errors, path)
|
25
|
-
::Leftovers::ConfigValidator::ErrorProcessor.process(errors).each do |message|
|
26
|
-
warn "\e[31mConfig SchemaError: (#{path}): #{message}\e[0m"
|
27
|
-
end
|
28
|
-
|
29
|
-
::Leftovers.exit 1
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.post_process!(obj)
|
33
|
-
case obj
|
34
|
-
when Hash
|
35
|
-
obj.keys.each do |key| # rubocop:disable Style/HashEachMethods # each_key never finishes.
|
36
|
-
obj[symbolize_name(key)] = post_process!(obj.delete(key))
|
37
|
-
end
|
38
|
-
when Array
|
39
|
-
obj.map! { |ea| post_process!(ea) }
|
40
|
-
end
|
41
|
-
obj
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.symbolize_name(name) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
45
|
-
case name
|
46
|
-
when 'matches' then :match
|
47
|
-
when 'defines' then :define
|
48
|
-
when 'calls' then :call
|
49
|
-
when 'name' then :names
|
50
|
-
when 'keyword' then :keywords
|
51
|
-
when 'argument' then :arguments
|
52
|
-
when 'has_argument' then :has_arguments
|
53
|
-
when 'path' then :paths
|
54
|
-
when 'unless' then :unless_arg
|
55
|
-
when 'require' then :requires
|
56
|
-
else name.to_sym
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
|
3
|
-
module Leftovers
|
4
|
-
module ValueProcessors
|
5
|
-
module ReturnDefinition
|
6
|
-
# :nocov:
|
7
|
-
using ::Leftovers::Backports::SetCaseEq if defined?(::Leftovers::Backports::SetCaseEq)
|
8
|
-
# :nocov:
|
9
|
-
|
10
|
-
def self.process(str, node, method_node)
|
11
|
-
return unless str
|
12
|
-
return if str.empty?
|
13
|
-
|
14
|
-
str_node = Leftovers::DefinitionNode.new(str.to_sym, method_node.path)
|
15
|
-
|
16
|
-
return :keep if ::Leftovers.config.keep === str_node
|
17
|
-
|
18
|
-
Leftovers::Definition.new(
|
19
|
-
str_node.name,
|
20
|
-
location: node.loc.expression,
|
21
|
-
test: method_node.test_line? || ::Leftovers.config.test_only === str_node
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|