• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

satisfactory-dev / ajv-utilities / 25136193506

29 Apr 2026 10:02PM UTC coverage: 98.787% (-1.1%) from 99.85%
25136193506

push

github

SignpostMarv
need to generate modified files on ci

491 of 497 branches covered (98.79%)

Branch coverage included in aggregate %.

3990 of 4039 relevant lines covered (98.79%)

20001.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.03
/src/TypeScriptify/modifiers/ModifyValidate.ts
1
import type {
1✔
2
        EmptyStatement,
1✔
3
        FunctionDeclaration,
1✔
4
        Identifier,
1✔
5
        ObjectBindingPattern,
1✔
6
        ParameterDeclaration,
1✔
7
} from 'typescript';
1✔
8
import {
1✔
9
        factory,
1✔
10
        isEmptyStatement,
1✔
11
        isFunctionDeclaration,
1✔
12
        isIdentifier,
1✔
13
        isObjectBindingPattern,
1✔
14
        SyntaxKind,
1✔
15
} from 'typescript';
1✔
16

1✔
17
import {
1✔
18
        ConditionalModification,
1✔
19
        ConditionalPreprocessor,
1✔
20
} from '../abstracts.ts';
1✔
21

1✔
22
import type {
1✔
23
        Config,
1✔
24
        remove_dataCtxKeys,
1✔
25
} from '../types.ts';
1✔
26

1✔
27
import type {
1✔
28
        prepend_with_imports,
1✔
29
} from '../TypeReferences.ts';
1✔
30

1✔
31
import KnownImports from '../known_imports.ts';
1✔
32

1✔
33
type options = (
1✔
34
        ParameterDeclaration
1✔
35
        & {
1✔
36
                name: ObjectBindingPattern,
1✔
37
        }
1✔
38
);
1✔
39

1✔
40
type ValidateFunctionDeclaration = (
1✔
41
        & FunctionDeclaration
1✔
42
        & {
1✔
43
                name: (
1✔
44
                        & Identifier
1✔
45
                        & {
1✔
46
                                getText(): `validate${number}`,
1✔
47
                        }
1✔
48
                ),
1✔
49
                parameters: [
1✔
50
                        ParameterDeclaration,
1✔
51
                        options,
1✔
52
                ],
1✔
53
        }
1✔
54
);
1✔
55

1✔
56
abstract class ModifyValidate extends ConditionalModification<
1✔
57
        ValidateFunctionDeclaration
1✔
58
> {
1✔
59
        protected maybe_modify_name(
1✔
60
                options_name: ValidateFunctionDeclaration['parameters'][1]['name'],
43✔
61
                config?: remove_dataCtxKeys,
43✔
62
        ) {
43✔
63
                if (
43✔
64
                        Array.isArray(config)
43✔
65
                        && 'string' !== typeof options_name
43✔
66
                        && options_name.elements.length > 0
43✔
67
                ) {
43✔
68
                        const elements = options_name.elements.filter((
4✔
69
                                maybe,
20✔
70
                        ) => {
20✔
71
                                return (
20✔
72
                                        isIdentifier(maybe.name)
20✔
73
                                        && !(
20✔
74
                                                config as string[]
20✔
75
                                        ).includes(maybe.name.getText())
20✔
76
                                );
20✔
77
                        });
4✔
78

4✔
79
                        return factory.updateObjectBindingPattern(
4✔
80
                                options_name,
4✔
81
                                elements,
4✔
82
                        );
4✔
83
                }
4✔
84

39✔
85
                return 'string' === typeof options_name
39✔
86
                        ? factory.createIdentifier(options_name)
43!
87
                        : options_name;
43✔
88
        }
43✔
89
}
1✔
90

