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

satisfactory-dev / ajv-utilities / 25249984834

02 May 2026 10:33AM UTC coverage: 98.808% (-0.2%) from 99.005%
25249984834

push

github

SignpostMarv
clean up known imports

591 of 609 branches covered (97.04%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 3 files covered. (100.0%)

44 existing lines in 3 files now uncovered.

4882 of 4930 relevant lines covered (99.03%)

22553.33 hits per line

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

98.94
/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'],
87✔
61
                config?: remove_dataCtxKeys,
87✔
62
        ) {
87✔
63
                if (
87✔
64
                        Array.isArray(config)
87✔
65
                        && 'string' !== typeof options_name
87✔
66
                        && options_name.elements.length > 0
87✔
67
                ) {
87✔
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

83✔
85
                return 'string' === typeof options_name
83✔
86
                        ? factory.createIdentifier(options_name)
87!
87
                        : options_name;
87✔
88
        }
87✔
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(
30✔
96
                        (node): node is ValidateFunctionDeclaration => (
30✔
97
                                isFunctionDeclaration(node)
286,048✔
98
                                && !!node.name
286,048✔
99
                                && this.validate_function_name.test(
286,048✔
100
                                        node.name.getText(),
86✔
101
                                )
86✔
102
                                && 2 === node.parameters.length
286,048✔
103
                                && isObjectBindingPattern(node.parameters[1].name)
286,048✔
104
                        ),
30✔
105
                        (node, config) => this.#modify_validate(node, config),
30✔
106
                );
30✔
107

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

1✔
111
        #shim_DataValidationCxt() {
1✔
112
                KnownImports.StandaloneDataValidationCxt(this.#prepend_with_imports);
86✔
113

86✔
114
                return factory.createTypeReferenceNode(
86✔
115
                        'StandaloneDataValidationCxt',
86✔
116
                );
86✔
117
        }
86✔
118

1✔
119
        #modify_validate(
1✔
120
                node: ValidateFunctionDeclaration,
86✔
121
                config?: Partial<Config>,
86✔
122
        ) {
86✔
123
                const [
86✔
124
                        data,
86✔
125
                        options,
86✔
126
                ] = node.parameters;
86✔
127

86✔
128
                const new_data = factory.updateParameterDeclaration(
86✔
129
                        data,
86✔
130
                        data.modifiers,
86✔
131
                        data.dotDotDotToken,
86✔
132
                        data.name,
86✔
133
                        data.questionToken,
86✔
134
                        factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword),
86✔
135
                        data.initializer,
86✔
136
                );
86✔
137

86✔
138
                const options_name = this.maybe_modify_name(
86✔
139
                        options.name,
86✔
140
                        (config && Array.isArray(config.remove_dataCtxKeys))
86✔
141
                                ? config.remove_dataCtxKeys
86✔
142
                                : undefined,
86✔
143
                );
86✔
144

86✔
145
                const new_options = factory.updateParameterDeclaration(
86✔
146
                        options,
86✔
147
                        options.modifiers,
86✔
148
                        options.dotDotDotToken,
86✔
149
                        options_name,
86✔
150
                        options.questionToken,
86✔
151
                        factory.createTypeReferenceNode('Partial', [
86✔
152
                                this.#shim_DataValidationCxt(),
86✔
153
                        ]),
86✔
154
                        options.initializer,
86✔
155
                );
86✔
156

86✔
157
                return factory.updateFunctionDeclaration(
86✔
158
                        node,
86✔
159
                        node.modifiers,
86✔
160
                        node.asteriskToken,
86✔
161
                        node.name,
86✔
162
                        node.typeParameters,
86✔
163
                        [
86✔
164
                                new_data,
86✔
165
                                new_options,
86✔
166
                        ],
86✔
167
                        node.type,
86✔
168
                        node.body,
86✔
169
                );
86✔
170
        }
86✔
171
}
1✔
172

1✔
173
type config = (
1✔
174
        & Omit<Partial<Config>, 'remove_dataCtxKeys'>
1✔
175
        & Pick<Config, 'remove_dataCtxKeys'>
1✔
176
);
1✔
177

1✔
178
type SpecifyModifyCandidate = (
1✔
179
        & EmptyStatement
1✔
180
        & {
1✔
181
                parent: (
1✔
182
                        & Node
1✔
183
                        & {
1✔
184
                                parent: (
1✔
185
                                        & FunctionDeclaration
1✔
186
                                        & {
1✔
187
                                                name: (
1✔
188
                                                        & Identifier
1✔
189
                                                        & {
1✔
190
                                                                text: `validate${number}`,
1✔
191
                                                        }
1✔
192
                                                ),
1✔
193
                                        }
1✔
194
                                ),
1✔
195
                        }
1✔
196
                ),
1✔
197
        }
1✔
198
);
1✔
199

1✔
200
export type specify_modify_options_name_config = {
1✔
201
        [key: string]: remove_dataCtxKeys,
1✔
202
};
1✔
203

