@imapps/oxc-config 0.0.0-stage → 7.0.0

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 (43) hide show
  1. package/README.md +65 -2
  2. package/anti-slop/LICENSE +21 -0
  3. package/anti-slop/UPSTREAM-IMAPPS.md +11 -0
  4. package/anti-slop/index.ts +47 -0
  5. package/anti-slop/rules/no-array-filter-map.ts +28 -0
  6. package/anti-slop/rules/no-chained-type-assertions.ts +77 -0
  7. package/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
  8. package/anti-slop/rules/no-known-value-widening.ts +415 -0
  9. package/anti-slop/rules/no-module-mocking.ts +80 -0
  10. package/anti-slop/rules/no-object-parameters.ts +83 -0
  11. package/anti-slop/rules/no-reduce-accumulator-copy.ts +109 -0
  12. package/anti-slop/rules/no-reflect-apply.ts +28 -0
  13. package/anti-slop/rules/no-reflect-get.ts +28 -0
  14. package/anti-slop/rules/no-runtime-typeof.ts +77 -0
  15. package/anti-slop/rules/no-shape-in-symbol-names.ts +46 -0
  16. package/anti-slop/rules/no-unknown-parameters.ts +69 -0
  17. package/anti-slop/rules/no-unknown-returns.ts +82 -0
  18. package/anti-slop/rules/no-unknown-type-aliases.ts +54 -0
  19. package/anti-slop/rules/no-unsafe-dictionary-type.ts +154 -0
  20. package/anti-slop/rules/no-widen-then-assert.ts +366 -0
  21. package/anti-slop/rules/require-readable-spacing.ts +80 -0
  22. package/anti-slop/rules/require-safety-comment-for-type-assertion.ts +131 -0
  23. package/anti-slop/shared/array-method.ts +94 -0
  24. package/anti-slop/shared/dictionary-types.ts +515 -0
  25. package/anti-slop/shared/function-parameters.ts +49 -0
  26. package/anti-slop/shared/lexical-type-parameters.ts +61 -0
  27. package/anti-slop/shared/reflect-method.ts +24 -0
  28. package/anti-slop/shared/scope.ts +15 -0
  29. package/anti-slop/shared/type-alias-resolution.ts +250 -0
  30. package/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
  31. package/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +28 -0
  32. package/anti-slop/vendor/eslint-stylistic/padding-line-ast.ts +51 -0
  33. package/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.ts +929 -0
  34. package/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +87 -0
  35. package/build/anti-slop.js +2569 -0
  36. package/build/anti-slop.js.map +1 -0
  37. package/build/oxfmt.d.ts +24 -0
  38. package/build/oxfmt.js +37 -0
  39. package/build/oxfmt.js.map +1 -0
  40. package/build/oxlint.d.ts +44 -0
  41. package/build/oxlint.js +57 -0
  42. package/build/oxlint.js.map +1 -0
  43. package/package.json +52 -4
