@krak-stack/registry 0.1.11 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +31 -2
  2. package/dist/components/ui/app-brand.d.ts +18 -13
  3. package/dist/components/ui/app-brand.js +48 -15
  4. package/dist/components/ui/code-block.js +10 -6
  5. package/dist/components/ui/copy-button.d.ts +1 -1
  6. package/dist/components/ui/copy-button.js +1 -1
  7. package/dist/components/ui/data-table.d.ts +1 -1
  8. package/dist/components/ui/data-table.js +21 -20
  9. package/dist/components/ui/effect-form.js +7 -6
  10. package/dist/components/ui/file-picker.js +2 -1
  11. package/dist/components/ui/form.js +17 -15
  12. package/dist/components/ui/google-map.d.ts +6 -10
  13. package/dist/components/ui/google-map.js +19 -14
  14. package/dist/components/ui/locale-switcher.js +7 -1
  15. package/dist/components/ui/sidebar-layout.js +19 -21
  16. package/dist/components/ui/theme-switcher.js +1 -1
  17. package/dist/lib/docs-core.js +165 -109
  18. package/dist/lib/documentation-toolkit.d.ts +140 -0
  19. package/dist/lib/{docs-ai.js → documentation-toolkit.js} +54 -63
  20. package/dist/lib/httpapi-cli.d.ts +6 -6
  21. package/dist/lib/httpapi-cli.js +75 -48
  22. package/dist/lib/httpapi-client.d.ts +8 -2
  23. package/dist/lib/httpapi-client.js +21 -9
  24. package/dist/lib/httpapi-helpers.d.ts +15 -21
  25. package/dist/lib/httpapi-helpers.js +38 -26
  26. package/dist/lib/httpapi-mcp.js +73 -50
  27. package/dist/lib/httpapi-toolkit.d.ts +20 -0
  28. package/dist/lib/{httpapi-ai.js → httpapi-toolkit.js} +123 -100
  29. package/dist/lib/seo.js +29 -17
  30. package/dist/lib/webfetch-toolkit.d.ts +45 -0
  31. package/dist/lib/webfetch-toolkit.js +276 -0
  32. package/dist/oxlint/anti-slop/index.js +1592 -0
  33. package/dist/services/agent/client/atom.d.ts +7 -7
  34. package/dist/services/agent/client/index.js +55 -54
  35. package/dist/services/agent/index.d.ts +71 -71
  36. package/dist/services/agent/index.js +38 -19
  37. package/dist/services/notification/channels/index.d.ts +11 -9
  38. package/dist/services/notification/channels/ses/index.d.ts +6 -6
  39. package/dist/services/notification/channels/ses/index.js +15 -11
  40. package/dist/services/notification/client/index.js +3 -2
  41. package/dist/services/notification/client/notification-menu.d.ts +9 -9
  42. package/dist/services/notification/index.d.ts +7 -6
  43. package/dist/services/notification/persistence/drizzle.js +214 -0
  44. package/dist/services/notification/persistence/index.js +227 -0
  45. package/dist/services/notification/persistence/schema.js +118 -0
  46. package/dist/services/notification/public.js +3 -2
  47. package/dist/services/s3/index.d.ts +2 -16
  48. package/dist/services/s3/index.js +12 -9
  49. package/package.json +33 -7
  50. package/dist/lib/docs-ai.d.ts +0 -142
  51. package/dist/lib/httpapi-ai.d.ts +0 -54
