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

satisfactory-dev / ajv-utilities / 26333519053

23 May 2026 01:06PM UTC coverage: 99.237% (+0.05%) from 99.186%
26333519053

push

github

SignpostMarv
updating readme

609 of 626 branches covered (97.28%)

Branch coverage included in aggregate %.

5372 of 5401 relevant lines covered (99.46%)

16572.71 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

1✔
9
import {
1✔
10
        ConditionalModification,
1✔
11
        ConditionalPreprocessor,
1✔
12
} from '../abstracts.ts';
1✔
13

1✔
14
import type {
1✔
15
        Config,
1✔
16
        remove_dataCtxKeys,
1✔
17
} from '../types.ts';
1✔
18

1✔
19
import type {
1✔
20
        prepend_with_imports,
1✔
21
} from '../TypeReferences.ts';
1✔
22

1✔
23
import KnownImports from '../known_imports.ts';
1✔
24

1✔
25
import type {
1✔
26
        ts,
1✔
27
} from '../../TypeScriptify.ts';
1✔
28

1✔
29
type options = (
1✔
30
        ParameterDeclaration
1✔
31
        & {
1✔
32
                name: ObjectBindingPattern,
1✔
33
        }
1✔
34
);
1✔
35

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

1✔
52
abstract class ModifyValidate extends ConditionalModification<
1✔
53
        ValidateFunctionDeclaration
1✔
54
> {
1✔
55
        protected maybe_modify_name(
1✔
56
                {
43✔
57
                        factory,
43✔
58
                        isIdentifier,
43✔
59
                }: ts,
43✔
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(
1✔
95
                ts: ts,
26✔
96
                prepend_with_imports: prepend_with_imports,
26✔
97
        ) {
26✔
98
                const {
26✔
99
                        isFunctionDeclaration,
26✔
100
                        isObjectBindingPattern,
26✔
101
                } = ts;
26✔
102

26✔
103
                super(
26✔
104
                        (node): node is ValidateFunctionDeclaration => (
26✔
105
                                isFunctionDeclaration(node)
238,764✔
106
                                && !!node.name
238,764✔
107
                                && this.validate_function_name.test(
238,764✔
108
                                        node.name.getText(),
42✔
109
                                )
42✔
110
                                && 2 === node.parameters.length
238,764✔
111
                                && isObjectBindingPattern(node.parameters[1].name)
238,764✔
112
                        ),
26✔
113
                        (node, config) => this.#modify_validate(
26✔
114
                                ts,
42✔
115
                                node,
42✔
116
                                config,
42✔
117
                        ),
26✔
118
                );
26✔
119

26✔
120
                this.#prepend_with_imports = prepend_with_imports;
26✔
121
        }
26✔
122

1✔
123
        #shim_DataValidationCxt({factory}: ts) {
1✔
124
                KnownImports.StandaloneDataValidationCxt(this.#prepend_with_imports);
42✔
125

42✔
126
                return factory.createTypeReferenceNode(
42✔
127
                        'StandaloneDataValidationCxt',
42✔
128
                );
42✔
129
        }
42✔
130

1✔
131
        #modify_validate(
1✔
132
                ts: ts,
42✔
133
                node: ValidateFunctionDeclaration,
42✔
134
                config?: Partial<Config>,
42✔
135
        ) {
42✔
136
                const {
42✔
137
                        factory,
42✔
138
                        SyntaxKind,
42✔
139
                } = ts;
42✔
140

42✔
141
                const [
42✔
142
                        data,
42✔
143
                        options,
42✔
144
                ] = node.parameters;
42✔
145

42✔
146
                const new_data = factory.updateParameterDeclaration(
42✔
147
                        data,
42✔
148
                        data.modifiers,
42✔
149
                        data.dotDotDotToken,
42✔
150
                        data.name,
42✔
151
                        data.questionToken,
42✔
152
                        factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword),
42✔
153
                        data.initializer,
42✔
154
                );
42✔
155

42✔
156
                const options_name = this.maybe_modify_name(
42✔
157
                        ts,
42✔
158
                        options.name,
42✔
159
                        (config && Array.isArray(config.remove_dataCtxKeys))
42✔
160
                                ? config.remove_dataCtxKeys
42✔
161
                                : undefined,
42✔
162
                );
42✔
163

42✔
164
                const new_options = factory.updateParameterDeclaration(
42✔
165
                        options,
42✔
166
                        options.modifiers,
42✔
167
                        options.dotDotDotToken,
42✔
168
                        options_name,
42✔
169
                        options.questionToken,
42✔
170
                        factory.createTypeReferenceNode('Partial', [
42✔
171
                                this.#shim_DataValidationCxt(ts),
42✔
172
                        ]),
42✔
173
                        options.initializer,
42✔
174
                );
42✔
175

42✔
176
                return factory.updateFunctionDeclaration(
42✔
177
                        node,
42✔
178
                        node.modifiers,
42✔
179
                        node.asteriskToken,
42✔
180
                        node.name,
42✔
181
                        node.typeParameters,
42✔
182
                        [
42✔
183
                                new_data,
42✔
184
                                new_options,
42✔
185
                        ],
42✔
186
                        node.type,
42✔
187
                        node.body,
42✔
188
                );
42✔
189
        }
42✔
190
}
1✔
191

1✔
192
type config = (
1✔
193
        & Omit<Partial<Config>, 'remove_dataCtxKeys'>
1✔
194
        & Pick<Config, 'remove_dataCtxKeys'>
1✔
195
);
1✔
196