1✔
204
export class SpecifyModifyCandidates extends ConditionalPreprocessor<
1✔
205
        SpecifyModifyCandidate,
1✔
206
        config
1✔
207
> {
1✔
208
        #configEntry(
1✔
209
                config: config['remove_dataCtxKeys'],
5✔
210
                node: EmptyStatement,
5✔
211
        ): remove_dataCtxKeys | undefined {
5✔
212
                if (Array.isArray(config)) {
5✔
213
                        return;
3✔
214
                }
3✔
215

2✔
216
                const keys = Object.keys(config);
2✔
217

2✔
218
                if (0 === keys.length) {
5!
UNCOV
219
                        return;
×
UNCOV
220
                }
✔
221

2✔
222
                const code = node.getFullText();
2✔
223

2✔
224
                const has_match = new RegExp(
2✔
225
                        `\\/\\*# sourceURL="(${
2✔
226
                                keys.map((key) => RegExp.escape(key)).join('|')
2✔
227
                        })" \\*\\/`,
2✔
228
                );
2✔
229

2✔
230
                const maybe = has_match.exec(code);
2✔
231

2✔
232
                if (maybe && maybe[1] in config) {
5✔
233
                        return config[maybe[1]];
1✔
234
                }
1✔
235
        }
5✔
236

1✔
237
        constructor(
1✔
238
                specify_config: specify_modify_options_name_config,
30✔
239
        ) {
30✔
240
                super(
30✔
241
                        (node, config): node is SpecifyModifyCandidate => (
30✔
242
                                !!config
286,051✔
243
                                && !!config.remove_dataCtxKeys
286,051✔
244
                                && isEmptyStatement(node)
286,051✔
245
                                && !!node.parent
286,051✔
246
                                && !!node.parent.parent
286,051✔
247
                                && isFunctionDeclaration(node.parent.parent)
286,051✔
248
                                && !!node.parent.parent.name
286,051✔
249
                                && this.validate_function_name.test(
286,051✔
250
                                        node.parent.parent.name.text,
5✔
251
                                )
5✔
252
                        ),
30✔
253
                        (node, config) => {
30✔
254
                                const maybe = this.#configEntry(
5✔
255
                                        config.remove_dataCtxKeys,
5✔
256
                                        node,
5✔
257
                                );
5✔
258

5✔
259
                                if (maybe) {
5✔
260
                                        specify_config[
1✔
261
                                                node.parent.parent.name.text
1✔
262
                                        ] = maybe;
1✔
263
                                }
1✔
264
                        },
30✔
265
                );
30✔
266
        }
30✔
267
}
1✔
268

1✔
269
export class ModifyValidateOptionsByConfig extends ModifyValidate {
1✔
270
        constructor(
1✔
271
                specify_modify_options_name_config: specify_modify_options_name_config,
30✔
272
        ) {
30✔
273
                super(
30✔
274
                        (node): node is ValidateFunctionDeclaration => (
30✔
275
                                isFunctionDeclaration(node)
286,673✔
276
                                && !!node.name
286,673✔
277
                                && this.validate_function_name.test(
286,673✔
278
                                        node.name.text,
86✔
279
                                )
86✔
280
                                && node.name.text in specify_modify_options_name_config
286,673✔
281
                                && 2 === node.parameters.length
286,673✔
282
                                && isObjectBindingPattern(node.parameters[1].name)
286,673✔
283
                        ),
30✔
284
                        (node) => this.#modify_validate(
30✔
285
                                node,
1✔
286
                                specify_modify_options_name_config,
1✔
287
                        ),
30✔
288
                );
30✔
289
        }
30✔
290

1✔
291
        #modify_validate(
1✔
292
                node: ValidateFunctionDeclaration,
1✔
293
                config: specify_modify_options_name_config,
1✔
294
        ) {
1✔
295
                const [
1✔
296
                        data,
1✔
297
                        options,
1✔
298
                ] = node.parameters;
1✔
299

1✔
300
                const options_name = this.maybe_modify_name(
1✔
301
                        options.name,
1✔
302
                        config[node.name.text],
1✔
303
                );
1✔
304

1✔
305
                const new_options = factory.updateParameterDeclaration(
1✔
306
                        options,
1✔
307
                        options.modifiers,
1✔
308
                        options.dotDotDotToken,
1✔
309
                        options_name,
1✔
310
                        options.questionToken,
1✔
311
                        options.type,
1✔
312
                        options.initializer,
1✔
313
                );
1✔
314

1✔
315
                return factory.updateFunctionDeclaration(
1✔
316
                        node,
1✔
317
                        node.modifiers,
1✔
318
                        node.asteriskToken,
1✔
319
                        node.name,
1✔
320
                        node.typeParameters,
1✔
321
                        [
1✔
322
                                data,
1✔
323
                                new_options,
1✔
324
                        ],
1✔
325
                        node.type,
1✔
326
                        node.body,
1✔
327
                );
1✔
328
        }
1✔
329
}
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