ai-deslop 0.2.0 → 0.2.2

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 (97) hide show
  1. package/README.md +35 -106
  2. package/dist/index.d.ts +18 -0
  3. package/dist/index.js +84 -0
  4. package/dist/rules/no-array-filter-map.d.ts +2 -0
  5. package/dist/rules/no-array-filter-map.js +30 -0
  6. package/dist/rules/no-call-only-assertions.d.ts +2 -0
  7. package/dist/rules/no-call-only-assertions.js +87 -0
  8. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  9. package/dist/rules/no-chained-type-assertions.js +60 -0
  10. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  11. package/dist/rules/no-conditional-empty-object-spread.js +40 -0
  12. package/dist/rules/no-duplicate-types.d.ts +2 -0
  13. package/dist/rules/no-duplicate-types.js +143 -0
  14. package/dist/rules/no-known-value-widening.d.ts +2 -0
  15. package/dist/rules/no-known-value-widening.js +300 -0
  16. package/dist/rules/no-module-mocking.d.ts +2 -0
  17. package/dist/rules/no-module-mocking.js +69 -0
  18. package/dist/rules/no-object-parameters.d.ts +2 -0
  19. package/dist/rules/no-object-parameters.js +56 -0
  20. package/dist/rules/no-pass-through-type-alias.d.ts +2 -0
  21. package/dist/rules/no-pass-through-type-alias.js +41 -0
  22. package/dist/rules/no-reduce-accumulator-copy.d.ts +2 -0
  23. package/dist/rules/no-reduce-accumulator-copy.js +99 -0
  24. package/dist/rules/no-reflect-apply.d.ts +2 -0
  25. package/dist/rules/no-reflect-apply.js +25 -0
  26. package/dist/rules/no-reflect-get.d.ts +2 -0
  27. package/dist/rules/no-reflect-get.js +25 -0
  28. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  29. package/dist/rules/no-runtime-typeof.js +64 -0
  30. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  31. package/dist/rules/no-shape-in-symbol-names.js +40 -0
  32. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  33. package/dist/rules/no-unknown-parameters.js +51 -0
  34. package/dist/rules/no-unknown-returns.d.ts +2 -0
  35. package/dist/rules/no-unknown-returns.js +58 -0
  36. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  37. package/dist/rules/no-unknown-type-aliases.js +40 -0
  38. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  39. package/dist/rules/no-unsafe-dictionary-type.js +134 -0
  40. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  41. package/dist/rules/no-widen-then-assert.js +270 -0
  42. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  43. package/dist/rules/require-safety-comment-for-type-assertion.js +100 -0
  44. package/dist/shared/array-method.d.ts +12 -0
  45. package/dist/shared/array-method.js +84 -0
  46. package/dist/shared/dictionary-types.d.ts +20 -0
  47. package/dist/shared/dictionary-types.js +377 -0
  48. package/dist/shared/function-parameters.d.ts +8 -0
  49. package/dist/shared/function-parameters.js +40 -0
  50. package/dist/shared/lexical-type-parameters.d.ts +5 -0
  51. package/dist/shared/lexical-type-parameters.js +47 -0
  52. package/dist/shared/reflect-method.d.ts +3 -0
  53. package/dist/shared/reflect-method.js +20 -0
  54. package/dist/shared/scope.d.ts +3 -0
  55. package/dist/shared/scope.js +11 -0
  56. package/dist/shared/type-alias-resolution.d.ts +23 -0
  57. package/dist/shared/type-alias-resolution.js +162 -0
  58. package/dist/tailwind/candidates.d.ts +14 -0
  59. package/dist/tailwind/candidates.js +24 -0
  60. package/dist/tailwind/design-system.d.ts +3 -0
  61. package/dist/tailwind/design-system.js +41 -0
  62. package/dist/tailwind/rule.d.ts +3 -0
  63. package/dist/tailwind/rule.js +133 -0
  64. package/dist/tailwind/worker.d.ts +1 -0
  65. package/dist/tailwind/worker.js +13 -0
  66. package/package.json +16 -5
  67. package/src/index.ts +0 -87
  68. package/src/rules/no-array-filter-map.ts +0 -28
  69. package/src/rules/no-call-only-assertions.ts +0 -94
  70. package/src/rules/no-chained-type-assertions.ts +0 -77
  71. package/src/rules/no-conditional-empty-object-spread.ts +0 -49
  72. package/src/rules/no-known-value-widening.ts +0 -415
  73. package/src/rules/no-module-mocking.ts +0 -80
  74. package/src/rules/no-object-parameters.ts +0 -83
  75. package/src/rules/no-pass-through-type-alias.ts +0 -52
  76. package/src/rules/no-reduce-accumulator-copy.ts +0 -109
  77. package/src/rules/no-reflect-apply.ts +0 -28
  78. package/src/rules/no-reflect-get.ts +0 -28
  79. package/src/rules/no-runtime-typeof.ts +0 -77
  80. package/src/rules/no-shape-in-symbol-names.ts +0 -46
  81. package/src/rules/no-unknown-parameters.ts +0 -69
  82. package/src/rules/no-unknown-returns.ts +0 -82
  83. package/src/rules/no-unknown-type-aliases.ts +0 -54
  84. package/src/rules/no-unsafe-dictionary-type.ts +0 -154
  85. package/src/rules/no-widen-then-assert.ts +0 -366
  86. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -131
  87. package/src/shared/array-method.ts +0 -94
  88. package/src/shared/dictionary-types.ts +0 -515
  89. package/src/shared/function-parameters.ts +0 -49
  90. package/src/shared/lexical-type-parameters.ts +0 -61
  91. package/src/shared/reflect-method.ts +0 -24
  92. package/src/shared/scope.ts +0 -15
  93. package/src/shared/type-alias-resolution.ts +0 -250
  94. package/src/tailwind/candidates.ts +0 -38
  95. package/src/tailwind/design-system.ts +0 -59
  96. package/src/tailwind/rule.ts +0 -126
  97. package/src/tailwind/worker.ts +0 -38