@@ -0,0 +1,2569 @@
1
+ // anti-slop/index.ts
2
+ import { eslintCompatPlugin } from "@oxlint/plugins";
3
+
4
+ // anti-slop/rules/no-array-filter-map.ts
5
+ import { defineRule } from "@oxlint/plugins";
6
+
7
+ // anti-slop/shared/array-method.ts
8
+ function unwrapArrayExpression(node) {
9
+ while (node.type === "ParenthesizedExpression" || node.type === "ChainExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression") {
10
+ node = node.expression;
11
+ }
12
+ return node;
13
+ }
14
+ function resolveArrayBinding(sourceCode, node) {
15
+ node = unwrapArrayExpression(node);
16
+ if (node.type !== "Identifier") return null;
17
+ let scope = sourceCode.getScope(node);
18
+ while (scope !== null) {
19
+ const variable = scope.set.get(node.name);
20
+ if (variable !== void 0) return variable;
21
+ scope = scope.upper;
22
+ }
23
+ return null;
24
+ }
25
+ function arrayMethodTarget(node) {
26
+ node = unwrapArrayExpression(node);
27
+ if (node.type !== "MemberExpression") return null;
28
+ const property = node.property;
29
+ if (!node.computed && property.type === "Identifier") {
30
+ return { name: property.name, object: node.object };
31
+ }
32
+ if (node.computed && property.type === "Literal" && typeof property.value === "string") {
33
+ return { name: property.value, object: node.object };
34
+ }
35
+ return null;
36
+ }
37
+ function isArrayAnnotation(type) {
38
+ if (type.type === "TSArrayType" || type.type === "TSTupleType") return true;
39
+ if (type.type === "TSParenthesizedType") return isArrayAnnotation(type.typeAnnotation);
40
+ if (type.type === "TSTypeOperator" && type.operator === "readonly") {
41
+ return isArrayAnnotation(type.typeAnnotation);
42
+ }
43
+ return type.type === "TSTypeReference" && type.typeName.type === "Identifier" && (type.typeName.name === "Array" || type.typeName.name === "ReadonlyArray");
44
+ }
45
+ function isKnownArrayExpression(sourceCode, node, visited = /* @__PURE__ */ new Set()) {
46
+ node = unwrapArrayExpression(node);
47
+ if (node.type === "ArrayExpression") return true;
48
+ if (node.type === "CallExpression") {
49
+ const method = arrayMethodTarget(node.callee);
50
+ return method !== null && ["map", "filter", "flatMap", "slice", "concat", "toSorted", "toReversed", "toSpliced"].includes(method.name) && isKnownArrayExpression(sourceCode, method.object, visited);
51
+ }
52
+ if (node.type !== "Identifier") return false;
53
+ const variable = resolveArrayBinding(sourceCode, node);
54
+ if (variable === null || visited.has(variable)) return false;
55
+ visited.add(variable);
56
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
57
+ for (const identifier of variable.identifiers) {
58
+ const annotation = identifier.typeAnnotation?.typeAnnotation;
59
+ if (annotation !== void 0) return isArrayAnnotation(annotation);
60
+ }
61
+ for (const definition of variable.defs) {
62
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier" && definition.node.init !== null && definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") {
63
+ return isKnownArrayExpression(sourceCode, definition.node.init, visited);
64
+ }
65
+ }
66
+ return false;
67
+ }
68
+
69
+ // anti-slop/rules/no-array-filter-map.ts
70
+ var noArrayFilterMapRule = defineRule({
71
+ meta: {
72
+ type: "suggestion",
73
+ docs: { description: "Disallow adjacent array filter/map passes in favor of lazy iterator helpers or a single transformation." },
74
+ messages: {
75
+ arrayFilterMap: "Avoid consecutive array `{{first}}` and `{{second}}` passes. Prefer `.values().{{first}}(...).{{second}}(...).toArray()` where iterator helpers are supported, or a single `flatMap`/mutating reducer. Preserve callback ordering, indexes, and filtering semantics."
76
+ }
77
+ },
78
+ createOnce(context) {
79
+ return {
80
+ CallExpression(node) {
81
+ const outer = arrayMethodTarget(node.callee);
82
+ if (outer === null || outer.name !== "map" && outer.name !== "filter") return;
83
+ const innerCall = unwrapArrayExpression(outer.object);
84
+ if (innerCall.type !== "CallExpression") return;
85
+ const inner = arrayMethodTarget(innerCall.callee);
86
+ if (inner === null || inner.name !== (outer.name === "map" ? "filter" : "map")) return;
87
+ if (!isKnownArrayExpression(context.sourceCode, inner.object)) return;
88
+ context.report({ node, messageId: "arrayFilterMap", data: { first: inner.name, second: outer.name } });
89
+ }
90
+ };
91
+ }
92
+ });
93
+
94
+ // anti-slop/rules/no-reduce-accumulator-copy.ts
95
+ import { defineRule as defineRule2 } from "@oxlint/plugins";
96
+ function enclosingReducer(node) {
97
+ let parent = node.parent;
98
+ while (parent !== null) {
99
+ if (parent.type === "FunctionDeclaration") return null;
100
+ if (parent.type === "ArrowFunctionExpression" || parent.type === "FunctionExpression") {
101
+ const callback = parent;
102
+ let owner = callback.parent;
103
+ while (owner !== null && unwrapArrayExpression(owner) === callback) owner = owner.parent;
104
+ if (owner?.type !== "CallExpression") return null;
105
+ const method = arrayMethodTarget(owner.callee);
106
+ const firstArgument = owner.arguments[0];
107
+ if (method === null || method.name !== "reduce" && method.name !== "reduceRight" || owner.arguments.length > 2 || firstArgument === void 0 || unwrapArrayExpression(firstArgument) !== callback) return null;
108
+ const firstParameter = callback.params[0];
109
+ const accumulator = firstParameter?.type === "AssignmentPattern" ? firstParameter.left : firstParameter;
110
+ if (accumulator?.type !== "Identifier") return null;
111
+ return { callback, accumulator, initialValue: owner.arguments[1] };
112
+ }
113
+ parent = parent.parent;
114
+ }
115
+ return null;
116
+ }
117
+ function referencesAccumulator(sourceCode, node, accumulator, visited = /* @__PURE__ */ new Set()) {
118
+ const variable = resolveArrayBinding(sourceCode, node);
119
+ if (variable === null || visited.has(variable)) return false;
120
+ if (variable === accumulator) return true;
121
+ visited.add(variable);
122
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
123
+ for (const definition of variable.defs) {
124
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier" && definition.node.init !== null && definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") {
125
+ return referencesAccumulator(sourceCode, definition.node.init, accumulator, visited);
126
+ }
127
+ }
128
+ return false;
129
+ }
130
+ function isGlobalCopyOwner(sourceCode, node, name) {
131
+ node = unwrapArrayExpression(node);
132
+ if (node.type !== "Identifier" || node.name !== name) return false;
133
+ const variable = resolveArrayBinding(sourceCode, node);
134
+ return variable === null || variable.defs.length === 0;
135
+ }
136
+ var noReduceAccumulatorCopyRule = defineRule2({
137
+ meta: {
138
+ type: "problem",
139
+ docs: { description: "Disallow copying growing reducer accumulators with Object.assign, Array.from, or array copy methods." },
140
+ messages: {
141
+ accumulatorCopy: "Do not copy the reducer accumulator on every iteration; growing copies can cause quadratic work. Mutate a fresh, locally owned accumulator and return it, or use an iterator pipeline/flatMap."
142
+ }
143
+ },
144
+ createOnce(context) {
145
+ return {
146
+ CallExpression(node) {
147
+ const method = arrayMethodTarget(node.callee);
148
+ if (method === null) return;
149
+ const reducer = enclosingReducer(node);
150
+ if (reducer === null) return;
151
+ const accumulator = context.sourceCode.getDeclaredVariables(reducer.callback).find(
152
+ (variable) => variable.identifiers.some((identifier) => identifier.start === reducer.accumulator.start)
153
+ );
154
+ if (accumulator === void 0) return;
155
+ const isAccumulator = (expression) => referencesAccumulator(context.sourceCode, expression, accumulator);
156
+ let copiesAccumulator = false;
157
+ if (method.name === "assign" && isGlobalCopyOwner(context.sourceCode, method.object, "Object")) {
158
+ const target = node.arguments[0];
159
+ copiesAccumulator = target !== void 0 && unwrapArrayExpression(target).type === "ObjectExpression" && node.arguments.slice(1).some(isAccumulator);
160
+ } else if (method.name === "from" && isGlobalCopyOwner(context.sourceCode, method.object, "Array")) {
161
+ const source = node.arguments[0];
162
+ copiesAccumulator = source !== void 0 && isAccumulator(source);
163
+ } else if (["concat", "slice", "toSpliced", "toSorted", "toReversed", "with"].includes(method.name)) {
164
+ const initialValue = reducer.initialValue;
165
+ const arrayAccumulator = initialValue !== void 0 && isKnownArrayExpression(context.sourceCode, initialValue);
166
+ copiesAccumulator = arrayAccumulator && isAccumulator(method.object);
167
+ }
168
+ if (copiesAccumulator) context.report({ node, messageId: "accumulatorCopy" });
169
+ }
170
+ };
171
+ }
172
+ });
173
+
174
+ // anti-slop/rules/no-chained-type-assertions.ts
175
+ import { defineRule as defineRule3 } from "@oxlint/plugins";
176
+ function isTypeAssertionExpression(node) {
177
+ return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
178
+ }
179
+ function unwrapParenthesizedExpression(expression) {
180
+ let current = expression;
181
+ while (current.type === "ParenthesizedExpression") {
182
+ current = current.expression;
183
+ }
184
+ return current;
185
+ }
186
+ function isConstAssertion(node) {
187
+ const { typeAnnotation } = node;
188
+ return typeAnnotation.type === "TSTypeReference" && typeAnnotation.typeName.type === "Identifier" && typeAnnotation.typeName.name === "const";
189
+ }
190
+ function isOutermostAssertionInChain(node) {
191
+ let current = node;
192
+ let parent = node.parent;
193
+ while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
194
+ current = parent;
195
+ parent = parent.parent;
196
+ }
197
+ return !isTypeAssertionExpression(parent) || parent.expression !== current;
198
+ }
199
+ function isForbiddenAssertionChain(node) {
200
+ let assertionCount = 0;
201
+ let hasNonConstAssertion = false;
202
+ let current = node;
203
+ while (isTypeAssertionExpression(current)) {
204
+ assertionCount += 1;
205
+ hasNonConstAssertion ||= !isConstAssertion(current);
206
+ current = unwrapParenthesizedExpression(current.expression);
207
+ }
208
+ return assertionCount > 1 && hasNonConstAssertion;
209
+ }
210
+ var noChainedTypeAssertionsRule = defineRule3({
211
+ meta: {
212
+ type: "problem",
213
+ docs: {
214
+ description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains."
215
+ },
216
+ messages: {
217
+ chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it."
218
+ }
219
+ },
220
+ createOnce(context) {
221
+ const checkTypeAssertion = (node) => {
222
+ if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node)) return;
223
+ context.report({ node, messageId: "chained" });
224
+ };
225
+ return {
226
+ TSAsExpression: checkTypeAssertion,
227
+ TSTypeAssertion: checkTypeAssertion
228
+ };
229
+ }
230
+ });
231
+
232
+ // anti-slop/rules/no-conditional-empty-object-spread.ts
233
+ import { defineRule as defineRule4 } from "@oxlint/plugins";
234
+ function unwrapParentheses(node) {
235
+ let current = node;
236
+ while (current.type === "ParenthesizedExpression") {
237
+ current = current.expression;
238
+ }
239
+ return current;
240
+ }
241
+ function isEmptyObjectExpression(node) {
242
+ return node.type === "ObjectExpression" && node.properties.length === 0;
243
+ }
244
+ function isConditionalEmptyObjectSpread(node) {
245
+ const conditional = unwrapParentheses(node);
246
+ return conditional.type === "ConditionalExpression" && (isEmptyObjectExpression(conditional.consequent) || isEmptyObjectExpression(conditional.alternate));
247
+ }
248
+ var noConditionalEmptyObjectSpreadRule = defineRule4({
249
+ meta: {
250
+ type: "suggestion",
251
+ docs: {
252
+ description: "Disallow object spreads that conditionally spread an empty object to omit fields."
253
+ },
254
+ messages: {
255
+ avoid: "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present."
256
+ }
257
+ },
258
+ createOnce(context) {
259
+ return {
260
+ SpreadElement(node) {
261
+ if (node.parent.type !== "ObjectExpression") return;
262
+ if (isConditionalEmptyObjectSpread(node.argument)) {
263
+ context.report({ node, messageId: "avoid" });
264
+ }
265
+ }
266
+ };
267
+ }
268
+ });
269
+
270
+ // anti-slop/rules/no-known-value-widening.ts
271
+ import { defineRule as defineRule5 } from "@oxlint/plugins";
272
+
273
+ // anti-slop/shared/lexical-type-parameters.ts
274
+ function isNode(value) {
275
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
276
+ }
277
+ function collectInferTypeParameterNames(node, visitorKeys, names) {
278
+ if (node.type === "TSInferType") names.add(node.typeParameter.name.name);
279
+ const record = node;
280
+ for (const key of visitorKeys[node.type] ?? []) {
281
+ const value = record[key];
282
+ if (isNode(value)) {
283
+ collectInferTypeParameterNames(value, visitorKeys, names);
284
+ continue;
285
+ }
286
+ if (!Array.isArray(value)) continue;
287
+ for (const child of value) {
288
+ if (isNode(child)) collectInferTypeParameterNames(child, visitorKeys, names);
289
+ }
290
+ }
291
+ }
292
+ function lexicalTypeParameterNames(node, visitorKeys) {
293
+ const names = /* @__PURE__ */ new Set();
294
+ let descendant = node;
295
+ let current = node;
296
+ while (current !== null && current.type !== "Program") {
297
+ if ("typeParameters" in current) {
298
+ for (const parameter of current.typeParameters?.params ?? []) {
299
+ names.add(parameter.name.name);
300
+ }
301
+ }
302
+ if (current.type === "TSMappedType" && (descendant === current.nameType || descendant === current.typeAnnotation)) {
303
+ names.add(current.key.name);
304
+ }
305
+ if (current.type === "TSConditionalType" && descendant === current.trueType) {
306
+ collectInferTypeParameterNames(current.extendsType, visitorKeys, names);
307
+ }
308
+ descendant = current;
309
+ current = current.parent;
310
+ }
311
+ return names;
312
+ }
313
+
314
+ // anti-slop/shared/type-alias-resolution.ts
315
+ var environmentsByProgram = /* @__PURE__ */ new WeakMap();
316
+ function isNode2(value) {
317
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
318
+ }
319
+ function enclosingTypeScope(node) {
320
+ let current = node.parent;
321
+ while (current !== null) {
322
+ if (current.type === "Program" || current.type === "BlockStatement" || current.type === "TSModuleBlock" || current.type === "StaticBlock" || current.type === "SwitchStatement") {
323
+ return current;
324
+ }
325
+ current = current.parent;
326
+ }
327
+ return node;
328
+ }
329
+ function declaredTypeBinding(node) {
330
+ if (node.type === "TSTypeAliasDeclaration") {
331
+ return { alias: node, name: node.id.name };
332
+ }
333
+ if (node.type === "TSInterfaceDeclaration" || node.type === "TSEnumDeclaration" || node.type === "ClassDeclaration" || node.type === "ClassExpression") {
334
+ return node.id === null ? null : { alias: null, name: node.id.name };
335
+ }
336
+ if (node.type === "ImportSpecifier" || node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") {
337
+ return { alias: null, name: node.local.name };
338
+ }
339
+ return null;
340
+ }
341
+ function collectTypeBindings(node, visitorKeys, bindingsByName, aliases) {
342
+ const declared = declaredTypeBinding(node);
343
+ if (declared !== null) {
344
+ const bindings = bindingsByName.get(declared.name) ?? [];
345
+ bindings.push({ ...declared, scope: enclosingTypeScope(node) });
346
+ bindingsByName.set(declared.name, bindings);
347
+ if (declared.alias !== null) aliases.push(declared.alias);
348
+ }
349
+ const fields = node;
350
+ for (const key of visitorKeys[node.type] ?? []) {
351
+ const value = fields[key];
352
+ if (isNode2(value)) {
353
+ collectTypeBindings(value, visitorKeys, bindingsByName, aliases);
354
+ continue;
355
+ }
356
+ if (!Array.isArray(value)) continue;
357
+ for (const child of value) {
358
+ if (isNode2(child)) {
359
+ collectTypeBindings(child, visitorKeys, bindingsByName, aliases);
360
+ }
361
+ }
362
+ }
363
+ }
364
+ function createTypeAliasEnvironment(program, visitorKeys) {
365
+ const cached = environmentsByProgram.get(program);
366
+ if (cached !== void 0) return cached;
367
+ const bindingsByName = /* @__PURE__ */ new Map();
368
+ const aliases = [];
369
+ collectTypeBindings(program, visitorKeys, bindingsByName, aliases);
370
+ const environment = { aliases, bindingsByName, visitorKeys };
371
+ environmentsByProgram.set(program, environment);
372
+ return environment;
373
+ }
374
+ function ancestorDistance(ancestor, node) {
375
+ let current = node;
376
+ let distance = 0;
377
+ while (current !== null) {
378
+ if (current === ancestor) return distance;
379
+ current = current.parent;
380
+ distance += 1;
381
+ }
382
+ return null;
383
+ }
384
+ function nearestTypeBindings(name, use, environment) {
385
+ const candidates = environment.bindingsByName.get(name) ?? [];
386
+ let nearestDistance = Number.POSITIVE_INFINITY;
387
+ let nearest = [];
388
+ for (const candidate of candidates) {
389
+ const distance = ancestorDistance(candidate.scope, use);
390
+ if (distance === null || distance > nearestDistance) continue;
391
+ if (distance === nearestDistance) {
392
+ nearest.push(candidate);
393
+ continue;
394
+ }
395
+ nearestDistance = distance;
396
+ nearest = [candidate];
397
+ }
398
+ return nearest;
399
+ }
400
+ function visibleTypeAlias(name, use, environment) {
401
+ if (lexicalTypeParameterNames(use, environment.visitorKeys).has(name)) return null;
402
+ const bindings = nearestTypeBindings(name, use, environment);
403
+ return bindings.length === 1 ? bindings[0]?.alias ?? null : null;
404
+ }
405
+ function hasVisibleTypeBinding(name, use, environment) {
406
+ return lexicalTypeParameterNames(use, environment.visitorKeys).has(name) || nearestTypeBindings(name, use, environment).length > 0;
407
+ }
408
+ function typeReferenceName(type) {
409
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
410
+ }
411
+ function aliasSubstitutions(alias, reference, base) {
412
+ const parameters = alias.typeParameters?.params ?? [];
413
+ const arguments_ = reference.typeArguments?.params ?? [];
414
+ const next = new Map(base);
415
+ for (const [index, parameter] of parameters.entries()) {
416
+ const explicitArgument = arguments_[index];
417
+ const argument = explicitArgument ?? parameter.default;
418
+ if (argument === null || argument === void 0) return null;
419
+ const argumentSubstitutions = explicitArgument === void 0 ? next : base;
420
+ next.set(parameter.name.name, {
421
+ type: argument,
422
+ substitutions: new Map(argumentSubstitutions)
423
+ });
424
+ }
425
+ return next;
426
+ }
427
+ function resolvedTypeMatches(type, environment, matcher) {
428
+ const evaluate = (current, substitutions, resolvingAliases) => {
429
+ if (current.type === "TSTypeReference") {
430
+ const name = typeReferenceName(current);
431
+ if (name !== null) {
432
+ const substitution = substitutions.get(name);
433
+ if (substitution !== void 0 && !current.typeArguments?.params.length) {
434
+ return evaluate(
435
+ substitution.type,
436
+ substitution.substitutions,
437
+ resolvingAliases
438
+ );
439
+ }
440
+ const alias = visibleTypeAlias(name, current, environment);
441
+ if (alias !== null && !resolvingAliases.has(alias)) {
442
+ const nextSubstitutions = aliasSubstitutions(alias, current, substitutions);
443
+ if (nextSubstitutions !== null) {
444
+ const nextResolving = new Set(resolvingAliases);
445
+ nextResolving.add(alias);
446
+ return evaluate(alias.typeAnnotation, nextSubstitutions, nextResolving);
447
+ }
448
+ }
449
+ }
450
+ }
451
+ return matcher(
452
+ current,
453
+ (child) => evaluate(child, substitutions, resolvingAliases)
454
+ );
455
+ };
456
+ return evaluate(type, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Set());
457
+ }
458
+
459
+ // anti-slop/shared/dictionary-types.ts
460
+ var BUILT_INS = /* @__PURE__ */ new Set([
461
+ "Record",
462
+ "Readonly",
463
+ "Partial",
464
+ "Required",
465
+ "Pick",
466
+ "Omit",
467
+ "PropertyKey",
468
+ "NonNullable"
469
+ ]);
470
+ var TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set(["Readonly", "Partial", "Required", "NonNullable"]);
471
+ function declaredStatement(statement) {
472
+ return statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration ?? null : statement;
473
+ }
474
+ function createTypeEnvironment(program, visitorKeys) {
475
+ const interfaces = /* @__PURE__ */ new Map();
476
+ for (const statement of program.body) {
477
+ const declaration = declaredStatement(statement);
478
+ if (declaration?.type !== "TSInterfaceDeclaration") continue;
479
+ const declarations = interfaces.get(declaration.id.name) ?? [];
480
+ declarations.push(declaration);
481
+ interfaces.set(declaration.id.name, declarations);
482
+ }
483
+ return {
484
+ interfaces,
485
+ typeAliases: createTypeAliasEnvironment(program, visitorKeys)
486
+ };
487
+ }
488
+ function typeReferenceName2(type) {
489
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
490
+ }
491
+ function isBuiltIn(name, use, environment) {
492
+ return BUILT_INS.has(name) && !hasVisibleTypeBinding(name, use, environment.typeAliases);
493
+ }
494
+ function isUnappliedReferenceTo(type, name) {
495
+ const unwrapped = unwrapTransparentType(type);
496
+ return unwrapped.type === "TSTypeReference" && typeReferenceName2(unwrapped) === name && (unwrapped.typeArguments === null || unwrapped.typeArguments === void 0 || unwrapped.typeArguments.params.length === 0);
497
+ }
498
+ function unwrapTransparentType(type) {
499
+ let current = type;
500
+ while (current.type === "TSParenthesizedType" || current.type === "TSTypeOperator" && current.operator === "readonly") {
501
+ current = current.typeAnnotation;
502
+ }
503
+ return current;
504
+ }
505
+ function isNeverType(type) {
506
+ return unwrapTransparentType(type).type === "TSNeverKeyword";
507
+ }
508
+ function isEffectivelyEmptyMember(member) {
509
+ return member.type === "TSPropertySignature" && member.optional === true && member.typeAnnotation !== null && member.typeAnnotation !== void 0 && isNeverType(member.typeAnnotation.typeAnnotation);
510
+ }
511
+ function isEffectivelyEmptyTypeLiteral(type) {
512
+ return type.members.length === 0 || type.members.every(isEffectivelyEmptyMember);
513
+ }
514
+ function isEffectivelyEmptyInterface(declarations) {
515
+ if (declarations.length !== 1) return false;
516
+ const [type] = declarations;
517
+ return type !== void 0 && type.extends.length === 0 && (type.body.body.length === 0 || type.body.body.every(isEffectivelyEmptyMember));
518
+ }
519
+ function resolvedSubstitutionArgument(type, base, resolving = /* @__PURE__ */ new Set()) {
520
+ const unwrapped = unwrapTransparentType(type);
521
+ if (unwrapped.type !== "TSTypeReference") return type;
522
+ const name = typeReferenceName2(unwrapped);
523
+ if (name === null || resolving.has(name)) return type;
524
+ const substitution = base.get(name);
525
+ if (substitution === void 0) return type;
526
+ const nextResolving = new Set(resolving);
527
+ nextResolving.add(name);
528
+ return resolvedSubstitutionArgument(substitution, base, nextResolving);
529
+ }
530
+ function aliasSubstitution(alias, type, base) {
531
+ const parameters = alias.typeParameters?.params ?? [];
532
+ const arguments_ = type.typeArguments?.params ?? [];
533
+ const next = new Map(base);
534
+ for (const [index, parameter] of parameters.entries()) {
535
+ const argument = arguments_[index] ?? parameter.default;
536
+ if (argument === null || argument === void 0) return null;
537
+ next.set(parameter.name.name, resolvedSubstitutionArgument(argument, next));
538
+ }
539
+ return next;
540
+ }
541
+ function unsafeDirectValue(type, environment, substitutions, resolvingAliases) {
542
+ const unwrapped = unwrapTransparentType(type);
543
+ if (unwrapped.type === "TSUnknownKeyword") return "unknown";
544
+ if (unwrapped.type === "TSAnyKeyword") return "any";
545
+ if (unwrapped.type === "TSObjectKeyword") return "object";
546
+ if (unwrapped.type === "TSTypeLiteral" && isEffectivelyEmptyTypeLiteral(unwrapped))
547
+ return "empty-object";
548
+ if (unwrapped.type === "TSUnionType") {
549
+ return unwrapped.types.some(
550
+ (member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null
551
+ ) ? "union" : null;
552
+ }
553
+ if (unwrapped.type === "TSIntersectionType") {
554
+ const unsafeMembers = unwrapped.types.map(
555
+ (member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases)
556
+ );
557
+ if (unsafeMembers.includes("any")) return "any";
558
+ return unsafeMembers.length > 0 && unsafeMembers.every((member) => member !== null) ? unsafeMembers[0] : null;
559
+ }
560
+ if (unwrapped.type !== "TSTypeReference") return null;
561
+ const name = typeReferenceName2(unwrapped);
562
+ if (name === null) return null;
563
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
564
+ const wrapped = unwrapped.typeArguments?.params[0];
565
+ return wrapped === void 0 ? null : unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
566
+ }
567
+ const substitution = substitutions.get(name);
568
+ if (substitution !== void 0) {
569
+ return isUnappliedReferenceTo(substitution, name) ? null : unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
570
+ }
571
+ const interfaceDeclarations = environment.interfaces.get(name);
572
+ if (interfaceDeclarations !== void 0) {
573
+ return isEffectivelyEmptyInterface(interfaceDeclarations) ? "empty-object" : null;
574
+ }
575
+ const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
576
+ if (alias === null || resolvingAliases.has(name)) return null;
577
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
578
+ if (nextSubstitutions === null) return null;
579
+ const nextResolving = new Set(resolvingAliases);
580
+ nextResolving.add(name);
581
+ return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
582
+ }
583
+ function dictionaryValueTypes(type, environment, substitutions, resolvingAliases) {
584
+ const unwrapped = unwrapTransparentType(type);
585
+ if (unwrapped.type === "TSTypeLiteral") {
586
+ return unwrapped.members.flatMap(
587
+ (member) => member.type === "TSIndexSignature" && member.typeAnnotation !== null ? [{ type: member.typeAnnotation.typeAnnotation, substitutions }] : []
588
+ );
589
+ }
590
+ if (unwrapped.type === "TSMappedType") {
591
+ return unwrapped.typeAnnotation === null ? [] : [{ type: unwrapped.typeAnnotation, substitutions }];
592
+ }
593
+ if (unwrapped.type !== "TSTypeReference") return [];
594
+ const name = typeReferenceName2(unwrapped);
595
+ if (name === null) return [];
596
+ const substitution = substitutions.get(name);
597
+ if (substitution !== void 0) {
598
+ return isUnappliedReferenceTo(substitution, name) ? [] : dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
599
+ }
600
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
601
+ const wrapped = unwrapped.typeArguments?.params[0];
602
+ return wrapped === void 0 ? [] : dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
603
+ }
604
+ if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
605
+ const value = unwrapped.typeArguments?.params[1] ?? null;
606
+ return value === null ? [] : [{ type: value, substitutions }];
607
+ }
608
+ if ((name === "Pick" || name === "Omit") && isBuiltIn(name, unwrapped, environment)) {
609
+ const source = unwrapped.typeArguments?.params[0];
610
+ return source === void 0 ? [] : dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
611
+ }
612
+ const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
613
+ if (alias === null || resolvingAliases.has(name)) return [];
614
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
615
+ if (nextSubstitutions === null) return [];
616
+ const nextResolving = new Set(resolvingAliases);
617
+ nextResolving.add(name);
618
+ return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
619
+ }
620
+ function classifyUnsafeDictionaryValue(valueType, environment) {
621
+ const unsafeValue = unsafeDirectValue(valueType, environment, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Set());
622
+ return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
623
+ }
624
+ function classifyUnsafeDictionary(type, environment) {
625
+ for (const valueType of dictionaryValueTypes(type, environment, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Set())) {
626
+ const unsafeValue = unsafeDirectValue(
627
+ valueType.type,
628
+ environment,
629
+ valueType.substitutions,
630
+ /* @__PURE__ */ new Set()
631
+ );
632
+ if (unsafeValue !== null) return { kind: "unsafe-dictionary", unsafeValue };
633
+ }
634
+ return null;
635
+ }
636
+ function classifyWideningTarget(type, environment) {
637
+ const unwrapped = unwrapTransparentType(type);
638
+ if (unwrapped.type === "TSUnknownKeyword") return { kind: "unknown" };
639
+ if (unwrapped.type === "TSObjectKeyword") return { kind: "object" };
640
+ if (unwrapped.type === "TSTypeLiteral") {
641
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature") ? { kind: "open dictionary" } : unwrapped.members.length > 0 ? { kind: "anonymous object" } : null;
642
+ }
643
+ if (unwrapped.type === "TSMappedType") return { kind: "open dictionary" };
644
+ if (unwrapped.type !== "TSTypeReference") return null;
645
+ const name = typeReferenceName2(unwrapped);
646
+ if (name === null) return null;
647
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
648
+ const wrapped = unwrapped.typeArguments?.params[0];
649
+ return wrapped === void 0 ? null : classifyWideningTarget(wrapped, environment);
650
+ }
651
+ if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
652
+ return hasBroadRecordKey(unwrapped, environment, /* @__PURE__ */ new Map()) ? { kind: "open dictionary" } : null;
653
+ }
654
+ const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
655
+ if (alias === null) return null;
656
+ if ((alias.typeParameters?.params.length ?? 0) > 0) {
657
+ const substitutions2 = aliasSubstitution(alias, unwrapped, /* @__PURE__ */ new Map());
658
+ const resolved2 = substitutions2 === null ? null : classifyAliasBroadTarget(
659
+ alias.typeAnnotation,
660
+ environment,
661
+ substitutions2,
662
+ /* @__PURE__ */ new Set([name])
663
+ );
664
+ return resolved2?.kind === "open dictionary" ? { kind: "generic container" } : null;
665
+ }
666
+ const substitutions = aliasSubstitution(alias, unwrapped, /* @__PURE__ */ new Map());
667
+ if (substitutions === null) return null;
668
+ const resolved = classifyAliasBroadTarget(
669
+ alias.typeAnnotation,
670
+ environment,
671
+ substitutions,
672
+ /* @__PURE__ */ new Set([name])
673
+ );
674
+ return resolved;
675
+ }
676
+ function hasBroadRecordKey(type, environment, substitutions) {
677
+ const key = type.typeArguments?.params[0];
678
+ return key === void 0 || isBroadMappedKey(key, environment, substitutions);
679
+ }
680
+ function isBroadMappedKey(type, environment, substitutions, visitedAliases = /* @__PURE__ */ new Set()) {
681
+ const unwrapped = unwrapTransparentType(type);
682
+ if (unwrapped.type === "TSStringKeyword" || unwrapped.type === "TSNumberKeyword" || unwrapped.type === "TSSymbolKeyword") {
683
+ return true;
684
+ }
685
+ if (unwrapped.type === "TSUnionType") {
686
+ return unwrapped.types.some(
687
+ (member) => isBroadMappedKey(member, environment, substitutions, visitedAliases)
688
+ );
689
+ }
690
+ if (unwrapped.type !== "TSTypeReference") return false;
691
+ const name = typeReferenceName2(unwrapped);
692
+ if (name === null) return false;
693
+ const substitution = substitutions.get(name);
694
+ if (substitution !== void 0 && !isUnappliedReferenceTo(substitution, name)) {
695
+ return isBroadMappedKey(substitution, environment, substitutions, visitedAliases);
696
+ }
697
+ if (name === "PropertyKey" && isBuiltIn(name, unwrapped, environment)) return true;
698
+ const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
699
+ if (alias === null || (alias.typeParameters?.params.length ?? 0) > 0 || visitedAliases.has(name)) {
700
+ return false;
701
+ }
702
+ const nextVisited = new Set(visitedAliases);
703
+ nextVisited.add(name);
704
+ return isBroadMappedKey(alias.typeAnnotation, environment, substitutions, nextVisited);
705
+ }
706
+ function classifyAliasBroadTarget(type, environment, substitutions, resolvingAliases) {
707
+ const unwrapped = unwrapTransparentType(type);
708
+ if (unwrapped.type === "TSUnknownKeyword") return { kind: "unknown" };
709
+ if (unwrapped.type === "TSObjectKeyword") return { kind: "object" };
710
+ if (unwrapped.type === "TSTypeLiteral") {
711
+ return unwrapped.members.some((member) => member.type === "TSIndexSignature") ? { kind: "open dictionary" } : null;
712
+ }
713
+ if (unwrapped.type === "TSMappedType") {
714
+ return isBroadMappedKey(unwrapped.constraint, environment, substitutions) ? { kind: "open dictionary" } : null;
715
+ }
716
+ if (unwrapped.type !== "TSTypeReference") return null;
717
+ const name = typeReferenceName2(unwrapped);
718
+ if (name === null) return null;
719
+ const substitution = substitutions.get(name);
720
+ if (substitution !== void 0) {
721
+ return isUnappliedReferenceTo(substitution, name) ? null : classifyAliasBroadTarget(
722
+ substitution,
723
+ environment,
724
+ substitutions,
725
+ resolvingAliases
726
+ );
727
+ }
728
+ if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
729
+ const wrapped = unwrapped.typeArguments?.params[0];
730
+ return wrapped === void 0 ? null : classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
731
+ }
732
+ if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
733
+ return hasBroadRecordKey(unwrapped, environment, substitutions) ? { kind: "open dictionary" } : null;
734
+ }
735
+ const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
736
+ if (alias === null || resolvingAliases.has(name)) return null;
737
+ const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
738
+ if (nextSubstitutions === null) return null;
739
+ const nextResolving = new Set(resolvingAliases);
740
+ nextResolving.add(name);
741
+ return classifyAliasBroadTarget(
742
+ alias.typeAnnotation,
743
+ environment,
744
+ nextSubstitutions,
745
+ nextResolving
746
+ );
747
+ }
748
+ function isKnownEvidenceExpression(expression) {
749
+ let current = expression;
750
+ while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression" || current.type === "TSSatisfiesExpression") {
751
+ current = current.expression;
752
+ }
753
+ if (current.type === "ObjectExpression") return true;
754
+ 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";
755
+ }
756
+
757
+ // anti-slop/shared/function-parameters.ts
758
+ function containsUnknownType(type) {
759
+ if (type.type === "TSUnknownKeyword") return true;
760
+ if (type.type === "TSParenthesizedType") return containsUnknownType(type.typeAnnotation);
761
+ return type.type === "TSUnionType" && type.types.some(containsUnknownType);
762
+ }
763
+ function functionParameterTypeAnnotation(parameter) {
764
+ if (parameter.type === "TSParameterProperty") {
765
+ return functionParameterTypeAnnotation(parameter.parameter);
766
+ }
767
+ if (parameter.type === "RestElement") {
768
+ return parameter.typeAnnotation ?? functionParameterTypeAnnotation(parameter.argument);
769
+ }
770
+ if (parameter.type === "AssignmentPattern") {
771
+ return parameter.typeAnnotation ?? functionParameterTypeAnnotation(parameter.left);
772
+ }
773
+ return parameter.typeAnnotation;
774
+ }
775
+ function functionParameterBindingName(parameter, sourceCode) {
776
+ if (parameter.type === "TSParameterProperty") {
777
+ return functionParameterBindingName(parameter.parameter, sourceCode);
778
+ }
779
+ if (parameter.type === "AssignmentPattern") {
780
+ return functionParameterBindingName(parameter.left, sourceCode);
781
+ }
782
+ if (parameter.type === "RestElement") {
783
+ return functionParameterBindingName(parameter.argument, sourceCode);
784
+ }
785
+ if (parameter.type === "Identifier") return parameter.name;
786
+ const sourceText = sourceCode.getText(parameter);
787
+ const annotationStart = parameter.typeAnnotation?.start;
788
+ return annotationStart === void 0 ? sourceText : sourceText.slice(0, annotationStart - parameter.start).trimEnd();
789
+ }
790
+
791
+ // anti-slop/shared/scope.ts
792
+ function resolveVariable(sourceCode, identifier) {
793
+ let scope = sourceCode.getScope(identifier);
794
+ while (scope !== null) {
795
+ const variable = scope.set.get(identifier.name);
796
+ if (variable !== void 0) return variable;
797
+ scope = scope.upper;
798
+ }
799
+ return null;
800
+ }
801
+
802
+ // anti-slop/rules/no-known-value-widening.ts
803
+ function unwrapExpression(expression) {
804
+ let current = expression;
805
+ while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") {
806
+ current = current.expression;
807
+ }
808
+ return current;
809
+ }
810
+ function variableDeclarator(variable) {
811
+ if (variable.defs.length !== 1) return null;
812
+ const [definition] = variable.defs;
813
+ return definition?.type === "Variable" && definition.node.type === "VariableDeclarator" ? definition.node : null;
814
+ }
815
+ function isStableConstVariable(variable, declarator) {
816
+ return declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" && variable.references.every((reference) => reference.init || !reference.isWrite());
817
+ }
818
+ function hasKnownEvidence(sourceCode, expression, visitedVariables = /* @__PURE__ */ new Set()) {
819
+ if (isKnownEvidenceExpression(expression)) return true;
820
+ const unwrapped = unwrapExpression(expression);
821
+ if (unwrapped.type !== "Identifier") return false;
822
+ const variable = resolveVariable(sourceCode, unwrapped);
823
+ if (variable === null || visitedVariables.has(variable)) return false;
824
+ const declarator = variableDeclarator(variable);
825
+ if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) {
826
+ return false;
827
+ }
828
+ visitedVariables.add(variable);
829
+ return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
830
+ }
831
+ function isFunctionExpression(node) {
832
+ return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "TSDeclareFunction" || node.type === "TSEmptyBodyFunctionExpression";
833
+ }
834
+ function localFunctionForCall(sourceCode, callee) {
835
+ const unwrapped = unwrapExpression(callee);
836
+ if (isFunctionExpression(unwrapped)) return unwrapped;
837
+ if (unwrapped.type !== "Identifier") return null;
838
+ const variable = resolveVariable(sourceCode, unwrapped);
839
+ if (variable === null || variable.defs.length !== 1) return null;
840
+ const [definition] = variable.defs;
841
+ if (definition === void 0) return null;
842
+ if (definition.type === "FunctionName" && isFunctionExpression(definition.node)) {
843
+ return definition.node;
844
+ }
845
+ if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator") {
846
+ return null;
847
+ }
848
+ const initializer = definition.node.init;
849
+ if (initializer === null) return null;
850
+ const unwrappedInitializer = unwrapExpression(initializer);
851
+ return isFunctionExpression(unwrappedInitializer) ? unwrappedInitializer : null;
852
+ }
853
+ function variableTypeAnnotation(sourceCode, variable) {
854
+ if (variable.defs.length !== 1) return null;
855
+ const [definition] = variable.defs;
856
+ if (definition === void 0) return null;
857
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier") {
858
+ return definition.node.id.typeAnnotation ?? null;
859
+ }
860
+ if (definition.type !== "Parameter" || !isFunctionExpression(definition.node)) {
861
+ return null;
862
+ }
863
+ const parameter = definition.node.params.find(
864
+ (candidate) => functionParameterBindingName(candidate, sourceCode) === variable.name
865
+ );
866
+ return parameter === void 0 ? null : functionParameterTypeAnnotation(parameter) ?? null;
867
+ }
868
+ function hasInformativeType(type, environment) {
869
+ return classifyUnsafeDictionaryValue(type, environment) === null;
870
+ }
871
+ function hasKnownCallArgumentEvidence(sourceCode, expression, environment, visitedVariables = /* @__PURE__ */ new Set()) {
872
+ if (expression.type === "ParenthesizedExpression" || expression.type === "TSNonNullExpression") {
873
+ return hasKnownCallArgumentEvidence(
874
+ sourceCode,
875
+ expression.expression,
876
+ environment,
877
+ visitedVariables
878
+ );
879
+ }
880
+ if (expression.type === "TSAsExpression" || expression.type === "TSTypeAssertion") {
881
+ return hasInformativeType(expression.typeAnnotation, environment);
882
+ }
883
+ if (expression.type === "TSSatisfiesExpression") {
884
+ return hasKnownCallArgumentEvidence(
885
+ sourceCode,
886
+ expression.expression,
887
+ environment,
888
+ visitedVariables
889
+ );
890
+ }
891
+ if (expression.type === "CallExpression") {
892
+ const owner = localFunctionForCall(sourceCode, expression.callee);
893
+ const returnType = owner?.returnType?.typeAnnotation;
894
+ return returnType !== void 0 && hasInformativeType(returnType, environment);
895
+ }
896
+ if (expression.type !== "Identifier") return isKnownEvidenceExpression(expression);
897
+ const variable = resolveVariable(sourceCode, expression);
898
+ if (variable === null || visitedVariables.has(variable)) return false;
899
+ const annotation = variableTypeAnnotation(sourceCode, variable);
900
+ if (annotation !== null) {
901
+ return hasInformativeType(annotation.typeAnnotation, environment);
902
+ }
903
+ const declarator = variableDeclarator(variable);
904
+ if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) {
905
+ return false;
906
+ }
907
+ visitedVariables.add(variable);
908
+ return hasKnownCallArgumentEvidence(
909
+ sourceCode,
910
+ declarator.init,
911
+ environment,
912
+ visitedVariables
913
+ );
914
+ }
915
+ function typePredicateSubjectIndex(sourceCode, owner) {
916
+ const predicate = owner.returnType?.typeAnnotation;
917
+ if (predicate?.type !== "TSTypePredicate" || predicate.parameterName.type !== "Identifier") {
918
+ return null;
919
+ }
920
+ const predicateParameterName = predicate.parameterName.name;
921
+ const index = owner.params.findIndex(
922
+ (parameter) => functionParameterBindingName(parameter, sourceCode) === predicateParameterName
923
+ );
924
+ return index === -1 ? null : index;
925
+ }
926
+ function annotationTarget(annotation, environment) {
927
+ return annotation === null || annotation === void 0 ? null : classifyWideningTarget(annotation.typeAnnotation, environment);
928
+ }
929
+ function enclosingFunction(node) {
930
+ let current = node.parent;
931
+ while (current !== null && current.type !== "Program") {
932
+ if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") {
933
+ return current;
934
+ }
935
+ current = current.parent;
936
+ }
937
+ return null;
938
+ }
939
+ function sourceKeyName(sourceCode, key) {
940
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier") return key.name;
941
+ if (key.type === "Literal") return String(key.value);
942
+ return sourceCode.getText(key);
943
+ }
944
+ function functionName(sourceCode, owner) {
945
+ if (owner === null) return "anonymous function";
946
+ if (owner.id !== null) return owner.id.name;
947
+ const parent = owner.parent;
948
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
949
+ return parent.id.name;
950
+ if (parent.type === "MethodDefinition") return sourceKeyName(sourceCode, parent.key);
951
+ return "anonymous function";
952
+ }
953
+ function isEmptyObjectExpression2(expression) {
954
+ const unwrapped = unwrapExpression(expression);
955
+ return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
956
+ }
957
+ function isDictionaryAccumulatorTarget(destination) {
958
+ return destination.kind === "open dictionary" || destination.kind === "generic container";
959
+ }
960
+ function hasParentAssertion(node) {
961
+ return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
962
+ }
963
+ var noKnownValueWideningRule = defineRule5({
964
+ meta: {
965
+ type: "problem",
966
+ docs: {
967
+ description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence."
968
+ },
969
+ messages: {
970
+ widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract."
971
+ }
972
+ },
973
+ createOnce(context) {
974
+ let environment = null;
975
+ const reportFlow = (expression, destination, subject) => {
976
+ if (destination === null) return;
977
+ if (isDictionaryAccumulatorTarget(destination) && isEmptyObjectExpression2(expression)) {
978
+ return;
979
+ }
980
+ if (!hasKnownEvidence(context.sourceCode, expression)) return;
981
+ context.report({
982
+ node: expression,
983
+ messageId: "widening",
984
+ data: { subject, target: destination.kind }
985
+ });
986
+ };
987
+ const targetFromAnnotation = (annotation) => environment === null ? null : annotationTarget(annotation, environment);
988
+ return {
989
+ Program(node) {
990
+ environment = createTypeEnvironment(
991
+ node,
992
+ context.sourceCode.visitorKeys
993
+ );
994
+ },
995
+ VariableDeclarator(node) {
996
+ if (node.init === null || node.id.type !== "Identifier") return;
997
+ reportFlow(
998
+ node.init,
999
+ targetFromAnnotation(node.id.typeAnnotation),
1000
+ `binding \`${node.id.name}\``
1001
+ );
1002
+ },
1003
+ PropertyDefinition(node) {
1004
+ if (node.value === null) return;
1005
+ reportFlow(
1006
+ node.value,
1007
+ targetFromAnnotation(node.typeAnnotation),
1008
+ `property \`${sourceKeyName(context.sourceCode, node.key)}\``
1009
+ );
1010
+ },
1011
+ AccessorProperty(node) {
1012
+ if (node.value === null) return;
1013
+ reportFlow(
1014
+ node.value,
1015
+ targetFromAnnotation(node.typeAnnotation),
1016
+ `property \`${sourceKeyName(context.sourceCode, node.key)}\``
1017
+ );
1018
+ },
1019
+ AssignmentExpression(node) {
1020
+ if (node.operator !== "=" || node.left.type !== "Identifier") return;
1021
+ const variable = resolveVariable(context.sourceCode, node.left);
1022
+ if (variable === null) return;
1023
+ const declarator = variableDeclarator(variable);
1024
+ if (declarator === null || declarator.id.type !== "Identifier") return;
1025
+ reportFlow(
1026
+ node.right,
1027
+ targetFromAnnotation(declarator.id.typeAnnotation),
1028
+ `binding \`${declarator.id.name}\``
1029
+ );
1030
+ },
1031
+ CallExpression(node) {
1032
+ if (environment === null) return;
1033
+ const owner = localFunctionForCall(context.sourceCode, node.callee);
1034
+ if (owner === null) return;
1035
+ const parameterIndex = typePredicateSubjectIndex(context.sourceCode, owner);
1036
+ if (parameterIndex === null) return;
1037
+ const parameter = owner.params[parameterIndex];
1038
+ const argument = node.arguments[parameterIndex];
1039
+ if (parameter === void 0 || argument === void 0 || argument.type === "SpreadElement") {
1040
+ return;
1041
+ }
1042
+ const parameterAnnotation = functionParameterTypeAnnotation(parameter);
1043
+ if (parameterAnnotation === null || parameterAnnotation === void 0 || !containsUnknownType(parameterAnnotation.typeAnnotation)) {
1044
+ return;
1045
+ }
1046
+ if (!hasKnownCallArgumentEvidence(
1047
+ context.sourceCode,
1048
+ argument,
1049
+ environment
1050
+ )) {
1051
+ return;
1052
+ }
1053
+ context.report({
1054
+ node: argument,
1055
+ messageId: "widening",
1056
+ data: {
1057
+ subject: `argument for parameter \`${functionParameterBindingName(parameter, context.sourceCode)}\` of \`${functionName(context.sourceCode, owner)}\``,
1058
+ target: "unknown"
1059
+ }
1060
+ });
1061
+ },
1062
+ ReturnStatement(node) {
1063
+ if (node.argument === null) return;
1064
+ const owner = enclosingFunction(node);
1065
+ reportFlow(
1066
+ node.argument,
1067
+ targetFromAnnotation(owner?.returnType),
1068
+ `return value of \`${functionName(context.sourceCode, owner)}\``
1069
+ );
1070
+ },
1071
+ ArrowFunctionExpression(node) {
1072
+ if (node.body.type === "BlockStatement") return;
1073
+ reportFlow(
1074
+ node.body,
1075
+ targetFromAnnotation(node.returnType),
1076
+ `return value of \`${functionName(context.sourceCode, node)}\``
1077
+ );
1078
+ },
1079
+ TSAsExpression(node) {
1080
+ if (environment === null || hasParentAssertion(node)) return;
1081
+ reportFlow(
1082
+ node.expression,
1083
+ classifyWideningTarget(node.typeAnnotation, environment),
1084
+ "assertion"
1085
+ );
1086
+ },
1087
+ TSTypeAssertion(node) {
1088
+ if (environment === null || hasParentAssertion(node)) return;
1089
+ reportFlow(
1090
+ node.expression,
1091
+ classifyWideningTarget(node.typeAnnotation, environment),
1092
+ "assertion"
1093
+ );
1094
+ }
1095
+ };
1096
+ }
1097
+ });
1098
+
1099
+ // anti-slop/rules/no-module-mocking.ts
1100
+ import { defineRule as defineRule6 } from "@oxlint/plugins";
1101
+ var moduleMockMethods = /* @__PURE__ */ new Set(["doMock", "mock", "unstable_mockModule"]);
1102
+ function importedName(node) {
1103
+ if (node.type !== "ImportSpecifier") return null;
1104
+ return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
1105
+ }
1106
+ function isTestFrameworkObject(sourceCode, expression) {
1107
+ if (expression.type !== "Identifier") return false;
1108
+ if ((expression.name === "vi" || expression.name === "jest") && sourceCode.isGlobalReference(expression)) {
1109
+ return true;
1110
+ }
1111
+ const variable = resolveVariable(sourceCode, expression);
1112
+ if (variable === null || variable.defs.length === 0) {
1113
+ return expression.name === "vi" || expression.name === "jest";
1114
+ }
1115
+ return variable.defs.some((definition) => {
1116
+ if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
1117
+ return false;
1118
+ }
1119
+ const source = definition.parent.source.value;
1120
+ const name = importedName(definition.node);
1121
+ return source === "vitest" && name === "vi" || source === "@jest/globals" && name === "jest";
1122
+ });
1123
+ }
1124
+ function moduleMockCall(sourceCode, callee) {
1125
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
1126
+ if (!isTestFrameworkObject(sourceCode, callee.object)) return false;
1127
+ const property = callee.property;
1128
+ 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;
1129
+ return method !== null && moduleMockMethods.has(method);
1130
+ }
1131
+ var noModuleMockingRule = defineRule6({
1132
+ meta: {
1133
+ type: "problem",
1134
+ docs: {
1135
+ description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces."
1136
+ },
1137
+ messages: {
1138
+ moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation."
1139
+ }
1140
+ },
1141
+ createOnce(context) {
1142
+ return {
1143
+ CallExpression(node) {
1144
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
1145
+ if (moduleMockCall(context.sourceCode, node.callee)) {
1146
+ context.report({ node, messageId: "moduleMock" });
1147
+ }
1148
+ }
1149
+ };
1150
+ }
1151
+ });
1152
+
1153
+ // anti-slop/rules/no-object-parameters.ts
1154
+ import { defineRule as defineRule7 } from "@oxlint/plugins";
1155
+ var noObjectParametersRule = defineRule7({
1156
+ meta: {
1157
+ type: "problem",
1158
+ docs: {
1159
+ description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary."
1160
+ },
1161
+ messages: {
1162
+ objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function."
1163
+ }
1164
+ },
1165
+ createOnce(context) {
1166
+ let environment = null;
1167
+ const resolvesToObject = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
1168
+ if (resolved.type === "TSObjectKeyword") return true;
1169
+ if (resolved.type === "TSParenthesizedType") {
1170
+ return matches(resolved.typeAnnotation);
1171
+ }
1172
+ return resolved.type === "TSUnionType" && resolved.types.some(matches);
1173
+ });
1174
+ const checkParameters = (node) => {
1175
+ for (const parameter of node.params) {
1176
+ const annotation = functionParameterTypeAnnotation(parameter);
1177
+ if (annotation === null || annotation === void 0) continue;
1178
+ if (!resolvesToObject(annotation.typeAnnotation)) continue;
1179
+ context.report({
1180
+ node: annotation.typeAnnotation,
1181
+ messageId: "objectParameter",
1182
+ data: { parameter: functionParameterBindingName(parameter, context.sourceCode) }
1183
+ });
1184
+ }
1185
+ };
1186
+ return {
1187
+ Program(node) {
1188
+ environment = createTypeAliasEnvironment(
1189
+ node,
1190
+ context.sourceCode.visitorKeys
1191
+ );
1192
+ },
1193
+ ArrowFunctionExpression: checkParameters,
1194
+ FunctionDeclaration: checkParameters,
1195
+ FunctionExpression: checkParameters,
1196
+ TSCallSignatureDeclaration: checkParameters,
1197
+ TSConstructSignatureDeclaration: checkParameters,
1198
+ TSConstructorType: checkParameters,
1199
+ TSDeclareFunction: checkParameters,
1200
+ TSEmptyBodyFunctionExpression: checkParameters,
1201
+ TSFunctionType: checkParameters,
1202
+ TSMethodSignature: checkParameters
1203
+ };
1204
+ }
1205
+ });
1206
+
1207
+ // anti-slop/rules/no-reflect-apply.ts
1208
+ import { defineRule as defineRule8 } from "@oxlint/plugins";
1209
+
1210
+ // anti-slop/shared/reflect-method.ts
1211
+ function isGlobalReflect(sourceCode, expression) {
1212
+ if (expression.type !== "Identifier" || expression.name !== "Reflect") return false;
1213
+ if (sourceCode.isGlobalReference(expression)) return true;
1214
+ const variable = resolveVariable(sourceCode, expression);
1215
+ return variable === null || variable.defs.length === 0;
1216
+ }
1217
+ function isGlobalReflectMethodCall(sourceCode, callee, methodName) {
1218
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
1219
+ if (!isGlobalReflect(sourceCode, callee.object)) return false;
1220
+ const property = callee.property;
1221
+ return callee.computed ? property.type === "Literal" && property.value === methodName : property.type === "Identifier" && property.name === methodName;
1222
+ }
1223
+
1224
+ // anti-slop/rules/no-reflect-apply.ts
1225
+ var noReflectApplyRule = defineRule8({
1226
+ meta: {
1227
+ type: "problem",
1228
+ docs: {
1229
+ description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface."
1230
+ },
1231
+ messages: {
1232
+ reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface."
1233
+ }
1234
+ },
1235
+ createOnce(context) {
1236
+ return {
1237
+ CallExpression(node) {
1238
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
1239
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "apply")) {
1240
+ context.report({ node, messageId: "reflectApply" });
1241
+ }
1242
+ }
1243
+ };
1244
+ }
1245
+ });
1246
+
1247
+ // anti-slop/rules/no-reflect-get.ts
1248
+ import { defineRule as defineRule9 } from "@oxlint/plugins";
1249
+ var noReflectGetRule = defineRule9({
1250
+ meta: {
1251
+ type: "problem",
1252
+ docs: {
1253
+ description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type."
1254
+ },
1255
+ messages: {
1256
+ reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it."
1257
+ }
1258
+ },
1259
+ createOnce(context) {
1260
+ return {
1261
+ CallExpression(node) {
1262
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
1263
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "get")) {
1264
+ context.report({ node, messageId: "reflectGet" });
1265
+ }
1266
+ }
1267
+ };
1268
+ }
1269
+ });
1270
+
1271
+ // anti-slop/rules/no-runtime-typeof.ts
1272
+ import { defineRule as defineRule10 } from "@oxlint/plugins";
1273
+ function isRuntimeFunction(node) {
1274
+ return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
1275
+ }
1276
+ function isInsideTypeGuard(node) {
1277
+ let current = node.parent;
1278
+ while (current !== null && current.type !== "Program") {
1279
+ if (isRuntimeFunction(current)) {
1280
+ return current.returnType?.typeAnnotation.type === "TSTypePredicate";
1281
+ }
1282
+ current = current.parent;
1283
+ }
1284
+ return false;
1285
+ }
1286
+ function isExistenceProbe(node) {
1287
+ const parent = node.parent;
1288
+ if (parent.type !== "BinaryExpression") return false;
1289
+ if (!["===", "!==", "==", "!="].includes(parent.operator)) return false;
1290
+ const other = parent.left === node ? parent.right : parent.left;
1291
+ return other.type === "Literal" && other.value === "undefined";
1292
+ }
1293
+ var noRuntimeTypeofRule = defineRule10({
1294
+ meta: {
1295
+ type: "problem",
1296
+ docs: {
1297
+ description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary."
1298
+ },
1299
+ messages: {
1300
+ runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value."
1301
+ },
1302
+ schema: [
1303
+ {
1304
+ type: "object",
1305
+ properties: {
1306
+ allowInTypeGuards: { type: "boolean" }
1307
+ },
1308
+ additionalProperties: false
1309
+ }
1310
+ ],
1311
+ defaultOptions: [{ allowInTypeGuards: false }]
1312
+ },
1313
+ createOnce(context) {
1314
+ return {
1315
+ UnaryExpression(node) {
1316
+ const option = context.options?.[0];
1317
+ const allowInTypeGuards = typeof option === "object" && option !== null && !Array.isArray(option) && option.allowInTypeGuards === true;
1318
+ if (node.operator === "typeof" && !isExistenceProbe(node) && (!allowInTypeGuards || !isInsideTypeGuard(node))) {
1319
+ context.report({ node, messageId: "runtimeTypeof" });
1320
+ }
1321
+ }
1322
+ };
1323
+ }
1324
+ });
1325
+
1326
+ // anti-slop/rules/no-shape-in-symbol-names.ts
1327
+ import { defineRule as defineRule11 } from "@oxlint/plugins";
1328
+ var FORBIDDEN_SYMBOL_NAME = "shape";
1329
+ function containsForbiddenSymbolName(name) {
1330
+ return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
1331
+ }
1332
+ function isBorrowedMemberName(node) {
1333
+ const parent = node.parent;
1334
+ if (parent === null || parent.type !== "MemberExpression") return false;
1335
+ return parent.property === node && parent.computed === false;
1336
+ }
1337
+ var noForbiddenTermInSymbolNamesRule = defineRule11({
1338
+ meta: {
1339
+ type: "problem",
1340
+ docs: {
1341
+ description: 'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.'
1342
+ },
1343
+ messages: {
1344
+ forbiddenSymbolName: 'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.'
1345
+ }
1346
+ },
1347
+ createOnce(context) {
1348
+ const reportForbiddenSymbolName = (node) => {
1349
+ if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
1350
+ context.report({
1351
+ node,
1352
+ messageId: "forbiddenSymbolName",
1353
+ data: { name: node.name }
1354
+ });
1355
+ };
1356
+ return {
1357
+ Identifier: reportForbiddenSymbolName,
1358
+ PrivateIdentifier: reportForbiddenSymbolName,
1359
+ JSXIdentifier: reportForbiddenSymbolName
1360
+ };
1361
+ }
1362
+ });
1363
+
1364
+ // anti-slop/rules/no-unknown-parameters.ts
1365
+ import { defineRule as defineRule12 } from "@oxlint/plugins";
1366
+ function isTypePredicateSubject(owner, parameterName) {
1367
+ const predicate = owner.returnType?.typeAnnotation;
1368
+ return predicate?.type === "TSTypePredicate" && predicate.parameterName.type === "Identifier" && predicate.parameterName.name === parameterName;
1369
+ }
1370
+ var noUnknownParametersRule = defineRule12({
1371
+ meta: {
1372
+ type: "problem",
1373
+ docs: {
1374
+ description: "Disallow explicitly unknown function parameters except `cause` and type-predicate subjects; decode unknown input at its I/O boundary instead."
1375
+ },
1376
+ messages: {
1377
+ 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."
1378
+ }
1379
+ },
1380
+ createOnce(context) {
1381
+ const checkParameters = (node) => {
1382
+ for (const parameter of node.params) {
1383
+ const annotation = functionParameterTypeAnnotation(parameter);
1384
+ if (annotation === null || annotation === void 0) continue;
1385
+ if (!containsUnknownType(annotation.typeAnnotation)) continue;
1386
+ const name = functionParameterBindingName(parameter, context.sourceCode);
1387
+ if (name === "cause" || isTypePredicateSubject(node, name)) continue;
1388
+ context.report({
1389
+ node: annotation.typeAnnotation,
1390
+ messageId: "unknownParameter",
1391
+ data: { parameter: name }
1392
+ });
1393
+ }
1394
+ };
1395
+ return {
1396
+ ArrowFunctionExpression: checkParameters,
1397
+ FunctionDeclaration: checkParameters,
1398
+ FunctionExpression: checkParameters,
1399
+ TSCallSignatureDeclaration: checkParameters,
1400
+ TSConstructSignatureDeclaration: checkParameters,
1401
+ TSConstructorType: checkParameters,
1402
+ TSDeclareFunction: checkParameters,
1403
+ TSEmptyBodyFunctionExpression: checkParameters,
1404
+ TSFunctionType: checkParameters,
1405
+ TSMethodSignature: checkParameters
1406
+ };
1407
+ }
1408
+ });
1409
+
1410
+ // anti-slop/rules/no-unknown-returns.ts
1411
+ import { defineRule as defineRule13 } from "@oxlint/plugins";
1412
+ var noUnknownReturnsRule = defineRule13({
1413
+ meta: {
1414
+ type: "problem",
1415
+ docs: {
1416
+ description: "Disallow functions whose explicit return contract is unknown or Promise<unknown>."
1417
+ },
1418
+ messages: {
1419
+ unknownReturn: "This function exposes `unknown` to its caller. Parse the value at its boundary and return a named domain type."
1420
+ }
1421
+ },
1422
+ createOnce(context) {
1423
+ let environment = null;
1424
+ const resolvesToUnknown = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
1425
+ if (resolved.type === "TSUnknownKeyword") return true;
1426
+ if (resolved.type === "TSParenthesizedType") {
1427
+ return matches(resolved.typeAnnotation);
1428
+ }
1429
+ if (resolved.type === "TSUnionType") return resolved.types.some(matches);
1430
+ if (resolved.type !== "TSTypeReference" || resolved.typeName.type !== "Identifier" || resolved.typeName.name !== "Promise" && resolved.typeName.name !== "PromiseLike") {
1431
+ return false;
1432
+ }
1433
+ const value = resolved.typeArguments?.params[0];
1434
+ return value !== void 0 && matches(value);
1435
+ });
1436
+ const checkReturnType = (node) => {
1437
+ const annotation = node.returnType;
1438
+ if (annotation === null || annotation === void 0) return;
1439
+ if (!resolvesToUnknown(annotation.typeAnnotation)) return;
1440
+ context.report({ node: annotation.typeAnnotation, messageId: "unknownReturn" });
1441
+ };
1442
+ return {
1443
+ Program(node) {
1444
+ environment = createTypeAliasEnvironment(
1445
+ node,
1446
+ context.sourceCode.visitorKeys
1447
+ );
1448
+ },
1449
+ ArrowFunctionExpression: checkReturnType,
1450
+ FunctionDeclaration: checkReturnType,
1451
+ FunctionExpression: checkReturnType,
1452
+ TSCallSignatureDeclaration: checkReturnType,
1453
+ TSConstructSignatureDeclaration: checkReturnType,
1454
+ TSConstructorType: checkReturnType,
1455
+ TSDeclareFunction: checkReturnType,
1456
+ TSEmptyBodyFunctionExpression: checkReturnType,
1457
+ TSFunctionType: checkReturnType,
1458
+ TSMethodSignature: checkReturnType
1459
+ };
1460
+ }
1461
+ });
1462
+
1463
+ // anti-slop/rules/no-unknown-type-aliases.ts
1464
+ import { defineRule as defineRule14 } from "@oxlint/plugins";
1465
+ var noUnknownTypeAliasesRule = defineRule14({
1466
+ meta: {
1467
+ type: "problem",
1468
+ docs: {
1469
+ description: "Disallow type aliases whose resolved type is unknown; unknown must remain visible at an allowed boundary."
1470
+ },
1471
+ messages: {
1472
+ 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."
1473
+ }
1474
+ },
1475
+ createOnce(context) {
1476
+ let environment = null;
1477
+ const resolvesToUnknown = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
1478
+ if (resolved.type === "TSUnknownKeyword") return true;
1479
+ if (resolved.type === "TSParenthesizedType") {
1480
+ return matches(resolved.typeAnnotation);
1481
+ }
1482
+ return resolved.type === "TSUnionType" && resolved.types.some(matches);
1483
+ });
1484
+ return {
1485
+ Program(node) {
1486
+ environment = createTypeAliasEnvironment(
1487
+ node,
1488
+ context.sourceCode.visitorKeys
1489
+ );
1490
+ },
1491
+ TSTypeAliasDeclaration(node) {
1492
+ if (!resolvesToUnknown(node.typeAnnotation)) return;
1493
+ context.report({
1494
+ node: node.id,
1495
+ messageId: "unknownAlias",
1496
+ data: { alias: node.id.name }
1497
+ });
1498
+ }
1499
+ };
1500
+ }
1501
+ });
1502
+
1503
+ // anti-slop/rules/no-unsafe-dictionary-type.ts
1504
+ import { defineRule as defineRule15 } from "@oxlint/plugins";
1505
+ var typeNodeKinds = /* @__PURE__ */ new Set([
1506
+ "JSDocNonNullableType",
1507
+ "JSDocNullableType",
1508
+ "JSDocUnknownType",
1509
+ "TSAnyKeyword",
1510
+ "TSArrayType",
1511
+ "TSBigIntKeyword",
1512
+ "TSBooleanKeyword",
1513
+ "TSConditionalType",
1514
+ "TSConstructorType",
1515
+ "TSFunctionType",
1516
+ "TSImportType",
1517
+ "TSIndexedAccessType",
1518
+ "TSInferType",
1519
+ "TSIntersectionType",
1520
+ "TSIntrinsicKeyword",
1521
+ "TSLiteralType",
1522
+ "TSMappedType",
1523
+ "TSNamedTupleMember",
1524
+ "TSNeverKeyword",
1525
+ "TSNullKeyword",
1526
+ "TSNumberKeyword",
1527
+ "TSObjectKeyword",
1528
+ "TSParenthesizedType",
1529
+ "TSStringKeyword",
1530
+ "TSSymbolKeyword",
1531
+ "TSTemplateLiteralType",
1532
+ "TSThisType",
1533
+ "TSTupleType",
1534
+ "TSTypeLiteral",
1535
+ "TSTypeOperator",
1536
+ "TSTypePredicate",
1537
+ "TSTypeQuery",
1538
+ "TSTypeReference",
1539
+ "TSUndefinedKeyword",
1540
+ "TSUnionType",
1541
+ "TSUnknownKeyword",
1542
+ "TSVoidKeyword"
1543
+ ]);
1544
+ function isTypeNode(node) {
1545
+ return typeNodeKinds.has(node.type);
1546
+ }
1547
+ function typeReferenceName3(type) {
1548
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
1549
+ }
1550
+ function isInsideTypeAliasDeclaration(node) {
1551
+ let current = node.parent;
1552
+ while (current !== null && current.type !== "Program") {
1553
+ if (current.type === "TSTypeAliasDeclaration") return true;
1554
+ current = current.parent;
1555
+ }
1556
+ return false;
1557
+ }
1558
+ function isPlainAliasConsumerUse(node, environment) {
1559
+ if (node.type !== "TSTypeReference" || node.typeArguments?.params.length) return false;
1560
+ const name = typeReferenceName3(node);
1561
+ return name !== null && visibleTypeAlias(name, node, environment.typeAliases) !== null && !isInsideTypeAliasDeclaration(node);
1562
+ }
1563
+ function isInsideTypeParameterConstraint(node) {
1564
+ let child = node;
1565
+ let parent = child.parent;
1566
+ while (parent !== null && parent.type !== "Program") {
1567
+ if (parent.type === "TSTypeParameter" && parent.constraint === child) return true;
1568
+ child = parent;
1569
+ parent = child.parent;
1570
+ }
1571
+ return false;
1572
+ }
1573
+ function shouldReportType(node, environment) {
1574
+ if (isInsideTypeParameterConstraint(node)) return false;
1575
+ if (isPlainAliasConsumerUse(node, environment)) return false;
1576
+ if (classifyUnsafeDictionary(node, environment) === null) return false;
1577
+ let current = node.parent;
1578
+ while (current !== null && current.type !== "Program") {
1579
+ if (isTypeNode(current) && classifyUnsafeDictionary(current, environment) !== null)
1580
+ return false;
1581
+ current = current.parent;
1582
+ }
1583
+ return true;
1584
+ }
1585
+ var noUnsafeDictionaryTypeRule = defineRule15({
1586
+ meta: {
1587
+ type: "problem",
1588
+ docs: {
1589
+ description: "Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches."
1590
+ },
1591
+ messages: {
1592
+ 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."
1593
+ }
1594
+ },
1595
+ createOnce(context) {
1596
+ let environment = null;
1597
+ const report = (node, value) => {
1598
+ context.report({ node, messageId: "unsafeDictionary", data: { value } });
1599
+ };
1600
+ const reportIfUnsafe = (node) => {
1601
+ if (environment === null || !shouldReportType(node, environment)) return;
1602
+ const unsafe = classifyUnsafeDictionary(node, environment);
1603
+ if (unsafe === null) return;
1604
+ report(node, unsafe.unsafeValue);
1605
+ };
1606
+ return {
1607
+ Program(node) {
1608
+ environment = createTypeEnvironment(
1609
+ node,
1610
+ context.sourceCode.visitorKeys
1611
+ );
1612
+ },
1613
+ TSTypeReference: reportIfUnsafe,
1614
+ TSTypeLiteral: reportIfUnsafe,
1615
+ TSMappedType: reportIfUnsafe,
1616
+ TSIndexSignature(node) {
1617
+ if (environment === null || node.typeAnnotation === null || node.parent.type === "TSTypeLiteral")
1618
+ return;
1619
+ const unsafe = classifyUnsafeDictionaryValue(
1620
+ node.typeAnnotation.typeAnnotation,
1621
+ environment
1622
+ );
1623
+ if (unsafe !== null) report(node, unsafe.unsafeValue);
1624
+ }
1625
+ };
1626
+ }
1627
+ });
1628
+
1629
+ // anti-slop/rules/no-widen-then-assert.ts
1630
+ import { defineRule as defineRule16 } from "@oxlint/plugins";
1631
+ var functionBoundaryTypes = /* @__PURE__ */ new Set([
1632
+ "ArrowFunctionExpression",
1633
+ "FunctionDeclaration",
1634
+ "FunctionExpression",
1635
+ "TSDeclareFunction",
1636
+ "TSEmptyBodyFunctionExpression"
1637
+ ]);
1638
+ function unwrapExpressionParentheses(expression) {
1639
+ let current = expression;
1640
+ while (current.type === "ParenthesizedExpression") current = current.expression;
1641
+ return current;
1642
+ }
1643
+ function unwrapTypeParentheses(type) {
1644
+ let current = type;
1645
+ while (current.type === "TSParenthesizedType") current = current.typeAnnotation;
1646
+ return current;
1647
+ }
1648
+ function typeReferenceName4(type) {
1649
+ return type.typeName.type === "Identifier" ? type.typeName.name : null;
1650
+ }
1651
+ function isUnknownOrAnyType(type) {
1652
+ const unwrapped = unwrapTypeParentheses(type);
1653
+ return unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword";
1654
+ }
1655
+ function isBroadRecordKeyType(type) {
1656
+ const unwrapped = unwrapTypeParentheses(type);
1657
+ if (unwrapped.type === "TSStringKeyword" || unwrapped.type === "TSNumberKeyword" || unwrapped.type === "TSSymbolKeyword") {
1658
+ return true;
1659
+ }
1660
+ if (unwrapped.type === "TSUnionType") return unwrapped.types.every(isBroadRecordKeyType);
1661
+ return unwrapped.type === "TSTypeReference" && typeReferenceName4(unwrapped) === "PropertyKey";
1662
+ }
1663
+ function isBroadRecordType(type) {
1664
+ const unwrapped = unwrapTypeParentheses(type);
1665
+ if (unwrapped.type === "TSTypeReference") {
1666
+ if (typeReferenceName4(unwrapped) === "Readonly") {
1667
+ const [inner] = unwrapped.typeArguments?.params ?? [];
1668
+ return inner !== void 0 && isBroadRecordType(inner);
1669
+ }
1670
+ if (typeReferenceName4(unwrapped) !== "Record") return false;
1671
+ const parameters = unwrapped.typeArguments?.params ?? [];
1672
+ return parameters.length === 2 && parameters[0] !== void 0 && parameters[1] !== void 0 && isBroadRecordKeyType(parameters[0]) && isUnknownOrAnyType(parameters[1]);
1673
+ }
1674
+ if (unwrapped.type !== "TSTypeLiteral" || unwrapped.members.length !== 1) return false;
1675
+ const [member] = unwrapped.members;
1676
+ const [parameter] = member?.type === "TSIndexSignature" ? member.parameters : [];
1677
+ return member?.type === "TSIndexSignature" && member.parameters.length === 1 && parameter !== void 0 && isBroadRecordKeyType(parameter.typeAnnotation.typeAnnotation) && isUnknownOrAnyType(member.typeAnnotation.typeAnnotation);
1678
+ }
1679
+ function broadTypeKind(type) {
1680
+ const unwrapped = unwrapTypeParentheses(type);
1681
+ if (unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword") return "top";
1682
+ if (unwrapped.type === "TSObjectKeyword") return "object";
1683
+ return isBroadRecordType(unwrapped) ? "record" : null;
1684
+ }
1685
+ function assertedExpression(node) {
1686
+ return unwrapExpressionParentheses(node.expression);
1687
+ }
1688
+ function assertionFromExpression(expression) {
1689
+ const unwrapped = unwrapExpressionParentheses(expression);
1690
+ return unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion" ? unwrapped : null;
1691
+ }
1692
+ function normalizedTypeText(sourceText, type) {
1693
+ return sourceText.slice(type.start, type.end).replaceAll(/\s+/gu, "");
1694
+ }
1695
+ function typesHaveSameSyntax(sourceText, left, right) {
1696
+ return left !== null && normalizedTypeText(sourceText, unwrapTypeParentheses(left)) === normalizedTypeText(sourceText, unwrapTypeParentheses(right));
1697
+ }
1698
+ function isDefinitelyObjectType(type) {
1699
+ const unwrapped = unwrapTypeParentheses(type);
1700
+ switch (unwrapped.type) {
1701
+ case "TSArrayType":
1702
+ case "TSConstructorType":
1703
+ case "TSFunctionType":
1704
+ case "TSMappedType":
1705
+ case "TSObjectKeyword":
1706
+ case "TSTupleType":
1707
+ return true;
1708
+ case "TSTypeLiteral":
1709
+ return unwrapped.members.length > 0;
1710
+ case "TSIntersectionType":
1711
+ return unwrapped.types.every(isDefinitelyObjectType);
1712
+ case "TSTypeOperator":
1713
+ return unwrapped.operator === "readonly" && isDefinitelyObjectType(unwrapped.typeAnnotation);
1714
+ default:
1715
+ return false;
1716
+ }
1717
+ }
1718
+ function isDefinitelyNarrowerRecordType(type) {
1719
+ const unwrapped = unwrapTypeParentheses(type);
1720
+ if (unwrapped.type === "TSTypeLiteral") {
1721
+ return unwrapped.members.some((member) => member.type !== "TSIndexSignature");
1722
+ }
1723
+ if (unwrapped.type !== "TSTypeReference") return false;
1724
+ if (typeReferenceName4(unwrapped) === "Readonly") {
1725
+ const [inner] = unwrapped.typeArguments?.params ?? [];
1726
+ return inner !== void 0 && isDefinitelyNarrowerRecordType(inner);
1727
+ }
1728
+ if (typeReferenceName4(unwrapped) !== "Record") return false;
1729
+ const parameters = unwrapped.typeArguments?.params ?? [];
1730
+ return parameters.length === 2 && parameters[1] !== void 0 && !isUnknownOrAnyType(parameters[1]);
1731
+ }
1732
+ function functionBoundary(node) {
1733
+ let current = node.parent;
1734
+ while (current !== null && current.type !== "Program") {
1735
+ if (functionBoundaryTypes.has(current.type)) return current;
1736
+ current = current.parent;
1737
+ }
1738
+ return null;
1739
+ }
1740
+ function resolvedVariableForIdentifier(scopes, identifier) {
1741
+ for (const scope of scopes) {
1742
+ const reference = scope.references.find(
1743
+ (candidate) => candidate.identifier.start === identifier.start && candidate.identifier.end === identifier.end
1744
+ );
1745
+ if (reference !== void 0) return reference.resolved;
1746
+ }
1747
+ return null;
1748
+ }
1749
+ function variableDeclarator2(variable) {
1750
+ for (const definition of variable.defs) {
1751
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator") {
1752
+ return definition.node;
1753
+ }
1754
+ }
1755
+ return null;
1756
+ }
1757
+ function knownValueEvidence(expression, scopes, boundary, visitedVariables) {
1758
+ const unwrapped = unwrapExpressionParentheses(expression);
1759
+ if (unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion") {
1760
+ if (broadTypeKind(unwrapped.typeAnnotation) !== null) return null;
1761
+ return { type: unwrapped.typeAnnotation };
1762
+ }
1763
+ if (unwrapped.type === "Literal" || unwrapped.type === "TemplateLiteral") {
1764
+ return { type: null };
1765
+ }
1766
+ if (unwrapped.type === "ArrayExpression" || unwrapped.type === "ArrowFunctionExpression" || unwrapped.type === "ClassExpression" || unwrapped.type === "FunctionExpression" || unwrapped.type === "NewExpression" || unwrapped.type === "ObjectExpression") {
1767
+ return { type: null };
1768
+ }
1769
+ if (unwrapped.type !== "Identifier") return null;
1770
+ const variable = resolvedVariableForIdentifier(scopes, unwrapped);
1771
+ if (variable === null || visitedVariables.has(variable)) return null;
1772
+ const annotatedIdentifier = variable.identifiers.find(
1773
+ (identifier) => identifier.typeAnnotation !== null && identifier.typeAnnotation !== void 0
1774
+ );
1775
+ const annotation = annotatedIdentifier?.typeAnnotation?.typeAnnotation;
1776
+ if (annotation !== void 0 && annotatedIdentifier !== void 0) {
1777
+ if (functionBoundary(annotatedIdentifier) !== boundary || broadTypeKind(annotation) !== null) {
1778
+ return null;
1779
+ }
1780
+ return { type: annotation };
1781
+ }
1782
+ const declarator = variableDeclarator2(variable);
1783
+ 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) {
1784
+ return null;
1785
+ }
1786
+ return knownValueEvidence(
1787
+ declarator.init,
1788
+ scopes,
1789
+ boundary,
1790
+ /* @__PURE__ */ new Set([...visitedVariables, variable])
1791
+ );
1792
+ }
1793
+ function widenedBinding(variable, scopes) {
1794
+ const declarator = variableDeclarator2(variable);
1795
+ 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)) {
1796
+ return null;
1797
+ }
1798
+ const boundary = functionBoundary(declarator);
1799
+ const declaredType = declarator.id.typeAnnotation?.typeAnnotation;
1800
+ const initializerAssertion = assertionFromExpression(declarator.init);
1801
+ const initializerBroadKind = initializerAssertion === null ? null : broadTypeKind(initializerAssertion.typeAnnotation);
1802
+ const declaredBroadKind = declaredType === void 0 ? null : broadTypeKind(declaredType);
1803
+ const broadKind = declaredBroadKind ?? initializerBroadKind;
1804
+ if (broadKind === null) return null;
1805
+ const originalExpression = initializerAssertion !== null && initializerBroadKind !== null ? assertedExpression(initializerAssertion) : declarator.init;
1806
+ const evidence = knownValueEvidence(originalExpression, scopes, boundary, /* @__PURE__ */ new Set([variable]));
1807
+ return evidence === null ? null : { broadKind, evidence, declaredAt: declarator.end, boundary };
1808
+ }
1809
+ function assertionIsNarrower(sourceText, broadKind, evidence, assertedType) {
1810
+ if (broadTypeKind(assertedType) !== null) return false;
1811
+ if (broadKind === "top") return true;
1812
+ if (typesHaveSameSyntax(sourceText, evidence.type, assertedType)) return true;
1813
+ if (broadKind === "object") return isDefinitelyObjectType(assertedType);
1814
+ return isDefinitelyNarrowerRecordType(assertedType);
1815
+ }
1816
+ var noWidenThenAssertRule = defineRule16({
1817
+ meta: {
1818
+ type: "problem",
1819
+ docs: {
1820
+ description: "Disallow local const flows that explicitly widen a known value before asserting the widened binding to a narrower type."
1821
+ },
1822
+ messages: {
1823
+ 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.'
1824
+ }
1825
+ },
1826
+ createOnce(context) {
1827
+ let scopes = [];
1828
+ const checkAssertion = (node) => {
1829
+ const expression = assertedExpression(node);
1830
+ if (expression.type !== "Identifier") return;
1831
+ const variable = resolvedVariableForIdentifier(scopes, expression);
1832
+ if (variable === null) return;
1833
+ const widened = widenedBinding(variable, scopes);
1834
+ if (widened === null || node.start <= widened.declaredAt || functionBoundary(node) !== widened.boundary || !assertionIsNarrower(
1835
+ context.sourceCode.text,
1836
+ widened.broadKind,
1837
+ widened.evidence,
1838
+ node.typeAnnotation
1839
+ )) {
1840
+ return;
1841
+ }
1842
+ context.report({
1843
+ node,
1844
+ messageId: "widenThenAssert",
1845
+ data: { name: expression.name }
1846
+ });
1847
+ };
1848
+ return {
1849
+ Program() {
1850
+ scopes = context.sourceCode.scopeManager.scopes;
1851
+ },
1852
+ TSAsExpression: checkAssertion,
1853
+ TSTypeAssertion: checkAssertion
1854
+ };
1855
+ }
1856
+ });
1857
+
1858
+ // anti-slop/vendor/eslint-stylistic/padding-line-ast.ts
1859
+ var LINEBREAKS = /* @__PURE__ */ new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]);
1860
+ var isClosingBraceToken = (token) => token.type === "Punctuator" && token.value === "}";
1861
+ var isSemicolonToken = (token) => token.type === "Punctuator" && token.value === ";";
1862
+ var isNotSemicolonToken = (token) => !isSemicolonToken(token);
1863
+ var isTokenOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
1864
+ var isFunction = (node) => node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
1865
+ var isSingleLine = (node) => node.loc.start.line === node.loc.end.line;
1866
+ var skipChainExpression = (node) => node.type === "ChainExpression" ? node.expression : node;
1867
+ var isTopLevelExpressionStatement = (node) => node.type === "ExpressionStatement" && (node.parent.type === "Program" || node.parent.type === "BlockStatement" && isFunction(node.parent.parent));
1868
+ function isParenthesized(node, sourceCode) {
1869
+ const before = sourceCode.getTokenBefore(node);
1870
+ const after = sourceCode.getTokenAfter(node);
1871
+ return before?.value === "(" && after?.value === ")";
1872
+ }
1873
+
1874
+ // anti-slop/vendor/eslint-stylistic/padding-line-between-statements.ts
1875
+ var CJS_EXPORT = /^(?:module\s*\.\s*)?exports(?:\s*\.|\s*\[|$)/u;
1876
+ var CJS_IMPORT = /^require\(/u;
1877
+ var LT = `[${Array.from(LINEBREAKS).join("")}]`;
1878
+ var PADDING_LINE_SEQUENCE = new RegExp(
1879
+ String.raw`^(\s*?${LT})\s*${LT}(\s*;?)$`,
1880
+ "u"
1881
+ );
1882
+ function isSelectorOption(option) {
1883
+ return typeof option === "object" && !Array.isArray(option);
1884
+ }
1885
+ function newKeywordTester(type, keyword) {
1886
+ return {
1887
+ test(node, sourceCode) {
1888
+ const isSameKeyword = sourceCode.getFirstToken(node)?.value === keyword;
1889
+ const isSameType = Array.isArray(type) ? type.includes(node.type) : type === node.type;
1890
+ return isSameKeyword && isSameType;
1891
+ }
1892
+ };
1893
+ }
1894
+ function newNodeTypeTester(type) {
1895
+ return {
1896
+ test: (node) => node.type === type
1897
+ };
1898
+ }
1899
+ function isIIFEStatement(node) {
1900
+ if (node.type === "ExpressionStatement") {
1901
+ let expression = skipChainExpression(node.expression);
1902
+ if (expression.type === "UnaryExpression")
1903
+ expression = skipChainExpression(expression.argument);
1904
+ if (expression.type === "CallExpression") {
1905
+ let node2 = expression.callee;
1906
+ while (node2.type === "SequenceExpression") {
1907
+ const lastExpression = node2.expressions.at(-1);
1908
+ if (lastExpression === void 0)
1909
+ throw new Error("Padding rule invariant: sequence expression is empty");
1910
+ node2 = lastExpression;
1911
+ }
1912
+ return isFunction(node2);
1913
+ }
1914
+ }
1915
+ return false;
1916
+ }
1917
+ function isCJSRequire(node) {
1918
+ if (node.type === "VariableDeclaration") {
1919
+ const declaration = node.declarations[0];
1920
+ if (declaration?.init) {
1921
+ let call = declaration?.init;
1922
+ while (call.type === "MemberExpression")
1923
+ call = call.object;
1924
+ if (call.type === "CallExpression" && call.callee.type === "Identifier") {
1925
+ return call.callee.name === "require";
1926
+ }
1927
+ }
1928
+ }
1929
+ return false;
1930
+ }
1931
+ function isBlockLikeStatement(node, sourceCode) {
1932
+ if (node.type === "DoWhileStatement" && node.body.type === "BlockStatement") {
1933
+ return true;
1934
+ }
1935
+ if (isIIFEStatement(node))
1936
+ return true;
1937
+ const lastToken = sourceCode.getLastToken(node, isNotSemicolonToken);
1938
+ const belongingNode = lastToken && isClosingBraceToken(lastToken) ? sourceCode.getNodeByRangeIndex(lastToken.range[0]) : null;
1939
+ return !!belongingNode && (belongingNode.type === "BlockStatement" || belongingNode.type === "SwitchStatement");
1940
+ }
1941
+ function isDirective(node, sourceCode) {
1942
+ return isTopLevelExpressionStatement(node) && node.expression.type === "Literal" && typeof node.expression.value === "string" && !isParenthesized(node.expression, sourceCode);
1943
+ }
1944
+ function isDirectivePrologue(node, sourceCode) {
1945
+ if (isDirective(node, sourceCode) && node.parent && "body" in node.parent && Array.isArray(node.parent.body)) {
1946
+ for (const sibling of node.parent.body) {
1947
+ if (sibling === node)
1948
+ break;
1949
+ if (!isDirective(sibling, sourceCode))
1950
+ return false;
1951
+ }
1952
+ return true;
1953
+ }
1954
+ return false;
1955
+ }
1956
+ function isCJSExport(node) {
1957
+ if (node.type === "ExpressionStatement") {
1958
+ const expression = node.expression;
1959
+ if (expression.type === "AssignmentExpression") {
1960
+ let left = expression.left;
1961
+ if (left.type === "MemberExpression") {
1962
+ while (left.object.type === "MemberExpression")
1963
+ left = left.object;
1964
+ return left.object.type === "Identifier" && (left.object.name === "exports" || left.object.name === "module" && left.property.type === "Identifier" && left.property.name === "exports");
1965
+ }
1966
+ }
1967
+ }
1968
+ return false;
1969
+ }
1970
+ function isExpression(node, sourceCode) {
1971
+ return node.type === "ExpressionStatement" && !isDirectivePrologue(node, sourceCode);
1972
+ }
1973
+ function getActualLastToken(node, sourceCode) {
1974
+ const semiToken = sourceCode.getLastToken(node);
1975
+ const prevToken = sourceCode.getTokenBefore(semiToken);
1976
+ const nextToken = sourceCode.getTokenAfter(semiToken);
1977
+ const isSemicolonLessStyle = prevToken && nextToken && prevToken.range[0] >= node.range[0] && isSemicolonToken(semiToken) && !isTokenOnSameLine(prevToken, semiToken) && isTokenOnSameLine(semiToken, nextToken);
1978
+ return isSemicolonLessStyle ? prevToken : semiToken;
1979
+ }
1980
+ function replacerToRemovePaddingLines(_, trailingSpaces, indentSpaces) {
1981
+ return trailingSpaces + indentSpaces;
1982
+ }
1983
+ function getReportLoc(node, sourceCode) {
1984
+ if (isSingleLine(node))
1985
+ return node.loc;
1986
+ const line = node.loc.start.line;
1987
+ const sourceLine = sourceCode.lines[line - 1];
1988
+ if (sourceLine === void 0)
1989
+ throw new Error("Padding rule invariant: statement source line is missing");
1990
+ return {
1991
+ start: node.loc.start,
1992
+ end: {
1993
+ line,
1994
+ column: sourceLine.length
1995
+ }
1996
+ };
1997
+ }
1998
+ function verifyForAny() {
1999
+ }
2000
+ function verifyForNever(context, _, nextNode, paddingLines) {
2001
+ if (paddingLines.length === 0)
2002
+ return;
2003
+ context.report({
2004
+ node: nextNode,
2005
+ messageId: "unexpectedBlankLine",
2006
+ loc: getReportLoc(nextNode, context.sourceCode),
2007
+ fix(fixer) {
2008
+ if (paddingLines.length >= 2)
2009
+ return null;
2010
+ const paddingPair = paddingLines[0];
2011
+ if (paddingPair === void 0)
2012
+ throw new Error("Padding rule invariant: reported padding pair is missing");
2013
+ const [prevToken, nextToken] = paddingPair;
2014
+ const start = prevToken.range[1];
2015
+ const end = nextToken.range[0];
2016
+ const text = context.sourceCode.text.slice(start, end).replace(PADDING_LINE_SEQUENCE, replacerToRemovePaddingLines);
2017
+ return fixer.replaceTextRange([start, end], text);
2018
+ }
2019
+ });
2020
+ }
2021
+ function verifyForAlways(context, prevNode, nextNode, paddingLines) {
2022
+ if (paddingLines.length > 0)
2023
+ return;
2024
+ context.report({
2025
+ node: nextNode,
2026
+ messageId: "expectedBlankLine",
2027
+ loc: getReportLoc(nextNode, context.sourceCode),
2028
+ fix(fixer) {
2029
+ const sourceCode = context.sourceCode;
2030
+ let prevToken = getActualLastToken(prevNode, sourceCode);
2031
+ const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
2032
+ includeComments: true,
2033
+ /**
2034
+ * Skip the trailing comments of the previous node.
2035
+ * This inserts a blank line after the last trailing comment.
2036
+ *
2037
+ * For example:
2038
+ *
2039
+ * foo(); // trailing comment.
2040
+ * // comment.
2041
+ * bar();
2042
+ *
2043
+ * Get fixed to:
2044
+ *
2045
+ * foo(); // trailing comment.
2046
+ *
2047
+ * // comment.
2048
+ * bar();
2049
+ * @param token The token to check.
2050
+ * @returns `true` if the token is not a trailing comment.
2051
+ * @private
2052
+ */
2053
+ filter(token) {
2054
+ if (isTokenOnSameLine(prevToken, token)) {
2055
+ prevToken = token;
2056
+ return false;
2057
+ }
2058
+ return true;
2059
+ }
2060
+ }) || nextNode;
2061
+ const insertText = isTokenOnSameLine(prevToken, nextToken) ? "\n\n" : "\n";
2062
+ return fixer.insertTextAfter(prevToken, insertText);
2063
+ }
2064
+ });
2065
+ }
2066
+ var PaddingTypes = {
2067
+ any: { verify: verifyForAny },
2068
+ never: { verify: verifyForNever },
2069
+ always: { verify: verifyForAlways }
2070
+ };
2071
+ var MaybeMultilineStatementType = {
2072
+ "block-like": { test: isBlockLikeStatement },
2073
+ "expression": { test: isExpression },
2074
+ "return": newKeywordTester("ReturnStatement", "return"),
2075
+ "export": newKeywordTester(
2076
+ [
2077
+ "ExportAllDeclaration",
2078
+ "ExportDefaultDeclaration",
2079
+ "ExportNamedDeclaration"
2080
+ ],
2081
+ "export"
2082
+ ),
2083
+ "var": newKeywordTester("VariableDeclaration", "var"),
2084
+ "let": newKeywordTester("VariableDeclaration", "let"),
2085
+ "const": newKeywordTester("VariableDeclaration", "const"),
2086
+ "using": {
2087
+ test: (node) => node.type === "VariableDeclaration" && (node.kind === "using" || node.kind === "await using")
2088
+ },
2089
+ "type": newKeywordTester("TSTypeAliasDeclaration", "type")
2090
+ };
2091
+ var StatementTypes = {
2092
+ "*": { test: () => true },
2093
+ "exports": { test: isCJSExport },
2094
+ "require": { test: isCJSRequire },
2095
+ "directive": { test: isDirectivePrologue },
2096
+ "iife": { test: isIIFEStatement },
2097
+ "block": newNodeTypeTester("BlockStatement"),
2098
+ "empty": newNodeTypeTester("EmptyStatement"),
2099
+ "function": newNodeTypeTester("FunctionDeclaration"),
2100
+ "ts-method": newNodeTypeTester("TSMethodSignature"),
2101
+ "break": newKeywordTester("BreakStatement", "break"),
2102
+ "case": newKeywordTester("SwitchCase", "case"),
2103
+ "class": newKeywordTester("ClassDeclaration", "class"),
2104
+ "continue": newKeywordTester("ContinueStatement", "continue"),
2105
+ "debugger": newKeywordTester("DebuggerStatement", "debugger"),
2106
+ "default": newKeywordTester(
2107
+ ["SwitchCase", "ExportDefaultDeclaration"],
2108
+ "default"
2109
+ ),
2110
+ "do": newKeywordTester("DoWhileStatement", "do"),
2111
+ "for": newKeywordTester(
2112
+ [
2113
+ "ForStatement",
2114
+ "ForInStatement",
2115
+ "ForOfStatement"
2116
+ ],
2117
+ "for"
2118
+ ),
2119
+ "if": newKeywordTester("IfStatement", "if"),
2120
+ "import": newKeywordTester("ImportDeclaration", "import"),
2121
+ "switch": newKeywordTester("SwitchStatement", "switch"),
2122
+ "throw": newKeywordTester("ThrowStatement", "throw"),
2123
+ "try": newKeywordTester("TryStatement", "try"),
2124
+ "while": newKeywordTester(
2125
+ ["WhileStatement", "DoWhileStatement"],
2126
+ "while"
2127
+ ),
2128
+ "with": newKeywordTester("WithStatement", "with"),
2129
+ "cjs-export": {
2130
+ test: (node, sourceCode) => node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && CJS_EXPORT.test(sourceCode.getText(node.expression.left))
2131
+ },
2132
+ "cjs-import": {
2133
+ test: (node, sourceCode) => node.type === "VariableDeclaration" && node.declarations.length > 0 && node.declarations[0]?.init != null && CJS_IMPORT.test(sourceCode.getText(node.declarations[0].init))
2134
+ },
2135
+ "enum": newKeywordTester(
2136
+ "TSEnumDeclaration",
2137
+ "enum"
2138
+ ),
2139
+ "interface": newKeywordTester(
2140
+ "TSInterfaceDeclaration",
2141
+ "interface"
2142
+ ),
2143
+ "function-overload": newNodeTypeTester("TSDeclareFunction"),
2144
+ ...Object.fromEntries(
2145
+ Object.entries(MaybeMultilineStatementType).flatMap(([key, value]) => [
2146
+ [key, value],
2147
+ [
2148
+ `singleline-${key}`,
2149
+ {
2150
+ ...value,
2151
+ test: (node, sourceCode) => value.test(node, sourceCode) && isSingleLine(node)
2152
+ }
2153
+ ],
2154
+ [
2155
+ `multiline-${key}`,
2156
+ {
2157
+ ...value,
2158
+ test: (node, sourceCode) => value.test(node, sourceCode) && !isSingleLine(node)
2159
+ }
2160
+ ]
2161
+ ])
2162
+ )
2163
+ };
2164
+ function createPaddingLineRule(options, statementTypes) {
2165
+ const customStatementTypes = statementTypes ?? {};
2166
+ return {
2167
+ meta: {
2168
+ type: "layout",
2169
+ docs: {
2170
+ description: "Require or disallow padding lines between statements"
2171
+ },
2172
+ fixable: "whitespace",
2173
+ hasSuggestions: false,
2174
+ // This is intentionally an array schema as you can pass 0..n config objects
2175
+ schema: {
2176
+ $defs: {
2177
+ paddingType: {
2178
+ type: "string",
2179
+ enum: Object.keys(PaddingTypes)
2180
+ },
2181
+ statementType: {
2182
+ type: "string",
2183
+ enum: Object.keys(StatementTypes)
2184
+ },
2185
+ selectorOption: {
2186
+ type: "object",
2187
+ properties: {
2188
+ selector: {
2189
+ type: "string"
2190
+ },
2191
+ lineMode: {
2192
+ type: "string",
2193
+ enum: ["any", "singleline", "multiline"]
2194
+ }
2195
+ },
2196
+ required: ["selector"],
2197
+ additionalProperties: false
2198
+ },
2199
+ statementMatcher: {
2200
+ anyOf: [
2201
+ { $ref: "#/$defs/statementType" },
2202
+ { $ref: "#/$defs/selectorOption" }
2203
+ ]
2204
+ },
2205
+ statementOption: {
2206
+ anyOf: [
2207
+ { $ref: "#/$defs/statementMatcher" },
2208
+ {
2209
+ type: "array",
2210
+ items: { $ref: "#/$defs/statementMatcher" },
2211
+ minItems: 1,
2212
+ uniqueItems: true,
2213
+ additionalItems: false
2214
+ }
2215
+ ]
2216
+ }
2217
+ },
2218
+ type: "array",
2219
+ additionalItems: false,
2220
+ items: {
2221
+ type: "object",
2222
+ properties: {
2223
+ blankLine: { $ref: "#/$defs/paddingType" },
2224
+ prev: { $ref: "#/$defs/statementOption" },
2225
+ next: { $ref: "#/$defs/statementOption" }
2226
+ },
2227
+ additionalProperties: false,
2228
+ required: ["blankLine", "prev", "next"]
2229
+ }
2230
+ },
2231
+ messages: {
2232
+ unexpectedBlankLine: "Unexpected blank line before this statement.",
2233
+ expectedBlankLine: "Expected blank line before this statement."
2234
+ }
2235
+ },
2236
+ create(context) {
2237
+ const sourceCode = context.sourceCode;
2238
+ const selectorMatchedNodes = /* @__PURE__ */ new Map();
2239
+ const pendingPairs = [];
2240
+ function collectSelectorOption(option) {
2241
+ if (Array.isArray(option)) {
2242
+ for (const item of option)
2243
+ collectSelectorOption(item);
2244
+ return;
2245
+ }
2246
+ if (!isSelectorOption(option))
2247
+ return;
2248
+ selectorMatchedNodes.set(option.selector, /* @__PURE__ */ new Set());
2249
+ }
2250
+ for (const configure of options) {
2251
+ collectSelectorOption(configure.prev);
2252
+ collectSelectorOption(configure.next);
2253
+ }
2254
+ let scopeInfo = null;
2255
+ function enterScope() {
2256
+ scopeInfo = {
2257
+ upper: scopeInfo,
2258
+ prevNode: null
2259
+ };
2260
+ }
2261
+ function exitScope() {
2262
+ if (scopeInfo)
2263
+ scopeInfo = scopeInfo.upper;
2264
+ }
2265
+ function match(node, type) {
2266
+ let innerStatementNode = node;
2267
+ while (innerStatementNode.type === "LabeledStatement")
2268
+ innerStatementNode = innerStatementNode.body;
2269
+ if (Array.isArray(type))
2270
+ return type.some(match.bind(null, innerStatementNode));
2271
+ if (isSelectorOption(type)) {
2272
+ const matchedNodes = selectorMatchedNodes.get(type.selector);
2273
+ if (!matchedNodes?.has(innerStatementNode))
2274
+ return false;
2275
+ const lineMode = type.lineMode;
2276
+ if (lineMode === "singleline")
2277
+ return isSingleLine(innerStatementNode);
2278
+ else if (lineMode === "multiline")
2279
+ return !isSingleLine(innerStatementNode);
2280
+ return true;
2281
+ } else {
2282
+ const statementType = customStatementTypes[type] ?? StatementTypes[type];
2283
+ if (statementType === void 0)
2284
+ throw new Error(`Padding rule invariant: unsupported statement type ${type}`);
2285
+ return statementType.test(innerStatementNode, sourceCode);
2286
+ }
2287
+ }
2288
+ function getPaddingType(prevNode, nextNode) {
2289
+ for (let i = options.length - 1; i >= 0; --i) {
2290
+ const configure = options[i];
2291
+ if (configure === void 0)
2292
+ throw new Error("Padding rule invariant: configuration entry is missing");
2293
+ if (match(prevNode, configure.prev) && match(nextNode, configure.next)) {
2294
+ return PaddingTypes[configure.blankLine];
2295
+ }
2296
+ }
2297
+ return PaddingTypes.any;
2298
+ }
2299
+ function getPaddingLineSequences(prevNode, nextNode) {
2300
+ const pairs = [];
2301
+ let prevToken = getActualLastToken(prevNode, sourceCode);
2302
+ if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
2303
+ do {
2304
+ const token = sourceCode.getTokenAfter(prevToken, {
2305
+ includeComments: true
2306
+ });
2307
+ if (token.loc.start.line - prevToken.loc.end.line >= 2)
2308
+ pairs.push([prevToken, token]);
2309
+ prevToken = token;
2310
+ } while (prevToken.range[0] < nextNode.range[0]);
2311
+ }
2312
+ return pairs;
2313
+ }
2314
+ function verify(node) {
2315
+ if (!node.parent || ![
2316
+ "BlockStatement",
2317
+ "Program",
2318
+ "StaticBlock",
2319
+ "SwitchCase",
2320
+ "SwitchStatement",
2321
+ "TSInterfaceBody",
2322
+ "TSModuleBlock",
2323
+ "TSTypeLiteral"
2324
+ ].includes(node.parent.type)) {
2325
+ return;
2326
+ }
2327
+ const prevNode = scopeInfo.prevNode;
2328
+ if (prevNode)
2329
+ pendingPairs.push({ prevNode, nextNode: node });
2330
+ scopeInfo.prevNode = node;
2331
+ }
2332
+ function verifyPendingPairs() {
2333
+ for (const { prevNode, nextNode } of pendingPairs) {
2334
+ const type = getPaddingType(prevNode, nextNode);
2335
+ const paddingLines = getPaddingLineSequences(prevNode, nextNode);
2336
+ type.verify(context, prevNode, nextNode, paddingLines);
2337
+ }
2338
+ }
2339
+ function verifyThenEnterScope(node) {
2340
+ verify(node);
2341
+ enterScope();
2342
+ }
2343
+ const selectorMatchListeners = Object.fromEntries(
2344
+ Array.from(selectorMatchedNodes.keys(), (selector) => [
2345
+ selector,
2346
+ (node) => {
2347
+ selectorMatchedNodes.get(selector)?.add(node);
2348
+ }
2349
+ ])
2350
+ );
2351
+ return {
2352
+ "Program": enterScope,
2353
+ "Program:exit": () => {
2354
+ verifyPendingPairs();
2355
+ exitScope();
2356
+ },
2357
+ "BlockStatement": enterScope,
2358
+ "BlockStatement:exit": exitScope,
2359
+ "SwitchStatement": enterScope,
2360
+ "SwitchStatement:exit": exitScope,
2361
+ "SwitchCase": verifyThenEnterScope,
2362
+ "SwitchCase:exit": exitScope,
2363
+ "StaticBlock": enterScope,
2364
+ "StaticBlock:exit": exitScope,
2365
+ "TSInterfaceBody": enterScope,
2366
+ "TSInterfaceBody:exit": exitScope,
2367
+ "TSModuleBlock": enterScope,
2368
+ "TSModuleBlock:exit": exitScope,
2369
+ "TSTypeLiteral": enterScope,
2370
+ "TSTypeLiteral:exit": exitScope,
2371
+ "TSDeclareFunction": verifyThenEnterScope,
2372
+ "TSDeclareFunction:exit": exitScope,
2373
+ "TSMethodSignature": verifyThenEnterScope,
2374
+ "TSMethodSignature:exit": exitScope,
2375
+ ":statement": verify,
2376
+ ...selectorMatchListeners
2377
+ };
2378
+ }
2379
+ };
2380
+ }
2381
+
2382
+ // anti-slop/rules/require-readable-spacing.ts
2383
+ function isSinglelineBinding(node) {
2384
+ const declaration = node.type === "ExportNamedDeclaration" ? node.declaration : node;
2385
+ return declaration?.type === "VariableDeclaration" && node.loc.start.line === node.loc.end.line;
2386
+ }
2387
+ function hasLeadingComment(node, sourceCode) {
2388
+ const previousLine = sourceCode.getTokenBefore(node)?.loc.end.line;
2389
+ return sourceCode.getCommentsBefore(node).some((comment) => comment.loc.start.line !== previousLine);
2390
+ }
2391
+ var singlelineBinding = {
2392
+ test: (node) => isSinglelineBinding(node)
2393
+ };
2394
+ var undocumentedSinglelineBinding = {
2395
+ test: (node, sourceCode) => isSinglelineBinding(node) && !hasLeadingComment(node, sourceCode)
2396
+ };
2397
+ var paddingRule = createPaddingLineRule(
2398
+ [
2399
+ { blankLine: "always", prev: "import", next: "*" },
2400
+ { blankLine: "always", prev: "*", next: { selector: "Program > :not(ImportDeclaration)" } },
2401
+ { blankLine: "always", prev: { selector: "Program > :not(ImportDeclaration)" }, next: "*" },
2402
+ { blankLine: "always", prev: "*", next: ["function", "class", "interface", "type"] },
2403
+ { blankLine: "always", prev: ["function", "class", "interface", "type"], next: "*" },
2404
+ {
2405
+ blankLine: "always",
2406
+ prev: "*",
2407
+ next: ["multiline-const", "multiline-let", "multiline-var", "multiline-using"]
2408
+ },
2409
+ {
2410
+ blankLine: "always",
2411
+ prev: ["multiline-const", "multiline-let", "multiline-var", "multiline-using"],
2412
+ next: "*"
2413
+ },
2414
+ { blankLine: "always", prev: "*", next: ["return", "if", "switch", "try", "for", "while", "do"] },
2415
+ { blankLine: "always", prev: "block-like", next: "*" },
2416
+ { blankLine: "any", prev: "import", next: "import" },
2417
+ // Consecutive single-line bindings form one group at any scope, including
2418
+ // module scope. A binding with its own leading comment starts a new group.
2419
+ { blankLine: "any", prev: "singleline-binding", next: "undocumented-singleline-binding" },
2420
+ {
2421
+ blankLine: "any",
2422
+ prev: {
2423
+ selector: ':matches(TSDeclareFunction, ExportNamedDeclaration[declaration.type="TSDeclareFunction"])'
2424
+ },
2425
+ next: {
2426
+ selector: ':matches(TSDeclareFunction, FunctionDeclaration, ExportNamedDeclaration[declaration.type="TSDeclareFunction"], ExportNamedDeclaration[declaration.type="FunctionDeclaration"])'
2427
+ }
2428
+ }
2429
+ ],
2430
+ {
2431
+ "singleline-binding": singlelineBinding,
2432
+ "undocumented-singleline-binding": undocumentedSinglelineBinding
2433
+ }
2434
+ );
2435
+ var requireReadableSpacingRule = {
2436
+ ...paddingRule,
2437
+ meta: {
2438
+ ...paddingRule.meta,
2439
+ docs: {
2440
+ description: "Require readable spacing between declarations and logical statement groups."
2441
+ },
2442
+ schema: []
2443
+ }
2444
+ };
2445
+
2446
+ // anti-slop/rules/require-safety-comment-for-type-assertion.ts
2447
+ import { defineRule as defineRule17 } from "@oxlint/plugins";
2448
+ var DEFAULT_SAFETY_MARKERS = ["SAFETY"];
2449
+ var commentOwnerKinds = /* @__PURE__ */ new Set([
2450
+ "ExpressionStatement",
2451
+ "PropertyDefinition",
2452
+ "ReturnStatement",
2453
+ "ThrowStatement",
2454
+ "VariableDeclaration"
2455
+ ]);
2456
+ function isConstAssertion2(node) {
2457
+ return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
2458
+ }
2459
+ function configuredSafetyMarkers(option) {
2460
+ if (typeof option !== "object" || option === null || !("markers" in option)) {
2461
+ return DEFAULT_SAFETY_MARKERS;
2462
+ }
2463
+ const configured = option.markers;
2464
+ if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
2465
+ const markers = configured.flatMap(
2466
+ (marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []
2467
+ );
2468
+ return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
2469
+ }
2470
+ function markerPattern(markers) {
2471
+ const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
2472
+ return new RegExp(
2473
+ String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`,
2474
+ "u"
2475
+ );
2476
+ }
2477
+ function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
2478
+ return sourceCode.getCommentsBefore(owner).some(
2479
+ (comment) => comment.end <= assertion.start && pattern.test(comment.value)
2480
+ );
2481
+ }
2482
+ function hasSafetyComment(sourceCode, node, pattern) {
2483
+ let current = node;
2484
+ while (true) {
2485
+ if (hasSafetyJustificationBefore(sourceCode, current, node, pattern)) return true;
2486
+ if (commentOwnerKinds.has(current.type)) {
2487
+ const exportDeclaration = current.parent;
2488
+ return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern);
2489
+ }
2490
+ if (current.parent.type === "Program") return false;
2491
+ current = current.parent;
2492
+ }
2493
+ }
2494
+ var requireSafetyCommentForTypeAssertionRule = defineRule17({
2495
+ meta: {
2496
+ type: "problem",
2497
+ docs: {
2498
+ description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions."
2499
+ },
2500
+ messages: {
2501
+ missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement."
2502
+ },
2503
+ schema: [
2504
+ {
2505
+ type: "object",
2506
+ properties: {
2507
+ markers: {
2508
+ type: "array",
2509
+ items: { type: "string", minLength: 1 },
2510
+ minItems: 1,
2511
+ uniqueItems: true
2512
+ }
2513
+ },
2514
+ additionalProperties: false
2515
+ }
2516
+ ],
2517
+ defaultOptions: [{ markers: ["SAFETY"] }]
2518
+ },
2519
+ createOnce(context) {
2520
+ const patterns = /* @__PURE__ */ new Map();
2521
+ const checkAssertion = (node) => {
2522
+ if (isConstAssertion2(node)) return;
2523
+ const markers = configuredSafetyMarkers(context.options?.[0]);
2524
+ const patternKey = markers.join("\0");
2525
+ const pattern = patterns.get(patternKey) ?? markerPattern(markers);
2526
+ patterns.set(patternKey, pattern);
2527
+ if (hasSafetyComment(context.sourceCode, node, pattern)) return;
2528
+ context.report({
2529
+ node,
2530
+ messageId: "missingSafetyComment",
2531
+ data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
2532
+ });
2533
+ };
2534
+ return {
2535
+ TSAsExpression: checkAssertion,
2536
+ TSTypeAssertion: checkAssertion
2537
+ };
2538
+ }
2539
+ });
2540
+
2541
+ // anti-slop/index.ts
2542
+ var antiSlopPlugin = eslintCompatPlugin({
2543
+ meta: { name: "anti-slop" },
2544
+ rules: {
2545
+ "no-array-filter-map": noArrayFilterMapRule,
2546
+ "no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
2547
+ "no-chained-type-assertions": noChainedTypeAssertionsRule,
2548
+ "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
2549
+ "no-known-value-widening": noKnownValueWideningRule,
2550
+ "no-module-mocking": noModuleMockingRule,
2551
+ "no-object-parameters": noObjectParametersRule,
2552
+ "no-reflect-apply": noReflectApplyRule,
2553
+ "no-reflect-get": noReflectGetRule,
2554
+ "no-runtime-typeof": noRuntimeTypeofRule,
2555
+ "no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
2556
+ "no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
2557
+ "no-unknown-parameters": noUnknownParametersRule,
2558
+ "no-unknown-returns": noUnknownReturnsRule,
2559
+ "no-unknown-type-aliases": noUnknownTypeAliasesRule,
2560
+ "no-widen-then-assert": noWidenThenAssertRule,
2561
+ "require-readable-spacing": requireReadableSpacingRule,
2562
+ "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule
2563
+ }
2564
+ });
2565
+ var anti_slop_default = antiSlopPlugin;
2566
+ export {
2567
+ anti_slop_default as default
2568
+ };
2569
+ //# sourceMappingURL=anti-slop.js.map