1✔
91
export class ModifyValidateOptions extends ModifyValidate {
1✔
92
        #prepend_with_imports: prepend_with_imports;
1✔
93

1✔
94
        constructor(prepend_with_imports: prepend_with_imports) {
1✔
95
                super(
26✔
96
                        (node): node is ValidateFunctionDeclaration => (
26✔
97
                                isFunctionDeclaration(node)
239,496✔
98
                                && !!node.name
239,496✔
99
                                && this.validate_function_name.test(
239,496✔
100
                                        node.name.getText(),
42✔
101
                                )
42✔
102
                                && 2 === node.parameters.length
239,496✔
103
                                && isObjectBindingPattern(node.parameters[1].name)
239,496✔
104
                        ),
26✔
105
                        (node, config) => this.#modify_validate(node, config),
26✔
106
                );
26✔
107

26✔
108
                this.#prepend_with_imports = prepend_with_imports;
26✔
109
        }
26✔
110

1✔
111
        #shim_DataValidationCxt() {
1✔
112
                KnownImports.ValidateFunction(this.#prepend_with_imports);
42✔
113

42✔
114
                return factory.createIntersectionTypeNode([
42✔
115
                        factory.createTypeReferenceNode(
42✔
116
                                'Omit',
42✔
117
                                [
42✔
118
                                        factory.createTypeReferenceNode(
42✔
119
                                                'Exclude',
42✔
120
                                                [
42✔
121
                                                        factory.createIndexedAccessTypeNode(
42✔
122
                                                                factory.createTypeReferenceNode(
42✔
123
                                                                        'Parameters',
42✔
124
                                                                        [
42✔
125
                                                                                factory.createTypeReferenceNode(
42✔
126
                                                                                        'ValidateFunction',
42✔
127
                                                                                ),
42✔
128
                                                                        ],
42✔
129
                                                                ),
42✔
130
                                                                factory.createLiteralTypeNode(
42✔
131
                                                                        factory.createNumericLiteral(1),
42✔
132
                                                                ),
42✔
133
                                                        ),
42✔
134
                                                        factory.createToken(SyntaxKind.UndefinedKeyword),
42✔
135
                                                ],
42✔
136
                                        ),
42✔
137
                                        factory.createLiteralTypeNode(
42✔
138
                                                factory.createStringLiteral('rootData'),
42✔
139
                                        ),
42✔
140
                                ],
42✔
141
                        ),
42✔
142
                        factory.createTypeLiteralNode([
42✔
143
                                factory.createPropertySignature(
42✔
144
                                        undefined,
42✔
145
                                        'rootData',
42✔
146
                                        undefined,
42✔
147
                                        factory.createKeywordTypeNode(
42✔
148
                                                SyntaxKind.UnknownKeyword,
42✔
149
                                        ),
42✔
150
                                ),
42✔
151
                        ]),
42✔
152
                ]);
42✔
153
        }
42✔
154

1✔
155
        #modify_validate(
1✔
156
                node: ValidateFunctionDeclaration,
42✔
157
                config?: Partial<Config>,
42✔
158
        ) {
42✔
159
                const [
42✔
160
                        data,
42✔
161
                        options,
42✔
162
                ] = node.parameters;
42✔
163

42✔
164
                const new_data = factory.updateParameterDeclaration(
42✔
165
                        data,
42✔
166
                        data.modifiers,
42✔
167
                        data.dotDotDotToken,
42✔
168
                        data.name,
42✔
169
                        data.questionToken,
42✔
170
                        factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword),
42✔
171
                        data.initializer,
42✔
172
                );
42✔
173

42✔
174
                const options_name = this.maybe_modify_name(
42✔
175
                        options.name,
42✔
176
                        (config && Array.isArray(config.remove_dataCtxKeys))
42✔
177
                                ? config.remove_dataCtxKeys
42✔
178
                                : undefined,
42✔
179
                );
42✔
180

42✔
181
                const new_options = factory.updateParameterDeclaration(
42✔
182
                        options,
42✔
183
                        options.modifiers,
42✔
184
                        options.dotDotDotToken,
42✔
185
                        options_name,
42✔
186
                        options.questionToken,
42✔
187
                        factory.createTypeReferenceNode('Partial', [
42✔
188
                                this.#shim_DataValidationCxt(),
42✔
189
                        ]),
42✔
190
                        options.initializer,
42✔
191
                );
42✔
192

42✔
193
                return factory.updateFunctionDeclaration(
42✔
194
                        node,
42✔
195
                        node.modifiers,
42✔
196
                        node.asteriskToken,
42✔
197
                        node.name,
42✔
198
                        node.typeParameters,
42✔
199
                        [
42✔
200
                                new_data,
42✔
201
                                new_options,
42✔
202
                        ],
42✔
203
                        node.type,
42✔
204
                        node.body,
42✔
205
                );
42✔
206
        }
42✔
207
}
1✔
208

1✔
209
type config = (
1✔
210
        & Omit<Partial<Config>, 'remove_dataCtxKeys'>
1✔
211
        & Pick<Config, 'remove_dataCtxKeys'>
1✔
212
);
1✔
213

1✔
214
type SpecifyModifyCandidate = (
1✔
215
        & EmptyStatement
1✔
216
        & {
1✔
217
                parent: (
1✔
218
                        & Node
1✔
219
                        & {
1✔
220
                                parent: (
1✔
221
                                        & FunctionDeclaration
1✔
222
                                        & {
1✔
223
                                                name: (
1✔
224
                                                        & Identifier
1✔
225
                                                        & {
1✔
226
                                                                text: `validate${number}`,
1✔
227
                                                        }
1✔
228
                                                ),
1✔
229
                                        }
1✔
230
                                ),
1✔
231
                        }
1✔
232
                ),
1✔
233
        }
1✔
234
);
1✔
235

1✔
236
export type specify_modify_options_name_config = {
1✔
237
        [key: string]: remove_dataCtxKeys,
1✔
238
};
1✔
239