@@ -0,0 +1,300 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { classifyUnsafeDictionaryValue, classifyWideningTarget, createTypeEnvironment, isKnownEvidenceExpression, } from "../shared/dictionary-types.js";
3
+ import { containsUnknownType, functionParameterBindingName, functionParameterTypeAnnotation, } from "../shared/function-parameters.js";
4
+ import { resolveVariable } from "../shared/scope.js";
5
+ function unwrapExpression(expression) {
6
+ let current = expression;
7
+ while (current.type === "ParenthesizedExpression" ||
8
+ current.type === "TSAsExpression" ||
9
+ current.type === "TSSatisfiesExpression" ||
10
+ current.type === "TSTypeAssertion" ||
11
+ current.type === "TSNonNullExpression") {
12
+ current = current.expression;
13
+ }
14
+ return current;
15
+ }
16
+ function variableDeclarator(variable) {
17
+ if (variable.defs.length !== 1)
18
+ return null;
19
+ const [definition] = variable.defs;
20
+ return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
21
+ ? definition.node
22
+ : null;
23
+ }
24
+ function isStableConstVariable(variable, declarator) {
25
+ return (declarator.parent.type === "VariableDeclaration" &&
26
+ declarator.parent.kind === "const" &&
27
+ variable.references.every((reference) => reference.init || !reference.isWrite()));
28
+ }
29
+ function hasKnownEvidence(sourceCode, expression, visitedVariables = new Set()) {
30
+ if (isKnownEvidenceExpression(expression))
31
+ return true;
32
+ const unwrapped = unwrapExpression(expression);
33
+ if (unwrapped.type !== "Identifier")
34
+ return false;
35
+ const variable = resolveVariable(sourceCode, unwrapped);
36
+ if (variable === null || visitedVariables.has(variable))
37
+ return false;
38
+ const declarator = variableDeclarator(variable);
39
+ if (declarator === null ||
40
+ declarator.init === null ||
41
+ !isStableConstVariable(variable, declarator)) {
42
+ return false;
43
+ }
44
+ visitedVariables.add(variable);
45
+ return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
46
+ }
47
+ function isFunctionExpression(node) {
48
+ return (node.type === "ArrowFunctionExpression" ||
49
+ node.type === "FunctionDeclaration" ||
50
+ node.type === "FunctionExpression" ||
51
+ node.type === "TSDeclareFunction" ||
52
+ node.type === "TSEmptyBodyFunctionExpression");
53
+ }
54
+ function localFunctionForCall(sourceCode, callee) {
55
+ const unwrapped = unwrapExpression(callee);
56
+ if (isFunctionExpression(unwrapped))
57
+ return unwrapped;
58
+ if (unwrapped.type !== "Identifier")
59
+ return null;
60
+ const variable = resolveVariable(sourceCode, unwrapped);
61
+ if (variable === null || variable.defs.length !== 1)
62
+ return null;
63
+ const [definition] = variable.defs;
64
+ if (definition === undefined)
65
+ return null;
66
+ if (definition.type === "FunctionName" && isFunctionExpression(definition.node)) {
67
+ return definition.node;
68
+ }
69
+ if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator") {
70
+ return null;
71
+ }
72
+ const initializer = definition.node.init;
73
+ if (initializer === null)
74
+ return null;
75
+ const unwrappedInitializer = unwrapExpression(initializer);
76
+ return isFunctionExpression(unwrappedInitializer) ? unwrappedInitializer : null;
77
+ }
78
+ function variableTypeAnnotation(sourceCode, variable) {
79
+ if (variable.defs.length !== 1)
80
+ return null;
81
+ const [definition] = variable.defs;
82
+ if (definition === undefined)
83
+ return null;
84
+ if (definition.type === "Variable" &&
85
+ definition.node.type === "VariableDeclarator" &&
86
+ definition.node.id.type === "Identifier") {
87
+ return definition.node.id.typeAnnotation ?? null;
88
+ }
89
+ if (definition.type !== "Parameter" || !isFunctionExpression(definition.node)) {
90
+ return null;
91
+ }
92
+ const parameter = definition.node.params.find((candidate) => functionParameterBindingName(candidate, sourceCode) === variable.name);
93
+ return parameter === undefined ? null : (functionParameterTypeAnnotation(parameter) ?? null);
94
+ }
95
+ function hasInformativeType(type, environment) {
96
+ return classifyUnsafeDictionaryValue(type, environment) === null;
97
+ }
98
+ function hasKnownCallArgumentEvidence(sourceCode, expression, environment, visitedVariables = new Set()) {
99
+ if (expression.type === "ParenthesizedExpression" || expression.type === "TSNonNullExpression") {
100
+ return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
101
+ }
102
+ if (expression.type === "TSAsExpression" || expression.type === "TSTypeAssertion") {
103
+ return hasInformativeType(expression.typeAnnotation, environment);
104
+ }
105
+ if (expression.type === "TSSatisfiesExpression") {
106
+ return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
107
+ }
108
+ if (expression.type === "CallExpression") {
109
+ const owner = localFunctionForCall(sourceCode, expression.callee);
110
+ const returnType = owner?.returnType?.typeAnnotation;
111
+ return returnType !== undefined && hasInformativeType(returnType, environment);
112
+ }
113
+ if (expression.type !== "Identifier")
114
+ return isKnownEvidenceExpression(expression);
115
+ const variable = resolveVariable(sourceCode, expression);
116
+ if (variable === null || visitedVariables.has(variable))
117
+ return false;
118
+ const annotation = variableTypeAnnotation(sourceCode, variable);
119
+ if (annotation !== null) {
120
+ return hasInformativeType(annotation.typeAnnotation, environment);
121
+ }
122
+ const declarator = variableDeclarator(variable);
123
+ if (declarator === null ||
124
+ declarator.init === null ||
125
+ !isStableConstVariable(variable, declarator)) {
126
+ return false;
127
+ }
128
+ visitedVariables.add(variable);
129
+ return hasKnownCallArgumentEvidence(sourceCode, declarator.init, environment, visitedVariables);
130
+ }
131
+ function typePredicateSubjectIndex(sourceCode, owner) {
132
+ const predicate = owner.returnType?.typeAnnotation;
133
+ if (predicate?.type !== "TSTypePredicate" || predicate.parameterName.type !== "Identifier") {
134
+ return null;
135
+ }
136
+ const predicateParameterName = predicate.parameterName.name;
137
+ const index = owner.params.findIndex((parameter) => functionParameterBindingName(parameter, sourceCode) === predicateParameterName);
138
+ return index === -1 ? null : index;
139
+ }
140
+ function annotationTarget(annotation, environment) {
141
+ return annotation === null || annotation === undefined
142
+ ? null
143
+ : classifyWideningTarget(annotation.typeAnnotation, environment);
144
+ }
145
+ function enclosingFunction(node) {
146
+ let current = node.parent;
147
+ while (current !== null && current.type !== "Program") {
148
+ if (current.type === "ArrowFunctionExpression" ||
149
+ current.type === "FunctionDeclaration" ||
150
+ current.type === "FunctionExpression") {
151
+ return current;
152
+ }
153
+ current = current.parent;
154
+ }
155
+ return null;
156
+ }
157
+ function sourceKeyName(sourceCode, key) {
158
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier")
159
+ return key.name;
160
+ if (key.type === "Literal")
161
+ return String(key.value);
162
+ return sourceCode.getText(key);
163
+ }
164
+ function functionName(sourceCode, owner) {
165
+ if (owner === null)
166
+ return "anonymous function";
167
+ if (owner.id !== null)
168
+ return owner.id.name;
169
+ const parent = owner.parent;
170
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
171
+ return parent.id.name;
172
+ if (parent.type === "MethodDefinition")
173
+ return sourceKeyName(sourceCode, parent.key);
174
+ return "anonymous function";
175
+ }
176
+ function isEmptyObjectExpression(expression) {
177
+ const unwrapped = unwrapExpression(expression);
178
+ return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
179
+ }
180
+ function isDictionaryAccumulatorTarget(destination) {
181
+ return destination.kind === "open dictionary" || destination.kind === "generic container";
182
+ }
183
+ function hasParentAssertion(node) {
184
+ return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
185
+ }
186
+ /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
187
+ export const noKnownValueWideningRule = defineRule({
188
+ meta: {
189
+ type: "problem",
190
+ docs: {
191
+ description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
192
+ },
193
+ messages: {
194
+ widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
195
+ },
196
+ },
197
+ createOnce(context) {
198
+ let environment = null;
199
+ const reportFlow = (expression, destination, subject) => {
200
+ if (destination === null)
201
+ return;
202
+ if (isDictionaryAccumulatorTarget(destination) &&
203
+ isEmptyObjectExpression(expression)) {
204
+ return;
205
+ }
206
+ if (!hasKnownEvidence(context.sourceCode, expression))
207
+ return;
208
+ context.report({
209
+ node: expression,
210
+ messageId: "widening",
211
+ data: { subject, target: destination.kind },
212
+ });
213
+ };
214
+ const targetFromAnnotation = (annotation) => environment === null ? null : annotationTarget(annotation, environment);
215
+ return {
216
+ Program(node) {
217
+ environment = createTypeEnvironment(node, context.sourceCode.visitorKeys);
218
+ },
219
+ VariableDeclarator(node) {
220
+ if (node.init === null || node.id.type !== "Identifier")
221
+ return;
222
+ reportFlow(node.init, targetFromAnnotation(node.id.typeAnnotation), `binding \`${node.id.name}\``);
223
+ },
224
+ PropertyDefinition(node) {
225
+ if (node.value === null)
226
+ return;
227
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
228
+ },
229
+ AccessorProperty(node) {
230
+ if (node.value === null)
231
+ return;
232
+ reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
233
+ },
234
+ AssignmentExpression(node) {
235
+ if (node.operator !== "=" || node.left.type !== "Identifier")
236
+ return;
237
+ const variable = resolveVariable(context.sourceCode, node.left);
238
+ if (variable === null)
239
+ return;
240
+ const declarator = variableDeclarator(variable);
241
+ if (declarator === null || declarator.id.type !== "Identifier")
242
+ return;
243
+ reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
244
+ },
245
+ CallExpression(node) {
246
+ if (environment === null)
247
+ return;
248
+ const owner = localFunctionForCall(context.sourceCode, node.callee);
249
+ if (owner === null)
250
+ return;
251
+ const parameterIndex = typePredicateSubjectIndex(context.sourceCode, owner);
252
+ if (parameterIndex === null)
253
+ return;
254
+ const parameter = owner.params[parameterIndex];
255
+ const argument = node.arguments[parameterIndex];
256
+ if (parameter === undefined || argument === undefined || argument.type === "SpreadElement") {
257
+ return;
258
+ }
259
+ const parameterAnnotation = functionParameterTypeAnnotation(parameter);
260
+ if (parameterAnnotation === null ||
261
+ parameterAnnotation === undefined ||
262
+ !containsUnknownType(parameterAnnotation.typeAnnotation)) {
263
+ return;
264
+ }
265
+ if (!hasKnownCallArgumentEvidence(context.sourceCode, argument, environment)) {
266
+ return;
267
+ }
268
+ context.report({
269
+ node: argument,
270
+ messageId: "widening",
271
+ data: {
272
+ subject: `argument for parameter \`${functionParameterBindingName(parameter, context.sourceCode)}\` of \`${functionName(context.sourceCode, owner)}\``,
273
+ target: "unknown",
274
+ },
275
+ });
276
+ },
277
+ ReturnStatement(node) {
278
+ if (node.argument === null)
279
+ return;
280
+ const owner = enclosingFunction(node);
281
+ reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
282
+ },
283
+ ArrowFunctionExpression(node) {
284
+ if (node.body.type === "BlockStatement")
285
+ return;
286
+ reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
287
+ },
288
+ TSAsExpression(node) {
289
+ if (environment === null || hasParentAssertion(node))
290
+ return;
291
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
292
+ },
293
+ TSTypeAssertion(node) {
294
+ if (environment === null || hasParentAssertion(node))
295
+ return;
296
+ reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
297
+ },
298
+ };
299
+ },
300
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban test framework module mocking in favor of real dependency seams. */
2
+ export declare const noModuleMockingRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,69 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { resolveVariable } from "../shared/scope.js";
3
+ const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
4
+ function importedName(node) {
5
+ if (node.type !== "ImportSpecifier")
6
+ return null;
7
+ return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
8
+ }
9
+ function isTestFrameworkObject(sourceCode, expression) {
10
+ if (expression.type !== "Identifier")
11
+ return false;
12
+ if ((expression.name === "vi" || expression.name === "jest") &&
13
+ sourceCode.isGlobalReference(expression)) {
14
+ return true;
15
+ }
16
+ const variable = resolveVariable(sourceCode, expression);
17
+ if (variable === null || variable.defs.length === 0) {
18
+ return expression.name === "vi" || expression.name === "jest";
19
+ }
20
+ return variable.defs.some((definition) => {
21
+ if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
22
+ return false;
23
+ }
24
+ const source = definition.parent.source.value;
25
+ const name = importedName(definition.node);
26
+ return (source === "vitest" && name === "vi") || (source === "@jest/globals" && name === "jest");
27
+ });
28
+ }
29
+ function moduleMockCall(sourceCode, callee) {
30
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
31
+ return false;
32
+ if (!isTestFrameworkObject(sourceCode, callee.object))
33
+ return false;
34
+ const property = callee.property;
35
+ const method = callee.computed
36
+ ? property.type === "Literal" &&
37
+ (property.value === "doMock" ||
38
+ property.value === "mock" ||
39
+ property.value === "unstable_mockModule")
40
+ ? property.value
41
+ : null
42
+ : property.type === "Identifier"
43
+ ? property.name
44
+ : null;
45
+ return method !== null && moduleMockMethods.has(method);
46
+ }
47
+ /** Ban test framework module mocking in favor of real dependency seams. */
48
+ export const noModuleMockingRule = defineRule({
49
+ meta: {
50
+ type: "problem",
51
+ docs: {
52
+ description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
53
+ },
54
+ messages: {
55
+ moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
56
+ },
57
+ },
58
+ createOnce(context) {
59
+ return {
60
+ CallExpression(node) {
61
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
62
+ return;
63
+ if (moduleMockCall(context.sourceCode, node.callee)) {
64
+ context.report({ node, messageId: "moduleMock" });
65
+ }
66
+ },
67
+ };
68
+ },
69
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban the broad object type on function inputs, including local aliases to object. */
2
+ export declare const noObjectParametersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,56 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { functionParameterBindingName, functionParameterTypeAnnotation, } from "../shared/function-parameters.js";
3
+ import { createTypeAliasEnvironment, resolvedTypeMatches, } from "../shared/type-alias-resolution.js";
4
+ /** Ban the broad object type on function inputs, including local aliases to object. */
5
+ export const noObjectParametersRule = defineRule({
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary.",
10
+ },
11
+ messages: {
12
+ objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function.",
13
+ },
14
+ },
15
+ createOnce(context) {
16
+ let environment = null;
17
+ const resolvesToObject = (type) => environment !== null &&
18
+ resolvedTypeMatches(type, environment, (resolved, matches) => {
19
+ if (resolved.type === "TSObjectKeyword")
20
+ return true;
21
+ if (resolved.type === "TSParenthesizedType") {
22
+ return matches(resolved.typeAnnotation);
23
+ }
24
+ return (resolved.type === "TSUnionType" && resolved.types.some(matches));
25
+ });
26
+ const checkParameters = (node) => {
27
+ for (const parameter of node.params) {
28
+ const annotation = functionParameterTypeAnnotation(parameter);
29
+ if (annotation === null || annotation === undefined)
30
+ continue;
31
+ if (!resolvesToObject(annotation.typeAnnotation))
32
+ continue;
33
+ context.report({
34
+ node: annotation.typeAnnotation,
35
+ messageId: "objectParameter",
36
+ data: { parameter: functionParameterBindingName(parameter, context.sourceCode) },
37
+ });
38
+ }
39
+ };
40
+ return {
41
+ Program(node) {
42
+ environment = createTypeAliasEnvironment(node, context.sourceCode.visitorKeys);
43
+ },
44
+ ArrowFunctionExpression: checkParameters,
45
+ FunctionDeclaration: checkParameters,
46
+ FunctionExpression: checkParameters,
47
+ TSCallSignatureDeclaration: checkParameters,
48
+ TSConstructSignatureDeclaration: checkParameters,
49
+ TSConstructorType: checkParameters,
50
+ TSDeclareFunction: checkParameters,
51
+ TSEmptyBodyFunctionExpression: checkParameters,
52
+ TSFunctionType: checkParameters,
53
+ TSMethodSignature: checkParameters,
54
+ };
55
+ },
56
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow type aliases that only rename another type. */
2
+ export declare const noPassThroughTypeAliasRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,41 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ function isForwardedTypeParameter(typeArgument, typeParameter) {
3
+ return (typeArgument.type === "TSTypeReference" &&
4
+ typeArgument.typeName.type === "Identifier" &&
5
+ typeArgument.typeName.name === typeParameter.name.name &&
6
+ !typeArgument.typeArguments);
7
+ }
8
+ function passThroughTargetName(node) {
9
+ const annotation = node.typeAnnotation;
10
+ if (annotation.type !== "TSTypeReference" || annotation.typeName.type !== "Identifier") {
11
+ return null;
12
+ }
13
+ const typeParameters = node.typeParameters?.params ?? [];
14
+ const typeArguments = annotation.typeArguments?.params ?? [];
15
+ const isPassThrough = typeParameters.length === typeArguments.length &&
16
+ typeParameters.every((typeParameter, index) => isForwardedTypeParameter(typeArguments[index], typeParameter));
17
+ return isPassThrough ? annotation.typeName.name : null;
18
+ }
19
+ /** Disallow type aliases that only rename another type. */
20
+ export const noPassThroughTypeAliasRule = defineRule({
21
+ meta: {
22
+ type: "suggestion",
23
+ docs: { description: "Disallow type aliases that only rename another type" },
24
+ messages: { passThroughAlias: "Use {{typeName}} directly instead of creating a pass-through type alias." },
25
+ schema: [],
26
+ },
27
+ createOnce(context) {
28
+ return {
29
+ TSTypeAliasDeclaration(node) {
30
+ const typeName = passThroughTargetName(node);
31
+ if (typeName !== null) {
32
+ context.report({
33
+ data: { typeName },
34
+ messageId: "passThroughAlias",
35
+ node,
36
+ });
37
+ }
38
+ },
39
+ };
40
+ },
41
+ });
@@ -0,0 +1,2 @@
1
+ /** Reject non-spread copies of reducer accumulators; pair with oxc/no-accumulating-spread. */
2
+ export declare const noReduceAccumulatorCopyRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,99 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { arrayMethodTarget, isKnownArrayExpression, resolveArrayBinding, unwrapArrayExpression, } from "../shared/array-method.js";
3
+ function enclosingReducer(node) {
4
+ let parent = node.parent;
5
+ while (parent !== null) {
6
+ if (parent.type === "FunctionDeclaration")
7
+ return null;
8
+ if (parent.type === "ArrowFunctionExpression" || parent.type === "FunctionExpression") {
9
+ const callback = parent;
10
+ let owner = callback.parent;
11
+ while (owner !== null && unwrapArrayExpression(owner) === callback)
12
+ owner = owner.parent;
13
+ if (owner?.type !== "CallExpression")
14
+ return null;
15
+ const method = arrayMethodTarget(owner.callee);
16
+ const firstArgument = owner.arguments[0];
17
+ if (method === null || (method.name !== "reduce" && method.name !== "reduceRight") ||
18
+ owner.arguments.length > 2 || firstArgument === undefined ||
19
+ unwrapArrayExpression(firstArgument) !== callback)
20
+ return null;
21
+ const firstParameter = callback.params[0];
22
+ const accumulator = firstParameter?.type === "AssignmentPattern" ? firstParameter.left : firstParameter;
23
+ if (accumulator?.type !== "Identifier")
24
+ return null;
25
+ return { callback, accumulator, initialValue: owner.arguments[1] };
26
+ }
27
+ parent = parent.parent;
28
+ }
29
+ return null;
30
+ }
31
+ function referencesAccumulator(sourceCode, node, accumulator, visited = new Set()) {
32
+ const variable = resolveArrayBinding(sourceCode, node);
33
+ if (variable === null || visited.has(variable))
34
+ return false;
35
+ if (variable === accumulator)
36
+ return true;
37
+ visited.add(variable);
38
+ if (variable.references.some(reference => reference.isWrite() && !reference.init))
39
+ return false;
40
+ for (const definition of variable.defs) {
41
+ if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" &&
42
+ definition.node.id.type === "Identifier" && definition.node.init !== null &&
43
+ definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") {
44
+ return referencesAccumulator(sourceCode, definition.node.init, accumulator, visited);
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ function isGlobalCopyOwner(sourceCode, node, name) {
50
+ node = unwrapArrayExpression(node);
51
+ if (node.type !== "Identifier" || node.name !== name)
52
+ return false;
53
+ const variable = resolveArrayBinding(sourceCode, node);
54
+ return variable === null || variable.defs.length === 0;
55
+ }
56
+ /** Reject non-spread copies of reducer accumulators; pair with oxc/no-accumulating-spread. */
57
+ export const noReduceAccumulatorCopyRule = defineRule({
58
+ meta: {
59
+ type: "problem",
60
+ docs: { description: "Disallow copying growing reducer accumulators with Object.assign, Array.from, or array copy methods." },
61
+ messages: {
62
+ 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.",
63
+ },
64
+ },
65
+ createOnce(context) {
66
+ return {
67
+ CallExpression(node) {
68
+ const method = arrayMethodTarget(node.callee);
69
+ if (method === null)
70
+ return;
71
+ const reducer = enclosingReducer(node);
72
+ if (reducer === null)
73
+ return;
74
+ const accumulator = context.sourceCode.getDeclaredVariables(reducer.callback).find(variable => variable.identifiers.some(identifier => identifier.start === reducer.accumulator.start));
75
+ if (accumulator === undefined)
76
+ return;
77
+ const isAccumulator = (expression) => referencesAccumulator(context.sourceCode, expression, accumulator);
78
+ let copiesAccumulator = false;
79
+ if (method.name === "assign" && isGlobalCopyOwner(context.sourceCode, method.object, "Object")) {
80
+ const target = node.arguments[0];
81
+ copiesAccumulator = (target !== undefined && unwrapArrayExpression(target).type === "ObjectExpression" &&
82
+ node.arguments.slice(1).some(isAccumulator));
83
+ }
84
+ else if (method.name === "from" && isGlobalCopyOwner(context.sourceCode, method.object, "Array")) {
85
+ const source = node.arguments[0];
86
+ copiesAccumulator = source !== undefined && isAccumulator(source);
87
+ }
88
+ else if (["concat", "slice", "toSpliced", "toSorted", "toReversed", "with"].includes(method.name)) {
89
+ const initialValue = reducer.initialValue;
90
+ const arrayAccumulator = initialValue !== undefined &&
91
+ isKnownArrayExpression(context.sourceCode, initialValue);
92
+ copiesAccumulator = arrayAccumulator && isAccumulator(method.object);
93
+ }
94
+ if (copiesAccumulator)
95
+ context.report({ node, messageId: "accumulatorCopy" });
96
+ },
97
+ };
98
+ },
99
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban Reflect.apply, which bypasses ordinary typed function calls. */
2
+ export declare const noReflectApplyRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,25 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
3
+ /** Ban Reflect.apply, which bypasses ordinary typed function calls. */
4
+ export const noReflectApplyRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface.",
9
+ },
10
+ messages: {
11
+ reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ return {
16
+ CallExpression(node) {
17
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
18
+ return;
19
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "apply")) {
20
+ context.report({ node, messageId: "reflectApply" });
21
+ }
22
+ },
23
+ };
24
+ },
25
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
2
+ export declare const noReflectGetRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,25 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
3
+ /** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
4
+ export const noReflectGetRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type.",
9
+ },
10
+ messages: {
11
+ reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ return {
16
+ CallExpression(node) {
17
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
18
+ return;
19
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "get")) {
20
+ context.report({ node, messageId: "reflectGet" });
21
+ }
22
+ },
23
+ };
24
+ },
25
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
2
+ export declare const noRuntimeTypeofRule: import("@oxlint/plugins").Rule;