1✔
197
type SpecifyModifyCandidate = (
1✔
198
        & EmptyStatement
1✔
199
        & {
1✔
200
                parent: (
1✔
201
                        & Node
1✔
202
                        & {
1✔
203
                                parent: (
1✔
204
                                        & FunctionDeclaration
1✔
205
                                        & {
1✔
206
                                                name: (
1✔
207
                                                        & Identifier
1✔
208
                                                        & {
1✔
209
                                                                text: `validate${number}`,
1✔
210
                                                        }
1✔
211
                                                ),
1✔
212
                                        }
1✔
213
                                ),
1✔
214
                        }
1✔
215
                ),
1✔
216
        }
1✔
217
);
1✔
218

1✔
219
export type specify_modify_options_name_config = {
1✔
220
        [key: string]: remove_dataCtxKeys,
1✔
221
};
1✔
222

1✔
223
export class SpecifyModifyCandidates extends ConditionalPreprocessor<
1✔
224
        SpecifyModifyCandidate,
1✔
225
        config
1✔
226
> {
1✔
227
        #configEntry(
1✔
228
                config: config['remove_dataCtxKeys'],
5✔
229
                node: EmptyStatement,
5✔
230
        ): remove_dataCtxKeys | undefined {
5✔
231
                if (Array.isArray(config)) {
5✔
232
                        return;
3✔
233
                }
3✔
234

2✔
235
                const keys = Object.keys(config);
2✔
236

2✔
237
                if (0 === keys.length) {
5!
238
                        return;
×
239
                }
✔
240

2✔
241
                const code = node.getFullText();
2✔
242

2✔
243
                const has_match = new RegExp(
2✔
244
                        `\\/\\*# sourceURL="(${
2✔
245
                                keys.map((key) => RegExp.escape(key)).join('|')
2✔
246
                        })" \\*\\/`,
2✔
247
                );
2✔
248

2✔
249
                const maybe = has_match.exec(code);
2✔
250

2✔
251
                if (maybe && maybe[1] in config) {
5✔
252
                        return config[maybe[1]];
1✔
253
                }
1✔
254
        }
5✔
255

1✔
256
        constructor(
1✔
257
                {
26✔
258
                        isEmptyStatement,
26✔
259
                        isFunctionDeclaration,
26✔
260
                }: ts,
26✔
261
                specify_config: specify_modify_options_name_config,
26✔
262
        ) {
26✔
263
                super(
26✔
264
                        (node, config): node is SpecifyModifyCandidate => (
26✔
265
                                !!config
238,767✔
266
                                && !!config.remove_dataCtxKeys
238,767✔
267
                                && isEmptyStatement(node)
238,767✔
268
                                && !!node.parent
238,767✔
269
                                && !!node.parent.parent
238,767✔
270
                                && isFunctionDeclaration(node.parent.parent)
238,767✔
271
                                && !!node.parent.parent.name
238,767✔
272
                                && this.validate_function_name.test(
238,767✔
273
                                        node.parent.parent.name.text,
5✔
274
                                )
5✔
275
                        ),
26✔
276
                        (node, config) => {
26✔
277
                                const maybe = this.#configEntry(
5✔
278
                                        config.remove_dataCtxKeys,
5✔
279
                                        node,
5✔
280
                                );
5✔
281

5✔
282
                                if (maybe) {
5✔
283
                                        specify_config[
1✔
284
                                                node.parent.parent.name.text
1✔
285
                                        ] = maybe;
1✔
286
                                }
1✔
287
                        },
26✔
288
                );
26✔
289
        }
26✔
290
}
1✔
291

1✔
292
export class ModifyValidateOptionsByConfig extends ModifyValidate {
1✔
293
        constructor(
1✔
294
                ts: ts,
26✔
295
                specify_modify_options_name_config: specify_modify_options_name_config,
26✔
296
        ) {
26✔
297
                const {
26✔
298
                        isFunctionDeclaration,
26✔
299
                        isObjectBindingPattern,
26✔
300
                } = ts;
26✔
301

26✔
302
                super(
26✔
303
                        (node): node is ValidateFunctionDeclaration => (
26✔
304
                                isFunctionDeclaration(node)
239,126✔
305
                                && !!node.name
239,126✔
306
                                && this.validate_function_name.test(
239,126✔
307
                                        node.name.text,
42✔
308
                                )
42✔
309
                                && node.name.text in specify_modify_options_name_config
239,126✔
310
                                && 2 === node.parameters.length
239,126✔
311
                                && isObjectBindingPattern(node.parameters[1].name)
239,126✔
312
                        ),
26✔
313
                        (node) => this.#modify_validate(
26✔
314
                                ts,
1✔
315
                                node,
1✔
316
                                specify_modify_options_name_config,
1✔
317
                        ),
26✔
318
                );
26✔
319
        }
26✔
320

1✔
321
        #modify_validate(
1✔
322
                ts: ts,
1✔
323
                node: ValidateFunctionDeclaration,
1✔
324
                config: specify_modify_options_name_config,
1✔
325
        ) {
1✔
326
                const {
1✔
327
                        factory,
1✔
328
                } = ts;
1✔
329

1✔
330
                const [
1✔
331
                        data,
1✔
332
                        options,
1✔
333
                ] = node.parameters;
1✔
334

1✔
335
                const options_name = this.maybe_modify_name(
1✔
336
                        ts,
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