@@ -0,0 +1,1592 @@
1
+ // ../../tools/oxlint/anti-slop/index.ts
2
+ import { eslintCompatPlugin } from "@oxlint/plugins";
3
+
4
+ // ../../tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts
5
+ import { defineRule } from "@oxlint/plugins";
6
+ function isTypeAssertionExpression(node) {
7
+ return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
8
+ }
9
+ function unwrapParenthesizedExpression(expression) {
10
+ let current = expression;
11
+ while (current.type === "ParenthesizedExpression") {
12
+ current = current.expression;
13
+ }
14
+ return current;
15
+ }
16
+ function isConstAssertion(node) {
17
+ const { typeAnnotation } = node;
18
+ return typeAnnotation.type === "TSTypeReference" && typeAnnotation.typeName.type === "Identifier" && typeAnnotation.typeName.name === "const";
19
+ }
20
+ function isOutermostAssertionInChain(node) {
21
+ let current = node;
22
+ let parent = node.parent;
23
+ while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
24
+ current = parent;
25
+ parent = parent.parent;
26
+ }
27
+ return !isTypeAssertionExpression(parent) || parent.expression !== current;
28
+ }
29
+ function isForbiddenAssertionChain(node) {
30
+ let assertionCount = 0;
31
+ let hasNonConstAssertion = false;
32
+ let current = node;
33
+ while (isTypeAssertionExpression(current)) {
34
+ assertionCount += 1;
35
+ hasNonConstAssertion ||= !isConstAssertion(current);
36
+ current = unwrapParenthesizedExpression(current.expression);
37
+ }
38
+ return assertionCount > 1 && hasNonConstAssertion;
39
+ }
40
+ var noChainedTypeAssertionsRule = defineRule({
41
+ meta: {
42
+ type: "problem",
43
+ docs: {
44
+ description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains."
45
+ },
46
+ messages: {
47
+ chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it."
48
+ }
49
+ },
50
+ createOnce(context) {
51
+ const checkTypeAssertion = (node) => {
52
+ if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node))
53
+ return;
54
+ context.report({ node, messageId: "chained" });
55
+ };
56
+ return {
57
+ TSAsExpression: checkTypeAssertion,
58
+ TSTypeAssertion: checkTypeAssertion
59
+ };
60
+ }
61
+ });
62
+
63
+ // ../../tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts
64
+ import { defineRule as defineRule2 } from "@oxlint/plugins";
65
+ function unwrapParentheses(node) {
66
+ let current = node;
67
+ while (current.type === "ParenthesizedExpression") {
68
+ current = current.expression;
69
+ }
70
+ return current;
71
+ }
72
+ function isEmptyObjectExpression(node) {
73
+ return node.type === "ObjectExpression" && node.properties.length === 0;
74
+ }
75
+ function isConditionalEmptyObjectSpread(node) {
76
+ const conditional = unwrapParentheses(node);
77
+ return conditional.type === "ConditionalExpression" && (isEmptyObjectExpression(conditional.consequent) || isEmptyObjectExpression(conditional.alternate));
78
+ }
79
+ var noConditionalEmptyObjectSpreadRule = defineRule2({
80
+ meta: {
81
+ type: "suggestion",
82
+ docs: {
83
+ description: "Disallow object spreads that conditionally spread an empty object to omit fields."
84
+ },
85
+ messages: {
86
+ avoid: "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present."
87
+ }
88
+ },
89
+ createOnce(context) {
90
+ return {
91
+ SpreadElement(node) {
92
+ if (node.parent.type !== "ObjectExpression")
93
+ return;
94
+ if (isConditionalEmptyObjectSpread(node.argument)) {
95
+ context.report({ node, messageId: "avoid" });
96
+ }
97
+ }
98
+ };
99
+ }
100
+ });
101
+
102
+ // ../../tools/oxlint/anti-slop/rules/no-known-value-widening.ts
103
+ import { defineRule as defineRule3 } from "@oxlint/plugins";
104
+
105
+ // ../../tools/oxlint/anti-slop/shared/dictionary-types.ts
106
+ var BUILT_INS = new Set([
107
+ "Record",
108
+ "Readonly",
109
+ "Partial",
110
+ "Required",
111
+ "Pick",
112
+ "Omit",
113
+ "PropertyKey",
114
+ "NonNullable"
115
+ ]);
116
+ var TRANSPARENT_WRAPPERS = new Set([
117
+ "Readonly",
118
+ "Partial",
119
+ "Required",
120
+ "NonNullable"
121
+ ]);
122
+ function declaredStatement(statement) {
123
+ return statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration ?? null : statement;
124
+ }
125
+ function createTypeEnvironment(program) {
126
+ const aliases = new Map;
127
+ const interfaces = new Map;
128
+ const shadowedBuiltIns = new Set;
129
+ for (const statement of program.body) {
130
+ const declaration = declaredStatement(statement);
131
+ if (declaration?.type === "ImportDeclaration") {
132
+ for (const specifier of declaration.specifiers) {
133
+ if (BUILT_INS.has(specifier.local.name))
134
+ shadowedBuiltIns.add(specifier.local.name);
135
+ }
136
+ continue;
137
+ }
138
+ if (declaration?.type === "TSTypeAliasDeclaration") {
139
+ const existing = aliases.get(declaration.id.name);
140
+ if (existing === undefined)
141
+ aliases.set(declaration.id.name, declaration);
142
+ else
143
+ shadowedBuiltIns.add(declaration.id.name);
144
+ if (BUILT_INS.has(declaration.id.name))
145
+ shadowedBuiltIns.add(declaration.id.name);
146
+ continue;
147
+ }
148
+ if (declaration?.type === "TSInterfaceDeclaration") {
149
+ const declarations = interfaces.get(declaration.id.name) ?? [];
150
+ declarations.push(declaration);
151
+ interfaces.set(declaration.id.name, declarations);
152
+ if (BUILT_INS.has(declaration.id.name))
153
+ shadowedBuiltIns.add(declaration.id.name);
154
+ continue;
155
+ }
156
+ if (declaration?.type === "TSEnumDeclaration") {
157
+ if (BUILT_INS.has(declaration.id.name))
158
+ shadowedBuiltIns.add(declaration.id.name);
159
+ continue;
160
+ }
161
+ if ((declaration?.type === "ClassDeclaration" || declaration?.type === "FunctionDeclaration") && declaration.id !== null) {
162
+ if (BUILT_INS.has(declaration.id.name))
163
+ shadowedBuiltIns.add(declaration.id.name);
164
+ }
165
+ }
166
+ return { aliases, interfaces, shadowedBuiltIns };
167
+ }
168
+ function typeReferenceName(type) {
169
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
170
+ }
171
+ function isBuiltIn(name, environment) {
172
+ return BUILT_INS.has(name) && !environment.shadowedBuiltIns.has(name);
173
+ }
174
+ function isUnappliedReferenceTo(type, name) {
175
+ const unwrapped = unwrapTransparentType(type);
176
+ return unwrapped.type === "TSTypeReference" && typeReferenceName(unwrapped) === name && (unwrapped.typeArguments === null || unwrapped.typeArguments === undefined || unwrapped.typeArguments.params.length === 0);
177
+ }
178
+ function unwrapTransparentType(type) {
179
+ let current = type;
180
+ while (current.type === "TSParenthesizedType" || current.type === "TSTypeOperator" && current.operator === "readonly") {
181
+ current = current.typeAnnotation;
182
+ }
183
+ return current;
184
+ }
185
+ function isNeverType(type) {
186
+ return unwrapTransparentType(type).type === "TSNeverKeyword";
187
+ }
188
+ function isEffectivelyEmptyMember(member) {
189
+ return member.type === "TSPropertySignature" && member.optional === true && member.typeAnnotation !== null && member.typeAnnotation !== undefined && isNeverType(member.typeAnnotation.typeAnnotation);
190
+ }
191
+ function isEffectivelyEmptyTypeLiteral(type) {
192
+ return type.members.length === 0 || type.members.every(isEffectivelyEmptyMember);
193
+ }
194
+ function isEffectivelyEmptyInterface(declarations) {
195
+ if (declarations.length !== 1)
196
+ return false;
197
+ const [type] = declarations;
198
+ return type !== undefined && type.extends.length === 0 && (type.body.body.length === 0 || type.body.body.every(isEffectivelyEmptyMember));
199
+ }
200
+ function resolvedSubstitutionArgument(type, base, resolving = new Set) {
201
+ const unwrapped = unwrapTransparentType(type);
202
+ if (unwrapped.type !== "TSTypeReference")
203
+ return type;
204
+ const name = typeReferenceName(unwrapped);
205
+ if (name === null || resolving.has(name))
206
+ return type;
207
+ const substitution = base.get(name);
208
+ if (substitution === undefined)
209
+ return type;
210
+ const nextResolving = new Set(resolving);
211
+ nextResolving.add(name);
212
+ return resolvedSubstitutionArgument(substitution, base, nextResolving);
213
+ }
214
+ function aliasSubstitution(alias, type, base) {
215
+ const parameters = alias.typeParameters?.params ?? [];
216
+ const arguments_ = type.typeArguments?.params ?? [];
217
+ const next = new Map(base);
218
+ for (const [index, parameter] of parameters.entries()) {
219
+ const argument = arguments_[index] ?? parameter.default;
220
+ if (argument === null || argument === undefined)
221
+ return null;
222
+ next.set(parameter.name.name, resolvedSubstitutionArgument(argument, next));
223
+ }
224
+ return next;
225
+ }
226
+ function unsafeDirectValue(type, environment, substitutions, resolvingAliases) {
227
+ const unwrapped = unwrapTransparentType(type);
228
+ if (unwrapped.type === "TSUnknownKeyword")
229
+ return "unknown";
230
+ if (unwrapped.type === "TSAnyKeyword")
231
+ return "any";
232
+ if (unwrapped.type === "TSObjectKeyword")
233
+ return "object";
234
+ if (unwrapped.type === "TSTypeLiteral" && isEffectivelyEmptyTypeLiteral(unwrapped))
235
+ return "empty-object";
236
+ if (unwrapped.type === "TSUnionType") {
237
+ return unwrapped.types.some((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null) ? "union" : null;
238
+ }
239
+ if (unwrapped.type === "TSIntersectionType") {
240
+ const unsafeMembers = unwrapped.types.map((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases));
241
+ if (unsafeMembers.includes("any"))
242
+ return "any";
243
+ return unsafeMembers.length > 0 && unsafeMembers.every((member) => member !== null) ? unsafeMembers[0] : null;
244
+ }
245
+ if (unwrapped.type !== "TSTypeReference")
246
+ return null;
247
+ const name = typeReferenceName(unwrapped);
248
+ if (name === null)
249
+ return null;
250
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, environment)) {
251
+ const wrapped = unwrapped.typeArguments?.params[0];
252
+ return wrapped === undefined ? null : unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
253
+ }
254
+ const substitution = substitutions.get(name);
255
+ if (substitution !== undefined) {
256
+ return isUnappliedReferenceTo(substitution, name) ? null : unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
257
+ }
258
+ const interfaceDeclarations = environment.interfaces.get(name);
259
+ if (interfaceDeclarations !== undefined) {
260
+ return isEffectivelyEmptyInterface(interfaceDeclarations) ? "empty-object" : null;
261
+ }
262
+ const alias = environment.aliases.get(name);
263
+ if (alias === undefined || resolvingAliases.has(name))
264
+ return null;
265
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
266
+ if (nextSubstitutions === null)
267
+ return null;
268
+ const nextResolving = new Set(resolvingAliases);
269
+ nextResolving.add(name);
270
+ return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
271
+ }
272
+ function dictionaryValueTypes(type, environment, substitutions, resolvingAliases) {
273
+ const unwrapped = unwrapTransparentType(type);
274
+ if (unwrapped.type === "TSTypeLiteral") {
275
+ return unwrapped.members.flatMap((member) => member.type === "TSIndexSignature" && member.typeAnnotation !== null ? [{ type: member.typeAnnotation.typeAnnotation, substitutions }] : []);
276
+ }
277
+ if (unwrapped.type === "TSMappedType") {
278
+ return unwrapped.typeAnnotation === null ? [] : [{ type: unwrapped.typeAnnotation, substitutions }];
279
+ }
280
+ if (unwrapped.type !== "TSTypeReference")
281
+ return [];
282
+ const name = typeReferenceName(unwrapped);
283
+ if (name === null)
284
+ return [];
285
+ const substitution = substitutions.get(name);
286
+ if (substitution !== undefined) {
287
+ return isUnappliedReferenceTo(substitution, name) ? [] : dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
288
+ }
289
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, environment)) {
290
+ const wrapped = unwrapped.typeArguments?.params[0];
291
+ return wrapped === undefined ? [] : dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
292
+ }
293
+ if (name === "Record" && isBuiltIn(name, environment)) {
294
+ const value = unwrapped.typeArguments?.params[1] ?? null;
295
+ return value === null ? [] : [{ type: value, substitutions }];
296
+ }
297
+ if ((name === "Pick" || name === "Omit") && isBuiltIn(name, environment)) {
298
+ const source = unwrapped.typeArguments?.params[0];
299
+ return source === undefined ? [] : dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
300
+ }
301
+ const alias = environment.aliases.get(name);
302
+ if (alias === undefined || resolvingAliases.has(name))
303
+ return [];
304
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
305
+ if (nextSubstitutions === null)
306
+ return [];
307
+ const nextResolving = new Set(resolvingAliases);
308
+ nextResolving.add(name);
309
+ return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
310
+ }
311
+ function classifyUnsafeDictionaryValue(valueType, environment) {
312
+ const unsafeValue = unsafeDirectValue(valueType, environment, new Map, new Set);
313
+ return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
314
+ }
315
+ function classifyUnsafeDictionary(type, environment) {
316
+ for (const valueType of dictionaryValueTypes(type, environment, new Map, new Set)) {
317
+ const unsafeValue = unsafeDirectValue(valueType.type, environment, valueType.substitutions, new Set);
318
+ if (unsafeValue !== null)
319
+ return { kind: "unsafe-dictionary", unsafeValue };
320
+ }
321
+ return null;
322
+ }
323
+ function resolvesToDictionary(type, environment, substitutions, resolvingAliases) {
324
+ return dictionaryValueTypes(type, environment, substitutions, resolvingAliases).length > 0;
325
+ }
326
+ function classifyWideningTarget(type, environment) {
327
+ const unwrapped = unwrapTransparentType(type);
328
+ if (unwrapped.type === "TSUnknownKeyword")
329
+ return { kind: "unknown" };
330
+ if (unwrapped.type === "TSObjectKeyword")
331
+ return { kind: "object" };
332
+ if (unwrapped.type === "TSTypeLiteral") {
333
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature") ? { kind: "open dictionary" } : unwrapped.members.length > 0 ? { kind: "anonymous object" } : null;
334
+ }
335
+ if (unwrapped.type === "TSMappedType")
336
+ return { kind: "open dictionary" };
337
+ if (unwrapped.type !== "TSTypeReference")
338
+ return null;
339
+ const name = typeReferenceName(unwrapped);
340
+ if (name === null)
341
+ return null;
342
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, environment)) {
343
+ const wrapped = unwrapped.typeArguments?.params[0];
344
+ return wrapped === undefined ? null : classifyWideningTarget(wrapped, environment);
345
+ }
346
+ if (name === "Record" && isBuiltIn(name, environment))
347
+ return { kind: "open dictionary" };
348
+ const alias = environment.aliases.get(name);
349
+ if (alias === undefined)
350
+ return null;
351
+ if ((alias.typeParameters?.params.length ?? 0) > 0) {
352
+ const substitutions2 = aliasSubstitution(alias, unwrapped, new Map);
353
+ return substitutions2 !== null && resolvesToDictionary(alias.typeAnnotation, environment, substitutions2, new Set([name])) ? { kind: "generic container" } : null;
354
+ }
355
+ const substitutions = aliasSubstitution(alias, unwrapped, new Map);
356
+ if (substitutions === null)
357
+ return null;
358
+ const resolved = classifyAliasBroadTarget(alias.typeAnnotation, environment, substitutions, new Set([name]));
359
+ return resolved;
360
+ }
361
+ function isBroadMappedKey(type, environment, substitutions) {
362
+ const unwrapped = unwrapTransparentType(type);
363
+ if (unwrapped.type === "TSStringKeyword" || unwrapped.type === "TSNumberKeyword" || unwrapped.type === "TSSymbolKeyword") {
364
+ return true;
365
+ }
366
+ if (unwrapped.type === "TSUnionType") {
367
+ return unwrapped.types.every((member) => isBroadMappedKey(member, environment, substitutions));
368
+ }
369
+ if (unwrapped.type !== "TSTypeReference")
370
+ return false;
371
+ const name = typeReferenceName(unwrapped);
372
+ if (name === null)
373
+ return false;
374
+ const substitution = substitutions.get(name);
375
+ if (substitution !== undefined && !isUnappliedReferenceTo(substitution, name)) {
376
+ return isBroadMappedKey(substitution, environment, substitutions);
377
+ }
378
+ return name === "PropertyKey" && isBuiltIn(name, environment);
379
+ }
380
+ function classifyAliasBroadTarget(type, environment, substitutions, resolvingAliases) {
381
+ const unwrapped = unwrapTransparentType(type);
382
+ if (unwrapped.type === "TSUnknownKeyword")
383
+ return { kind: "unknown" };
384
+ if (unwrapped.type === "TSObjectKeyword")
385
+ return { kind: "object" };
386
+ if (unwrapped.type === "TSTypeLiteral") {
387
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature") ? { kind: "open dictionary" } : null;
388
+ }
389
+ if (unwrapped.type === "TSMappedType") {
390
+ return isBroadMappedKey(unwrapped.constraint, environment, substitutions) ? { kind: "open dictionary" } : null;
391
+ }
392
+ if (unwrapped.type !== "TSTypeReference")
393
+ return null;
394
+ const name = typeReferenceName(unwrapped);
395
+ if (name === null)
396
+ return null;
397
+ const substitution = substitutions.get(name);
398
+ if (substitution !== undefined) {
399
+ return isUnappliedReferenceTo(substitution, name) ? null : classifyAliasBroadTarget(substitution, environment, substitutions, resolvingAliases);
400
+ }
401
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, environment)) {
402
+ const wrapped = unwrapped.typeArguments?.params[0];
403
+ return wrapped === undefined ? null : classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
404
+ }
405
+ if (name === "Record" && isBuiltIn(name, environment)) {
406
+ return { kind: "open dictionary" };
407
+ }
408
+ const alias = environment.aliases.get(name);
409
+ if (alias === undefined || resolvingAliases.has(name))
410
+ return null;
411
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
412
+ if (nextSubstitutions === null)
413
+ return null;
414
+ const nextResolving = new Set(resolvingAliases);
415
+ nextResolving.add(name);
416
+ return classifyAliasBroadTarget(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
417
+ }
418
+ function isKnownEvidenceExpression(expression) {
419
+ let current = expression;
420
+ while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression" || current.type === "TSSatisfiesExpression") {
421
+ current = current.expression;
422
+ }
423
+ if (current.type === "ObjectExpression")
424
+ return true;
425
+ return current.type === "ArrayExpression" || current.type === "ArrowFunctionExpression" || current.type === "ClassExpression" || current.type === "FunctionExpression" || current.type === "NewExpression" || current.type === "Literal" || current.type === "TemplateLiteral" || current.type === "UnaryExpression";
426
+ }
427
+
428
+ // ../../tools/oxlint/anti-slop/rules/no-known-value-widening.ts
429
+ function unwrapExpression(expression) {
430
+ let current = expression;
431
+ while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") {
432
+ current = current.expression;
433
+ }
434
+ return current;
435
+ }
436
+ function resolveVariable(sourceCode, identifier) {
437
+ let scope = sourceCode.getScope(identifier);
438
+ while (scope !== null) {
439
+ const variable = scope.set.get(identifier.name);
440
+ if (variable !== undefined)
441
+ return variable;
442
+ scope = scope.upper;
443
+ }
444
+ return null;
445
+ }
446
+ function variableDeclarator(variable) {
447
+ if (variable.defs.length !== 1)
448
+ return null;
449
+ const [definition] = variable.defs;
450
+ return definition?.type === "Variable" && definition.node.type === "VariableDeclarator" ? definition.node : null;
451
+ }
452
+ function isStableConstVariable(variable, declarator) {
453
+ return declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" && variable.references.every((reference) => reference.init || !reference.isWrite());
454
+ }
455
+ function hasKnownEvidence(sourceCode, expression, visitedVariables = new Set) {
456
+ if (isKnownEvidenceExpression(expression))
457
+ return true;
458
+ const unwrapped = unwrapExpression(expression);
459
+ if (unwrapped.type !== "Identifier")
460
+ return false;
461
+ const variable = resolveVariable(sourceCode, unwrapped);
462
+ if (variable === null || visitedVariables.has(variable))
463
+ return false;
464
+ const declarator = variableDeclarator(variable);
465
+ if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) {
466
+ return false;
467
+ }
468
+ visitedVariables.add(variable);
469
+ return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
470
+ }
471
+ function annotationTarget(annotation, environment) {
472
+ return annotation === null || annotation === undefined ? null : classifyWideningTarget(annotation.typeAnnotation, environment);
473
+ }
474
+ function enclosingFunction(node) {
475
+ let current = node.parent;
476
+ while (current !== null && current.type !== "Program") {
477
+ if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") {
478
+ return current;
479
+ }
480
+ current = current.parent;
481
+ }
482
+ return null;
483
+ }
484
+ function sourceKeyName(sourceCode, key) {
485
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier")
486
+ return key.name;
487
+ if (key.type === "Literal")
488
+ return String(key.value);
489
+ return sourceCode.getText(key);
490
+ }
491
+ function functionName(sourceCode, owner) {
492
+ if (owner === null)
493
+ return "anonymous function";
494
+ if (owner.id !== null)
495
+ return owner.id.name;
496
+ const parent = owner.parent;
497
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
498
+ return parent.id.name;
499
+ if (parent.type === "MethodDefinition")
500
+ return sourceKeyName(sourceCode, parent.key);
501
+ return "anonymous function";
502
+ }
503
+ function isEmptyObjectExpression2(expression) {
504
+ const unwrapped = unwrapExpression(expression);
505
+ return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
506
+ }
507
+ function isDictionaryAccumulatorTarget(destination) {
508
+ return destination.kind === "open dictionary" || destination.kind === "generic container";
509
+ }
510
+ function hasParentAssertion(node) {
511
+ return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
512
+ }
513
+ var noKnownValueWideningRule = defineRule3({
514
+ meta: {
515
+ type: "problem",
516
+ docs: {
517
+ description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence."
518
+ },
519
+ messages: {
520
+ widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract."
521
+ }
522
+ },
523
+ createOnce(context) {
524
+ let environment = null;
525
+ const reportFlow = (expression, destination, subject) => {
526
+ if (destination === null)
527
+ return;
528
+ if (isDictionaryAccumulatorTarget(destination) && isEmptyObjectExpression2(expression)) {
529
+ return;
530
+ }
531
+ if (!hasKnownEvidence(context.sourceCode, expression))
532
+ return;
533
+ context.report({
534
+ node: expression,
535
+ messageId: "widening",
536
+ data: { subject, target: destination.kind }
537
+ });
538
+ };
539
+ const targetFromAnnotation = (annotation) => environment === null ? null : annotationTarget(annotation, environment);
540
+ return {
541
+ Program(node) {
542
+ environment = createTypeEnvironment(node);
543
+ },
544
+ VariableDeclarator(node) {
545
+ if (node.init === null || node.id.type !== "Identifier")
546
+ return;
547
+ reportFlow(node.init, targetFromAnnotation(node.id.typeAnnotation), `binding \`${node.id.name}\``);
548
+ },
549
+ PropertyDefinition(node) {
550
+ if (node.value === null)
551
+ return;
552
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
553
+ },
554
+ AccessorProperty(node) {
555
+ if (node.value === null)
556
+ return;
557
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
558
+ },
559
+ AssignmentExpression(node) {
560
+ if (node.operator !== "=" || node.left.type !== "Identifier")
561
+ return;
562
+ const variable = resolveVariable(context.sourceCode, node.left);
563
+ if (variable === null)
564
+ return;
565
+ const declarator = variableDeclarator(variable);
566
+ if (declarator === null || declarator.id.type !== "Identifier")
567
+ return;
568
+ reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
569
+ },
570
+ ReturnStatement(node) {
571
+ if (node.argument === null)
572
+ return;
573
+ const owner = enclosingFunction(node);
574
+ reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
575
+ },
576
+ ArrowFunctionExpression(node) {
577
+ if (node.body.type === "BlockStatement")
578
+ return;
579
+ reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
580
+ },
581
+ TSAsExpression(node) {
582
+ if (environment === null || hasParentAssertion(node))
583
+ return;
584
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
585
+ },
586
+ TSTypeAssertion(node) {
587
+ if (environment === null || hasParentAssertion(node))
588
+ return;
589
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
590
+ }
591
+ };
592
+ }
593
+ });
594
+
595
+ // ../../tools/oxlint/anti-slop/rules/no-module-mocking.ts
596
+ import { defineRule as defineRule4 } from "@oxlint/plugins";
597
+ var moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
598
+ function resolveVariable2(sourceCode, identifier) {
599
+ let scope = sourceCode.getScope(identifier);
600
+ while (scope !== null) {
601
+ const variable = scope.set.get(identifier.name);
602
+ if (variable !== undefined)
603
+ return variable;
604
+ scope = scope.upper;
605
+ }
606
+ return null;
607
+ }
608
+ function importedName(node) {
609
+ if (node.type !== "ImportSpecifier")
610
+ return null;
611
+ return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
612
+ }
613
+ function isTestFrameworkObject(sourceCode, expression) {
614
+ if (expression.type !== "Identifier")
615
+ return false;
616
+ if ((expression.name === "vi" || expression.name === "jest") && sourceCode.isGlobalReference(expression)) {
617
+ return true;
618
+ }
619
+ const variable = resolveVariable2(sourceCode, expression);
620
+ if (variable === null || variable.defs.length === 0) {
621
+ return expression.name === "vi" || expression.name === "jest";
622
+ }
623
+ return variable.defs.some((definition) => {
624
+ if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
625
+ return false;
626
+ }
627
+ const source = definition.parent.source.value;
628
+ const name = importedName(definition.node);
629
+ return source === "vitest" && name === "vi" || source === "@jest/globals" && name === "jest";
630
+ });
631
+ }
632
+ function moduleMockCall(sourceCode, callee) {
633
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
634
+ return false;
635
+ if (!isTestFrameworkObject(sourceCode, callee.object))
636
+ return false;
637
+ const property = callee.property;
638
+ const method = callee.computed ? property.type === "Literal" && (property.value === "doMock" || property.value === "mock" || property.value === "unstable_mockModule") ? property.value : null : property.type === "Identifier" ? property.name : null;
639
+ return method !== null && moduleMockMethods.has(method);
640
+ }
641
+ var noModuleMockingRule = defineRule4({
642
+ meta: {
643
+ type: "problem",
644
+ docs: {
645
+ description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces."
646
+ },
647
+ messages: {
648
+ moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation."
649
+ }
650
+ },
651
+ createOnce(context) {
652
+ return {
653
+ CallExpression(node) {
654
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
655
+ return;
656
+ if (moduleMockCall(context.sourceCode, node.callee)) {
657
+ context.report({ node, messageId: "moduleMock" });
658
+ }
659
+ }
660
+ };
661
+ }
662
+ });
663
+
664
+ // ../../tools/oxlint/anti-slop/rules/no-object-parameters.ts
665
+ import { defineRule as defineRule5 } from "@oxlint/plugins";
666
+
667
+ // ../../tools/oxlint/anti-slop/shared/lexical-type-parameters.ts
668
+ function isNode(value) {
669
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
670
+ }
671
+ function collectInferTypeParameterNames(node, visitorKeys, names) {
672
+ if (node.type === "TSInferType")
673
+ names.add(node.typeParameter.name.name);
674
+ const record = node;
675
+ for (const key of visitorKeys[node.type] ?? []) {
676
+ const value = record[key];
677
+ if (isNode(value)) {
678
+ collectInferTypeParameterNames(value, visitorKeys, names);
679
+ continue;
680
+ }
681
+ if (!Array.isArray(value))
682
+ continue;
683
+ for (const child of value) {
684
+ if (isNode(child))
685
+ collectInferTypeParameterNames(child, visitorKeys, names);
686
+ }
687
+ }
688
+ }
689
+ function lexicalTypeParameterNames(node, visitorKeys) {
690
+ const names = new Set;
691
+ let descendant = node;
692
+ let current = node;
693
+ while (current !== null && current.type !== "Program") {
694
+ if ("typeParameters" in current) {
695
+ for (const parameter of current.typeParameters?.params ?? []) {
696
+ names.add(parameter.name.name);
697
+ }
698
+ }
699
+ if (current.type === "TSMappedType" && (descendant === current.nameType || descendant === current.typeAnnotation)) {
700
+ names.add(current.key.name);
701
+ }
702
+ if (current.type === "TSConditionalType" && descendant === current.trueType) {
703
+ collectInferTypeParameterNames(current.extendsType, visitorKeys, names);
704
+ }
705
+ descendant = current;
706
+ current = current.parent;
707
+ }
708
+ return names;
709
+ }
710
+
711
+ // ../../tools/oxlint/anti-slop/rules/no-object-parameters.ts
712
+ function parameterAnnotation(parameter) {
713
+ if (parameter.type === "TSParameterProperty") {
714
+ return parameterAnnotation(parameter.parameter);
715
+ }
716
+ if (parameter.type === "RestElement") {
717
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
718
+ }
719
+ if (parameter.type === "AssignmentPattern") {
720
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
721
+ }
722
+ return parameter.typeAnnotation;
723
+ }
724
+ function parameterName(parameter, sourceCode) {
725
+ return parameter.type === "Identifier" ? parameter.name : sourceCode.getText(parameter).replace(/\s*:\s*object\s*$/u, "");
726
+ }
727
+ var noObjectParametersRule = defineRule5({
728
+ meta: {
729
+ type: "problem",
730
+ docs: {
731
+ description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary."
732
+ },
733
+ messages: {
734
+ objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function."
735
+ }
736
+ },
737
+ createOnce(context) {
738
+ const aliases = new Map;
739
+ const resolvesToObject = (type, shadowedAliases, visited = new Set) => {
740
+ if (type.type === "TSObjectKeyword")
741
+ return true;
742
+ if (type.type === "TSParenthesizedType")
743
+ return resolvesToObject(type.typeAnnotation, shadowedAliases, visited);
744
+ if (type.type === "TSUnionType") {
745
+ return type.types.some((member) => resolvesToObject(member, shadowedAliases, visited));
746
+ }
747
+ if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier" || type.typeArguments !== null && type.typeArguments !== undefined && type.typeArguments.params.length > 0 || visited.has(type.typeName.name) || shadowedAliases.has(type.typeName.name)) {
748
+ return false;
749
+ }
750
+ const alias = aliases.get(type.typeName.name);
751
+ if (alias === undefined)
752
+ return false;
753
+ const nextVisited = new Set(visited);
754
+ nextVisited.add(type.typeName.name);
755
+ return resolvesToObject(alias, shadowedAliases, nextVisited);
756
+ };
757
+ const checkParameters = (node) => {
758
+ const shadowedAliases = lexicalTypeParameterNames(node, context.sourceCode.visitorKeys);
759
+ for (const parameter of node.params) {
760
+ const annotation = parameterAnnotation(parameter);
761
+ if (annotation === null || annotation === undefined)
762
+ continue;
763
+ if (!resolvesToObject(annotation.typeAnnotation, shadowedAliases))
764
+ continue;
765
+ context.report({
766
+ node: annotation.typeAnnotation,
767
+ messageId: "objectParameter",
768
+ data: { parameter: parameterName(parameter, context.sourceCode) }
769
+ });
770
+ }
771
+ };
772
+ return {
773
+ Program(node) {
774
+ aliases.clear();
775
+ for (const statement of node.body) {
776
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
777
+ if (declaration?.type === "TSTypeAliasDeclaration" && (declaration.typeParameters === null || declaration.typeParameters === undefined)) {
778
+ aliases.set(declaration.id.name, declaration.typeAnnotation);
779
+ }
780
+ }
781
+ },
782
+ ArrowFunctionExpression: checkParameters,
783
+ FunctionDeclaration: checkParameters,
784
+ FunctionExpression: checkParameters,
785
+ TSCallSignatureDeclaration: checkParameters,
786
+ TSConstructSignatureDeclaration: checkParameters,
787
+ TSConstructorType: checkParameters,
788
+ TSDeclareFunction: checkParameters,
789
+ TSEmptyBodyFunctionExpression: checkParameters,
790
+ TSFunctionType: checkParameters,
791
+ TSMethodSignature: checkParameters
792
+ };
793
+ }
794
+ });
795
+
796
+ // ../../tools/oxlint/anti-slop/rules/no-reflect-apply.ts
797
+ import { defineRule as defineRule6 } from "@oxlint/plugins";
798
+
799
+ // ../../tools/oxlint/anti-slop/shared/reflect-method.ts
800
+ function resolveVariable3(sourceCode, identifier) {
801
+ let scope = sourceCode.getScope(identifier);
802
+ while (scope !== null) {
803
+ const variable = scope.set.get(identifier.name);
804
+ if (variable !== undefined)
805
+ return variable;
806
+ scope = scope.upper;
807
+ }
808
+ return null;
809
+ }
810
+ function isGlobalReflect(sourceCode, expression) {
811
+ if (expression.type !== "Identifier" || expression.name !== "Reflect")
812
+ return false;
813
+ if (sourceCode.isGlobalReference(expression))
814
+ return true;
815
+ const variable = resolveVariable3(sourceCode, expression);
816
+ return variable === null || variable.defs.length === 0;
817
+ }
818
+ function isGlobalReflectMethodCall(sourceCode, callee, methodName) {
819
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
820
+ return false;
821
+ if (!isGlobalReflect(sourceCode, callee.object))
822
+ return false;
823
+ const property = callee.property;
824
+ return callee.computed ? property.type === "Literal" && property.value === methodName : property.type === "Identifier" && property.name === methodName;
825
+ }
826
+
827
+ // ../../tools/oxlint/anti-slop/rules/no-reflect-apply.ts
828
+ var noReflectApplyRule = defineRule6({
829
+ meta: {
830
+ type: "problem",
831
+ docs: {
832
+ description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface."
833
+ },
834
+ messages: {
835
+ reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface."
836
+ }
837
+ },
838
+ createOnce(context) {
839
+ return {
840
+ CallExpression(node) {
841
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
842
+ return;
843
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "apply")) {
844
+ context.report({ node, messageId: "reflectApply" });
845
+ }
846
+ }
847
+ };
848
+ }
849
+ });
850
+
851
+ // ../../tools/oxlint/anti-slop/rules/no-reflect-get.ts
852
+ import { defineRule as defineRule7 } from "@oxlint/plugins";
853
+ var noReflectGetRule = defineRule7({
854
+ meta: {
855
+ type: "problem",
856
+ docs: {
857
+ description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type."
858
+ },
859
+ messages: {
860
+ reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it."
861
+ }
862
+ },
863
+ createOnce(context) {
864
+ return {
865
+ CallExpression(node) {
866
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
867
+ return;
868
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "get")) {
869
+ context.report({ node, messageId: "reflectGet" });
870
+ }
871
+ }
872
+ };
873
+ }
874
+ });
875
+
876
+ // ../../tools/oxlint/anti-slop/rules/no-runtime-typeof.ts
877
+ import { defineRule as defineRule8 } from "@oxlint/plugins";
878
+ function isRuntimeFunction(node) {
879
+ return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
880
+ }
881
+ function isInsideTypeGuard(node) {
882
+ let current = node.parent;
883
+ while (current !== null && current.type !== "Program") {
884
+ if (isRuntimeFunction(current)) {
885
+ return current.returnType?.typeAnnotation.type === "TSTypePredicate";
886
+ }
887
+ current = current.parent;
888
+ }
889
+ return false;
890
+ }
891
+ var noRuntimeTypeofRule = defineRule8({
892
+ meta: {
893
+ type: "problem",
894
+ docs: {
895
+ description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary."
896
+ },
897
+ messages: {
898
+ runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value."
899
+ },
900
+ schema: [
901
+ {
902
+ type: "object",
903
+ properties: {
904
+ allowInTypeGuards: { type: "boolean" }
905
+ },
906
+ additionalProperties: false
907
+ }
908
+ ],
909
+ defaultOptions: [{ allowInTypeGuards: false }]
910
+ },
911
+ createOnce(context) {
912
+ return {
913
+ UnaryExpression(node) {
914
+ const option = context.options?.[0];
915
+ const allowInTypeGuards = typeof option === "object" && option !== null && !Array.isArray(option) && option.allowInTypeGuards === true;
916
+ if (node.operator === "typeof" && (!allowInTypeGuards || !isInsideTypeGuard(node))) {
917
+ context.report({ node, messageId: "runtimeTypeof" });
918
+ }
919
+ }
920
+ };
921
+ }
922
+ });
923
+
924
+ // ../../tools/oxlint/anti-slop/rules/no-shape-in-symbol-names.ts
925
+ import { defineRule as defineRule9 } from "@oxlint/plugins";
926
+ var FORBIDDEN_SYMBOL_NAME = "shape";
927
+ function containsForbiddenSymbolName(name) {
928
+ return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
929
+ }
930
+ var noForbiddenTermInSymbolNamesRule = defineRule9({
931
+ meta: {
932
+ type: "problem",
933
+ docs: {
934
+ description: 'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.'
935
+ },
936
+ messages: {
937
+ forbiddenSymbolName: 'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.'
938
+ }
939
+ },
940
+ createOnce(context) {
941
+ const reportForbiddenSymbolName = (node) => {
942
+ if (!containsForbiddenSymbolName(node.name))
943
+ return;
944
+ const parent = node.parent;
945
+ if (parent?.type === "ExportSpecifier" && parent.exported === node && parent.local.type === "Identifier" && parent.local.name !== node.name) {
946
+ return;
947
+ }
948
+ context.report({
949
+ node,
950
+ messageId: "forbiddenSymbolName",
951
+ data: { name: node.name }
952
+ });
953
+ };
954
+ return {
955
+ Identifier: reportForbiddenSymbolName,
956
+ PrivateIdentifier: reportForbiddenSymbolName,
957
+ JSXIdentifier: reportForbiddenSymbolName
958
+ };
959
+ }
960
+ });
961
+
962
+ // ../../tools/oxlint/anti-slop/rules/no-unknown-parameters.ts
963
+ import { defineRule as defineRule10 } from "@oxlint/plugins";
964
+ function parameterAnnotation2(parameter) {
965
+ if (parameter.type === "TSParameterProperty") {
966
+ return parameterAnnotation2(parameter.parameter);
967
+ }
968
+ if (parameter.type === "RestElement") {
969
+ return parameter.typeAnnotation ?? parameterAnnotation2(parameter.argument);
970
+ }
971
+ if (parameter.type === "AssignmentPattern") {
972
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
973
+ }
974
+ return parameter.typeAnnotation;
975
+ }
976
+ function parameterName2(parameter, sourceText) {
977
+ if (parameter.type === "TSParameterProperty") {
978
+ return parameterName2(parameter.parameter, sourceText);
979
+ }
980
+ if (parameter.type === "AssignmentPattern") {
981
+ return parameterName2(parameter.left, sourceText);
982
+ }
983
+ if (parameter.type === "RestElement") {
984
+ return parameterName2(parameter.argument, sourceText);
985
+ }
986
+ return parameter.type === "Identifier" ? parameter.name : sourceText.replace(/\s*:\s*unknown\s*$/u, "");
987
+ }
988
+ var noUnknownParametersRule = defineRule10({
989
+ meta: {
990
+ type: "problem",
991
+ docs: {
992
+ description: "Disallow explicitly unknown function parameters except `cause`; decode unknown input at its I/O boundary instead."
993
+ },
994
+ messages: {
995
+ unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function."
996
+ }
997
+ },
998
+ createOnce(context) {
999
+ const checkParameters = (node) => {
1000
+ for (const parameter of node.params) {
1001
+ const annotation = parameterAnnotation2(parameter);
1002
+ if (annotation?.typeAnnotation.type !== "TSUnknownKeyword")
1003
+ continue;
1004
+ const name = parameterName2(parameter, context.sourceCode.getText(parameter));
1005
+ if (name === "cause")
1006
+ continue;
1007
+ context.report({
1008
+ node: annotation.typeAnnotation,
1009
+ messageId: "unknownParameter",
1010
+ data: { parameter: name }
1011
+ });
1012
+ }
1013
+ };
1014
+ return {
1015
+ ArrowFunctionExpression: checkParameters,
1016
+ FunctionDeclaration: checkParameters,
1017
+ FunctionExpression: checkParameters,
1018
+ TSCallSignatureDeclaration: checkParameters,
1019
+ TSConstructSignatureDeclaration: checkParameters,
1020
+ TSConstructorType: checkParameters,
1021
+ TSDeclareFunction: checkParameters,
1022
+ TSEmptyBodyFunctionExpression: checkParameters,
1023
+ TSFunctionType: checkParameters,
1024
+ TSMethodSignature: checkParameters
1025
+ };
1026
+ }
1027
+ });
1028
+
1029
+ // ../../tools/oxlint/anti-slop/rules/no-unknown-returns.ts
1030
+ import { defineRule as defineRule11 } from "@oxlint/plugins";
1031
+ function referencedAliasName(type) {
1032
+ if (type.type === "TSParenthesizedType")
1033
+ return referencedAliasName(type.typeAnnotation);
1034
+ if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
1035
+ return null;
1036
+ return type.typeArguments === null || type.typeArguments === undefined || type.typeArguments.params.length === 0 ? type.typeName.name : null;
1037
+ }
1038
+ var noUnknownReturnsRule = defineRule11({
1039
+ meta: {
1040
+ type: "problem",
1041
+ docs: {
1042
+ description: "Disallow functions whose explicit return contract is unknown or Promise<unknown>."
1043
+ },
1044
+ messages: {
1045
+ unknownReturn: "This function exposes `unknown` to its caller. Parse the value at its boundary and return a named domain type."
1046
+ }
1047
+ },
1048
+ createOnce(context) {
1049
+ const aliases = new Map;
1050
+ const resolvesToUnknown = (type, shadowedAliases, visited = new Set) => {
1051
+ if (type.type === "TSUnknownKeyword")
1052
+ return true;
1053
+ if (type.type === "TSParenthesizedType") {
1054
+ return resolvesToUnknown(type.typeAnnotation, shadowedAliases, visited);
1055
+ }
1056
+ if (type.type === "TSUnionType") {
1057
+ return type.types.some((member) => resolvesToUnknown(member, shadowedAliases, visited));
1058
+ }
1059
+ if (type.type === "TSTypeReference" && type.typeName.type === "Identifier" && (type.typeName.name === "Promise" || type.typeName.name === "PromiseLike")) {
1060
+ const value = type.typeArguments?.params[0];
1061
+ return value !== undefined && resolvesToUnknown(value, shadowedAliases, visited);
1062
+ }
1063
+ const name = referencedAliasName(type);
1064
+ if (name === null || visited.has(name) || shadowedAliases.has(name))
1065
+ return false;
1066
+ const alias = aliases.get(name);
1067
+ if (alias === undefined || alias.typeParameters !== null && alias.typeParameters !== undefined) {
1068
+ return false;
1069
+ }
1070
+ const nextVisited = new Set(visited);
1071
+ nextVisited.add(name);
1072
+ return resolvesToUnknown(alias.typeAnnotation, shadowedAliases, nextVisited);
1073
+ };
1074
+ const checkReturnType = (node) => {
1075
+ const annotation = node.returnType;
1076
+ if (annotation === null || annotation === undefined)
1077
+ return;
1078
+ if (!resolvesToUnknown(annotation.typeAnnotation, lexicalTypeParameterNames(node, context.sourceCode.visitorKeys))) {
1079
+ return;
1080
+ }
1081
+ context.report({
1082
+ node: annotation.typeAnnotation,
1083
+ messageId: "unknownReturn"
1084
+ });
1085
+ };
1086
+ return {
1087
+ Program(node) {
1088
+ aliases.clear();
1089
+ for (const statement of node.body) {
1090
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
1091
+ if (declaration?.type === "TSTypeAliasDeclaration") {
1092
+ aliases.set(declaration.id.name, declaration);
1093
+ }
1094
+ }
1095
+ },
1096
+ ArrowFunctionExpression: checkReturnType,
1097
+ FunctionDeclaration: checkReturnType,
1098
+ FunctionExpression: checkReturnType,
1099
+ TSCallSignatureDeclaration: checkReturnType,
1100
+ TSConstructSignatureDeclaration: checkReturnType,
1101
+ TSConstructorType: checkReturnType,
1102
+ TSDeclareFunction: checkReturnType,
1103
+ TSEmptyBodyFunctionExpression: checkReturnType,
1104
+ TSFunctionType: checkReturnType,
1105
+ TSMethodSignature: checkReturnType
1106
+ };
1107
+ }
1108
+ });
1109
+
1110
+ // ../../tools/oxlint/anti-slop/rules/no-unknown-type-aliases.ts
1111
+ import { defineRule as defineRule12 } from "@oxlint/plugins";
1112
+ function referencedAliasName2(type) {
1113
+ if (type.type === "TSParenthesizedType")
1114
+ return referencedAliasName2(type.typeAnnotation);
1115
+ if (type.type !== "TSTypeReference" || type.typeName.type !== "Identifier")
1116
+ return null;
1117
+ return type.typeArguments === null || type.typeArguments === undefined || type.typeArguments.params.length === 0 ? type.typeName.name : null;
1118
+ }
1119
+ var noUnknownTypeAliasesRule = defineRule12({
1120
+ meta: {
1121
+ type: "problem",
1122
+ docs: {
1123
+ description: "Disallow type aliases whose resolved type is unknown; unknown must remain visible at an allowed boundary."
1124
+ },
1125
+ messages: {
1126
+ unknownAlias: "Type alias `{{alias}}` hides `unknown`. Keep `unknown` explicit at the parsing boundary or on an allowed `cause` field; otherwise use the parsed owner type."
1127
+ }
1128
+ },
1129
+ createOnce(context) {
1130
+ const aliases = new Map;
1131
+ const resolvesToUnknown = (type, visited = new Set) => {
1132
+ if (type.type === "TSUnknownKeyword")
1133
+ return true;
1134
+ if (type.type === "TSParenthesizedType")
1135
+ return resolvesToUnknown(type.typeAnnotation, visited);
1136
+ const name = referencedAliasName2(type);
1137
+ if (name === null || visited.has(name))
1138
+ return false;
1139
+ const alias = aliases.get(name);
1140
+ if (alias === undefined || alias.typeParameters !== null && alias.typeParameters !== undefined) {
1141
+ return false;
1142
+ }
1143
+ const nextVisited = new Set(visited);
1144
+ nextVisited.add(name);
1145
+ return resolvesToUnknown(alias.typeAnnotation, nextVisited);
1146
+ };
1147
+ return {
1148
+ Program(node) {
1149
+ aliases.clear();
1150
+ for (const statement of node.body) {
1151
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
1152
+ if (declaration?.type === "TSTypeAliasDeclaration") {
1153
+ aliases.set(declaration.id.name, declaration);
1154
+ }
1155
+ }
1156
+ for (const alias of aliases.values()) {
1157
+ if (!resolvesToUnknown(alias.typeAnnotation, new Set([alias.id.name])))
1158
+ continue;
1159
+ context.report({
1160
+ node: alias.id,
1161
+ messageId: "unknownAlias",
1162
+ data: { alias: alias.id.name }
1163
+ });
1164
+ }
1165
+ }
1166
+ };
1167
+ }
1168
+ });
1169
+
1170
+ // ../../tools/oxlint/anti-slop/rules/no-unsafe-dictionary-type.ts
1171
+ import { defineRule as defineRule13 } from "@oxlint/plugins";
1172
+ var typeNodeKinds = new Set([
1173
+ "JSDocNonNullableType",
1174
+ "JSDocNullableType",
1175
+ "JSDocUnknownType",
1176
+ "TSAnyKeyword",
1177
+ "TSArrayType",
1178
+ "TSBigIntKeyword",
1179
+ "TSBooleanKeyword",
1180
+ "TSConditionalType",
1181
+ "TSConstructorType",
1182
+ "TSFunctionType",
1183
+ "TSImportType",
1184
+ "TSIndexedAccessType",
1185
+ "TSInferType",
1186
+ "TSIntersectionType",
1187
+ "TSIntrinsicKeyword",
1188
+ "TSLiteralType",
1189
+ "TSMappedType",
1190
+ "TSNamedTupleMember",
1191
+ "TSNeverKeyword",
1192
+ "TSNullKeyword",
1193
+ "TSNumberKeyword",
1194
+ "TSObjectKeyword",
1195
+ "TSParenthesizedType",
1196
+ "TSStringKeyword",
1197
+ "TSSymbolKeyword",
1198
+ "TSTemplateLiteralType",
1199
+ "TSThisType",
1200
+ "TSTupleType",
1201
+ "TSTypeLiteral",
1202
+ "TSTypeOperator",
1203
+ "TSTypePredicate",
1204
+ "TSTypeQuery",
1205
+ "TSTypeReference",
1206
+ "TSUndefinedKeyword",
1207
+ "TSUnionType",
1208
+ "TSUnknownKeyword",
1209
+ "TSVoidKeyword"
1210
+ ]);
1211
+ function isTypeNode(node) {
1212
+ return typeNodeKinds.has(node.type);
1213
+ }
1214
+ function typeReferenceName2(type) {
1215
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
1216
+ }
1217
+ function isInsideTypeAliasDeclaration(node) {
1218
+ let current = node.parent;
1219
+ while (current !== null && current.type !== "Program") {
1220
+ if (current.type === "TSTypeAliasDeclaration")
1221
+ return true;
1222
+ current = current.parent;
1223
+ }
1224
+ return false;
1225
+ }
1226
+ function isPlainAliasConsumerUse(node, environment) {
1227
+ if (node.type !== "TSTypeReference" || node.typeArguments?.params.length)
1228
+ return false;
1229
+ const name = typeReferenceName2(node);
1230
+ return name !== null && environment.aliases.has(name) && !isInsideTypeAliasDeclaration(node);
1231
+ }
1232
+ function shouldReportType(node, environment) {
1233
+ if (isPlainAliasConsumerUse(node, environment))
1234
+ return false;
1235
+ if (classifyUnsafeDictionary(node, environment) === null)
1236
+ return false;
1237
+ let current = node.parent;
1238
+ while (current !== null && current.type !== "Program") {
1239
+ if (isTypeNode(current) && classifyUnsafeDictionary(current, environment) !== null)
1240
+ return false;
1241
+ current = current.parent;
1242
+ }
1243
+ return true;
1244
+ }
1245
+ var noUnsafeDictionaryTypeRule = defineRule13({
1246
+ meta: {
1247
+ type: "problem",
1248
+ docs: {
1249
+ description: "Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches."
1250
+ },
1251
+ messages: {
1252
+ unsafeDictionary: "This dictionary's {{value}} value type gives callers no concrete value contract. Use an owner/schema-derived value type; parse external payloads before insertion."
1253
+ }
1254
+ },
1255
+ createOnce(context) {
1256
+ let environment = null;
1257
+ const report = (node, value) => {
1258
+ context.report({ node, messageId: "unsafeDictionary", data: { value } });
1259
+ };
1260
+ const reportIfUnsafe = (node) => {
1261
+ if (environment === null || !shouldReportType(node, environment))
1262
+ return;
1263
+ const unsafe = classifyUnsafeDictionary(node, environment);
1264
+ if (unsafe === null)
1265
+ return;
1266
+ report(node, unsafe.unsafeValue);
1267
+ };
1268
+ return {
1269
+ Program(node) {
1270
+ environment = createTypeEnvironment(node);
1271
+ },
1272
+ TSTypeReference: reportIfUnsafe,
1273
+ TSTypeLiteral: reportIfUnsafe,
1274
+ TSMappedType: reportIfUnsafe,
1275
+ TSIndexSignature(node) {
1276
+ if (environment === null || node.typeAnnotation === null || node.parent.type === "TSTypeLiteral")
1277
+ return;
1278
+ const unsafe = classifyUnsafeDictionaryValue(node.typeAnnotation.typeAnnotation, environment);
1279
+ if (unsafe !== null)
1280
+ report(node, unsafe.unsafeValue);
1281
+ }
1282
+ };
1283
+ }
1284
+ });
1285
+
1286
+ // ../../tools/oxlint/anti-slop/rules/no-widen-then-assert.ts
1287
+ import { defineRule as defineRule14 } from "@oxlint/plugins";
1288
+ var functionBoundaryTypes = new Set([
1289
+ "ArrowFunctionExpression",
1290
+ "FunctionDeclaration",
1291
+ "FunctionExpression",
1292
+ "TSDeclareFunction",
1293
+ "TSEmptyBodyFunctionExpression"
1294
+ ]);
1295
+ function unwrapExpressionParentheses(expression) {
1296
+ let current = expression;
1297
+ while (current.type === "ParenthesizedExpression")
1298
+ current = current.expression;
1299
+ return current;
1300
+ }
1301
+ function unwrapTypeParentheses(type) {
1302
+ let current = type;
1303
+ while (current.type === "TSParenthesizedType")
1304
+ current = current.typeAnnotation;
1305
+ return current;
1306
+ }
1307
+ function typeReferenceName3(type) {
1308
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
1309
+ }
1310
+ function isUnknownOrAnyType(type) {
1311
+ const unwrapped = unwrapTypeParentheses(type);
1312
+ return unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword";
1313
+ }
1314
+ function isBroadRecordKeyType(type) {
1315
+ const unwrapped = unwrapTypeParentheses(type);
1316
+ if (unwrapped.type === "TSStringKeyword" || unwrapped.type === "TSNumberKeyword" || unwrapped.type === "TSSymbolKeyword") {
1317
+ return true;
1318
+ }
1319
+ if (unwrapped.type === "TSUnionType")
1320
+ return unwrapped.types.every(isBroadRecordKeyType);
1321
+ return unwrapped.type === "TSTypeReference" && typeReferenceName3(unwrapped) === "PropertyKey";
1322
+ }
1323
+ function isBroadRecordType(type) {
1324
+ const unwrapped = unwrapTypeParentheses(type);
1325
+ if (unwrapped.type === "TSTypeReference") {
1326
+ if (typeReferenceName3(unwrapped) === "Readonly") {
1327
+ const [inner] = unwrapped.typeArguments?.params ?? [];
1328
+ return inner !== undefined && isBroadRecordType(inner);
1329
+ }
1330
+ if (typeReferenceName3(unwrapped) !== "Record")
1331
+ return false;
1332
+ const parameters = unwrapped.typeArguments?.params ?? [];
1333
+ return parameters.length === 2 && parameters[0] !== undefined && parameters[1] !== undefined && isBroadRecordKeyType(parameters[0]) && isUnknownOrAnyType(parameters[1]);
1334
+ }
1335
+ if (unwrapped.type !== "TSTypeLiteral" || unwrapped.members.length !== 1)
1336
+ return false;
1337
+ const [member] = unwrapped.members;
1338
+ const [parameter] = member?.type === "TSIndexSignature" ? member.parameters : [];
1339
+ return member?.type === "TSIndexSignature" && member.parameters.length === 1 && parameter !== undefined && isBroadRecordKeyType(parameter.typeAnnotation.typeAnnotation) && isUnknownOrAnyType(member.typeAnnotation.typeAnnotation);
1340
+ }
1341
+ function broadTypeKind(type) {
1342
+ const unwrapped = unwrapTypeParentheses(type);
1343
+ if (unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword")
1344
+ return "top";
1345
+ if (unwrapped.type === "TSObjectKeyword")
1346
+ return "object";
1347
+ return isBroadRecordType(unwrapped) ? "record" : null;
1348
+ }
1349
+ function assertedExpression(node) {
1350
+ return unwrapExpressionParentheses(node.expression);
1351
+ }
1352
+ function assertionFromExpression(expression) {
1353
+ const unwrapped = unwrapExpressionParentheses(expression);
1354
+ return unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion" ? unwrapped : null;
1355
+ }
1356
+ function normalizedTypeText(sourceText, type) {
1357
+ return sourceText.slice(type.start, type.end).replaceAll(/\s+/gu, "");
1358
+ }
1359
+ function typesHaveSameSyntax(sourceText, left, right) {
1360
+ return left !== null && normalizedTypeText(sourceText, unwrapTypeParentheses(left)) === normalizedTypeText(sourceText, unwrapTypeParentheses(right));
1361
+ }
1362
+ function isDefinitelyObjectType(type) {
1363
+ const unwrapped = unwrapTypeParentheses(type);
1364
+ switch (unwrapped.type) {
1365
+ case "TSArrayType":
1366
+ case "TSConstructorType":
1367
+ case "TSFunctionType":
1368
+ case "TSMappedType":
1369
+ case "TSObjectKeyword":
1370
+ case "TSTupleType":
1371
+ return true;
1372
+ case "TSTypeLiteral":
1373
+ return unwrapped.members.length > 0;
1374
+ case "TSIntersectionType":
1375
+ return unwrapped.types.every(isDefinitelyObjectType);
1376
+ case "TSTypeOperator":
1377
+ return unwrapped.operator === "readonly" && isDefinitelyObjectType(unwrapped.typeAnnotation);
1378
+ default:
1379
+ return false;
1380
+ }
1381
+ }
1382
+ function isDefinitelyNarrowerRecordType(type) {
1383
+ const unwrapped = unwrapTypeParentheses(type);
1384
+ if (unwrapped.type === "TSTypeLiteral") {
1385
+ return unwrapped.members.some((member) => member.type !== "TSIndexSignature");
1386
+ }
1387
+ if (unwrapped.type !== "TSTypeReference")
1388
+ return false;
1389
+ if (typeReferenceName3(unwrapped) === "Readonly") {
1390
+ const [inner] = unwrapped.typeArguments?.params ?? [];
1391
+ return inner !== undefined && isDefinitelyNarrowerRecordType(inner);
1392
+ }
1393
+ if (typeReferenceName3(unwrapped) !== "Record")
1394
+ return false;
1395
+ const parameters = unwrapped.typeArguments?.params ?? [];
1396
+ return parameters.length === 2 && parameters[1] !== undefined && !isUnknownOrAnyType(parameters[1]);
1397
+ }
1398
+ function functionBoundary(node) {
1399
+ let current = node.parent;
1400
+ while (current !== null && current.type !== "Program") {
1401
+ if (functionBoundaryTypes.has(current.type))
1402
+ return current;
1403
+ current = current.parent;
1404
+ }
1405
+ return null;
1406
+ }
1407
+ function resolvedVariableForIdentifier(scopes, identifier) {
1408
+ for (const scope of scopes) {
1409
+ const reference = scope.references.find((candidate) => candidate.identifier.start === identifier.start && candidate.identifier.end === identifier.end);
1410
+ if (reference !== undefined)
1411
+ return reference.resolved;
1412
+ }
1413
+ return null;
1414
+ }
1415
+ function variableDeclarator2(variable) {
1416
+ for (const definition of variable.defs) {
1417
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator") {
1418
+ return definition.node;
1419
+ }
1420
+ }
1421
+ return null;
1422
+ }
1423
+ function knownValueEvidence(expression, scopes, boundary, visitedVariables) {
1424
+ const unwrapped = unwrapExpressionParentheses(expression);
1425
+ if (unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion") {
1426
+ if (broadTypeKind(unwrapped.typeAnnotation) !== null)
1427
+ return null;
1428
+ return { type: unwrapped.typeAnnotation };
1429
+ }
1430
+ if (unwrapped.type === "Literal" || unwrapped.type === "TemplateLiteral") {
1431
+ return { type: null };
1432
+ }
1433
+ if (unwrapped.type === "ArrayExpression" || unwrapped.type === "ArrowFunctionExpression" || unwrapped.type === "ClassExpression" || unwrapped.type === "FunctionExpression" || unwrapped.type === "NewExpression" || unwrapped.type === "ObjectExpression") {
1434
+ return { type: null };
1435
+ }
1436
+ if (unwrapped.type !== "Identifier")
1437
+ return null;
1438
+ const variable = resolvedVariableForIdentifier(scopes, unwrapped);
1439
+ if (variable === null || visitedVariables.has(variable))
1440
+ return null;
1441
+ const annotatedIdentifier = variable.identifiers.find((identifier) => identifier.typeAnnotation !== null && identifier.typeAnnotation !== undefined);
1442
+ const annotation = annotatedIdentifier?.typeAnnotation?.typeAnnotation;
1443
+ if (annotation !== undefined && annotatedIdentifier !== undefined) {
1444
+ if (functionBoundary(annotatedIdentifier) !== boundary || broadTypeKind(annotation) !== null) {
1445
+ return null;
1446
+ }
1447
+ return { type: annotation };
1448
+ }
1449
+ const declarator = variableDeclarator2(variable);
1450
+ if (declarator === null || declarator.parent.type !== "VariableDeclaration" || declarator.parent.kind !== "const" || declarator.init === null || variable.references.some((reference) => reference.isWrite() && !reference.init) || functionBoundary(declarator) !== boundary) {
1451
+ return null;
1452
+ }
1453
+ return knownValueEvidence(declarator.init, scopes, boundary, new Set([...visitedVariables, variable]));
1454
+ }
1455
+ function widenedBinding(variable, scopes) {
1456
+ const declarator = variableDeclarator2(variable);
1457
+ if (declarator === null || declarator.parent.type !== "VariableDeclaration" || declarator.parent.kind !== "const" || declarator.id.type !== "Identifier" || declarator.init === null || variable.references.some((reference) => reference.isWrite() && !reference.init)) {
1458
+ return null;
1459
+ }
1460
+ const boundary = functionBoundary(declarator);
1461
+ const declaredType = declarator.id.typeAnnotation?.typeAnnotation;
1462
+ const initializerAssertion = assertionFromExpression(declarator.init);
1463
+ const initializerBroadKind = initializerAssertion === null ? null : broadTypeKind(initializerAssertion.typeAnnotation);
1464
+ const declaredBroadKind = declaredType === undefined ? null : broadTypeKind(declaredType);
1465
+ const broadKind = declaredBroadKind ?? initializerBroadKind;
1466
+ if (broadKind === null)
1467
+ return null;
1468
+ const originalExpression = initializerAssertion !== null && initializerBroadKind !== null ? assertedExpression(initializerAssertion) : declarator.init;
1469
+ const evidence = knownValueEvidence(originalExpression, scopes, boundary, new Set([variable]));
1470
+ return evidence === null ? null : { broadKind, evidence, declaredAt: declarator.end, boundary };
1471
+ }
1472
+ function assertionIsNarrower(sourceText, broadKind, evidence, assertedType) {
1473
+ if (broadTypeKind(assertedType) !== null)
1474
+ return false;
1475
+ if (broadKind === "top")
1476
+ return true;
1477
+ if (typesHaveSameSyntax(sourceText, evidence.type, assertedType))
1478
+ return true;
1479
+ if (broadKind === "object")
1480
+ return isDefinitelyObjectType(assertedType);
1481
+ return isDefinitelyNarrowerRecordType(assertedType);
1482
+ }
1483
+ var noWidenThenAssertRule = defineRule14({
1484
+ meta: {
1485
+ type: "problem",
1486
+ docs: {
1487
+ description: "Disallow local const flows that explicitly widen a known value before asserting the widened binding to a narrower type."
1488
+ },
1489
+ messages: {
1490
+ widenThenAssert: 'Binding "{{name}}" discards type evidence and later recreates it with an assertion. Keep the precise type from initialization through use; parse boundary input once.'
1491
+ }
1492
+ },
1493
+ createOnce(context) {
1494
+ let scopes = [];
1495
+ const checkAssertion = (node) => {
1496
+ const expression = assertedExpression(node);
1497
+ if (expression.type !== "Identifier")
1498
+ return;
1499
+ const variable = resolvedVariableForIdentifier(scopes, expression);
1500
+ if (variable === null)
1501
+ return;
1502
+ const widened = widenedBinding(variable, scopes);
1503
+ if (widened === null || node.start <= widened.declaredAt || functionBoundary(node) !== widened.boundary || !assertionIsNarrower(context.sourceCode.text, widened.broadKind, widened.evidence, node.typeAnnotation)) {
1504
+ return;
1505
+ }
1506
+ context.report({
1507
+ node,
1508
+ messageId: "widenThenAssert",
1509
+ data: { name: expression.name }
1510
+ });
1511
+ };
1512
+ return {
1513
+ Program() {
1514
+ scopes = context.sourceCode.scopeManager.scopes;
1515
+ },
1516
+ TSAsExpression: checkAssertion,
1517
+ TSTypeAssertion: checkAssertion
1518
+ };
1519
+ }
1520
+ });
1521
+
1522
+ // ../../tools/oxlint/anti-slop/rules/require-safety-comment-for-type-assertion.ts
1523
+ import { defineRule as defineRule15 } from "@oxlint/plugins";
1524
+ var commentOwnerKinds = new Set([
1525
+ "ExpressionStatement",
1526
+ "PropertyDefinition",
1527
+ "ReturnStatement",
1528
+ "ThrowStatement",
1529
+ "VariableDeclaration"
1530
+ ]);
1531
+ function isConstAssertion2(node) {
1532
+ return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
1533
+ }
1534
+ function hasSafetyComment(sourceCode, node) {
1535
+ let current = node;
1536
+ while (true) {
1537
+ if (sourceCode.getCommentsBefore(current).some((comment) => comment.end <= node.start && /\bSAFETY\s*:/u.test(comment.value))) {
1538
+ return true;
1539
+ }
1540
+ if (commentOwnerKinds.has(current.type) || current.parent.type === "Program")
1541
+ return false;
1542
+ current = current.parent;
1543
+ }
1544
+ }
1545
+ var requireSafetyCommentForTypeAssertionRule = defineRule15({
1546
+ meta: {
1547
+ type: "problem",
1548
+ docs: {
1549
+ description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions."
1550
+ },
1551
+ messages: {
1552
+ missingSafetyComment: "This type assertion has no `SAFETY:` justification. State the checked invariant immediately before the assertion or its containing statement."
1553
+ }
1554
+ },
1555
+ createOnce(context) {
1556
+ const checkAssertion = (node) => {
1557
+ if (isConstAssertion2(node) || hasSafetyComment(context.sourceCode, node))
1558
+ return;
1559
+ context.report({ node, messageId: "missingSafetyComment" });
1560
+ };
1561
+ return {
1562
+ TSAsExpression: checkAssertion,
1563
+ TSTypeAssertion: checkAssertion
1564
+ };
1565
+ }
1566
+ });
1567
+
1568
+ // ../../tools/oxlint/anti-slop/index.ts
1569
+ var antiSlopPlugin = eslintCompatPlugin({
1570
+ meta: { name: "anti-slop" },
1571
+ rules: {
1572
+ "no-chained-type-assertions": noChainedTypeAssertionsRule,
1573
+ "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
1574
+ "no-known-value-widening": noKnownValueWideningRule,
1575
+ "no-module-mocking": noModuleMockingRule,
1576
+ "no-object-parameters": noObjectParametersRule,
1577
+ "no-reflect-apply": noReflectApplyRule,
1578
+ "no-reflect-get": noReflectGetRule,
1579
+ "no-runtime-typeof": noRuntimeTypeofRule,
1580
+ "no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
1581
+ "no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
1582
+ "no-unknown-parameters": noUnknownParametersRule,
1583
+ "no-unknown-returns": noUnknownReturnsRule,
1584
+ "no-unknown-type-aliases": noUnknownTypeAliasesRule,
1585
+ "no-widen-then-assert": noWidenThenAssertRule,
1586
+ "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule
1587
+ }
1588
+ });
1589
+ var anti_slop_default = antiSlopPlugin;
1590
+ export {
1591
+ anti_slop_default as default
1592
+ };