1✔
240
export class SpecifyModifyCandidates extends ConditionalPreprocessor<
1✔
241
        SpecifyModifyCandidate,
1✔
242
        config
1✔
243
> {
1✔
244
        #configEntry(
1✔
245
                config: config['remove_dataCtxKeys'],
5✔
246
                node: EmptyStatement,
5✔
247
        ): remove_dataCtxKeys | undefined {
5✔
248
                if (Array.isArray(config)) {
5✔
249
                        return;
3✔
250
                }
3✔
251

2✔
252
                const keys = Object.keys(config);
2✔
253

2✔
254
                if (0 === keys.length) {
5!
255
                        return;
×
256
                }
✔
257

2✔
258
                const code = node.getFullText();
2✔
259

2✔
260
                const has_match = new RegExp(
2✔
261
                        `\\/\\*# sourceURL="(${
2✔
262
                                keys.map((key) => RegExp.escape(key)).join('|')
2✔
263
                        })" \\*\\/`,
2✔
264
                );
2✔
265

2✔
266
                const maybe = has_match.exec(code);
2✔
267

2✔
268
                if (maybe && maybe[1] in config) {
5✔
269
                        return config[maybe[1]];
1✔
270
                }
1✔
271
        }
5✔
272

1✔
273
        constructor(
1✔
274
                specify_config: specify_modify_options_name_config,
26✔
275
        ) {
26✔
276
                super(
26✔
277
                        (node, config): node is SpecifyModifyCandidate => (
26✔
278
                                !!config
239,499✔
279
                                && !!config.remove_dataCtxKeys
239,499✔
280
                                && isEmptyStatement(node)
239,499✔
281
                                && !!node.parent
239,499✔
282
                                && !!node.parent.parent
239,499✔
283
                                && isFunctionDeclaration(node.parent.parent)
239,499✔
284
                                && !!node.parent.parent.name
239,499✔
285
                                && this.validate_function_name.test(
239,499✔
286
                                        node.parent.parent.name.text,
5✔
287
                                )
5✔
288
                        ),
26✔
289
                        (node, config) => {
26✔
290
                                const maybe = this.#configEntry(
5✔
291
                                        config.remove_dataCtxKeys,
5✔
292
                                        node,
5✔
293
                                );
5✔
294

5✔
295
                                if (maybe) {
5✔
296
                                        specify_config[
1✔
297
                                                node.parent.parent.name.text
1✔
298
                                        ] = maybe;
1✔
299
                                }
1✔
300
                        },
26✔
301
                );
26✔
302
        }
26✔
303
}
1✔
304

1✔
305
export class ModifyValidateOptionsByConfig extends ModifyValidate {
1✔
306
        constructor(
1✔
307
                specify_modify_options_name_config: specify_modify_options_name_config,
16✔
308
        ) {
16✔
309
                super(
16✔
310
                        (node): node is ValidateFunctionDeclaration => (
16✔
311
                                isFunctionDeclaration(node)
238,978✔
312
                                && !!node.name
238,978✔
313
                                && this.validate_function_name.test(
238,978✔
314
                                        node.name.text,
78✔
315
                                )
78✔
316
                                && node.name.text in specify_modify_options_name_config
238,978✔
317
                                && 2 === node.parameters.length
238,978✔
318
                                && isObjectBindingPattern(node.parameters[1].name)
238,978✔
319
                        ),
16✔
320
                        (node) => this.#modify_validate(
16✔
321
                                node,
1✔
322
                                specify_modify_options_name_config,
1✔
323
                        ),
16✔
324
                );
16✔
325
        }
16✔
326

1✔
327
        #modify_validate(
1✔
328
                node: ValidateFunctionDeclaration,
1✔
329
                config: specify_modify_options_name_config,
1✔
330
        ) {
1✔
331
                const [
1✔
332
                        data,
1✔
333
                        options,
1✔
334
                ] = node.parameters;
1✔
335

1✔
336
                const options_name = this.maybe_modify_name(
1✔
337
                        options.name,
1✔
338
                        config[node.name.text],
1✔
339
                );
1✔
340

1✔
341
                const new_options = factory.updateParameterDeclaration(
1✔
342
                        options,
1✔
343
                        options.modifiers,
1✔
344
                        options.dotDotDotToken,
1✔
345
                        options_name,
1✔
346
                        options.questionToken,
1✔
347
                        options.type,
1✔
348
                        options.initializer,
1✔
349
                );
1✔
350

1✔
351
                return factory.updateFunctionDeclaration(
1✔
352
                        node,
1✔
353
                        node.modifiers,
1✔
354
                        node.asteriskToken,
1✔
355
                        node.name,
1✔
356
                        node.typeParameters,
1✔
357
                        [
1✔
358
                                data,
1✔
359
                                new_options,
1✔
360
                        ],
1✔
361
                        node.type,
1✔
362
                        node.body,
1✔
363
                );
1✔
364
        }
1✔
365
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc