@danieljvdm/dev-kit 0.16.0 → 0.18.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 +18 -7
  2. package/package.json +20 -9
  3. package/scripts/sync-anti-slop-runtime.mjs +19 -0
  4. package/skill-sources.jsonc +17 -0
  5. package/skill-sources.lock.json +48 -0
  6. package/skills/dev-kit/SKILL.md +4 -5
  7. package/src/bin/dev-kit.ts +11 -7
  8. package/src/catalog-manager.ts +23 -18
  9. package/src/catalog.ts +8 -5
  10. package/src/cli-ui.ts +2 -2
  11. package/src/effect-tsgo.ts +10 -6
  12. package/src/gitignore.ts +6 -3
  13. package/src/manifest.ts +10 -2
  14. package/src/oxlint-plugin-anti-slop/LICENSE +21 -0
  15. package/src/oxlint-plugin-anti-slop/index.ts +43 -0
  16. package/src/oxlint-plugin-anti-slop/rules/no-chained-type-assertions.ts +79 -0
  17. package/src/oxlint-plugin-anti-slop/rules/no-conditional-empty-object-spread.ts +51 -0
  18. package/src/oxlint-plugin-anti-slop/rules/no-known-value-widening.ts +267 -0
  19. package/src/oxlint-plugin-anti-slop/rules/no-module-mocking.ts +105 -0
  20. package/src/oxlint-plugin-anti-slop/rules/no-object-parameters.ts +141 -0
  21. package/src/oxlint-plugin-anti-slop/rules/no-reflect-apply.ts +28 -0
  22. package/src/oxlint-plugin-anti-slop/rules/no-reflect-get.ts +28 -0
  23. package/src/oxlint-plugin-anti-slop/rules/no-runtime-typeof.ts +25 -0
  24. package/src/oxlint-plugin-anti-slop/rules/no-shape-in-symbol-names.ts +38 -0
  25. package/src/oxlint-plugin-anti-slop/rules/no-unknown-parameters.ts +86 -0
  26. package/src/oxlint-plugin-anti-slop/rules/no-unknown-returns.ts +125 -0
  27. package/src/oxlint-plugin-anti-slop/rules/no-unknown-type-aliases.ts +73 -0
  28. package/src/oxlint-plugin-anti-slop/rules/no-unsafe-dictionary-type.ts +139 -0
  29. package/src/oxlint-plugin-anti-slop/rules/no-widen-then-assert.ts +396 -0
  30. package/src/oxlint-plugin-anti-slop/rules/require-safety-comment-for-type-assertion.ts +61 -0
  31. package/src/oxlint-plugin-anti-slop/runtime.d.ts +22 -0
  32. package/src/oxlint-plugin-anti-slop/runtime.js +1209 -0
  33. package/src/oxlint-plugin-anti-slop/shared/dictionary-types.ts +555 -0
  34. package/src/oxlint-plugin-anti-slop/shared/reflect-method.ts +40 -0
  35. package/src/oxlint-plugin-effect.d.ts +4 -2
  36. package/src/oxlint.js +19 -0
  37. package/src/oxlint.ts +22 -5
  38. package/src/package-skill-source.ts +17 -25
  39. package/src/path-digest.ts +2 -1
  40. package/src/project-package.ts +14 -12
  41. package/src/skill-manager.ts +25 -13
  42. package/src/sync.ts +65 -49
  43. package/src/vendor.ts +35 -16
@@ -0,0 +1,51 @@
1
+ import { defineRule, type ESTree } from "@oxlint/plugins";
2
+
3
+ function unwrapParentheses(node: ESTree.Expression): ESTree.Expression {
4
+ let current = node;
5
+
6
+ while (current.type === "ParenthesizedExpression") {
7
+ current = current.expression;
8
+ }
9
+
10
+ return current;
11
+ }
12
+
13
+ function isEmptyObjectExpression(node: ESTree.Expression): boolean {
14
+ return node.type === "ObjectExpression" && node.properties.length === 0;
15
+ }
16
+
17
+ function isConditionalEmptyObjectSpread(node: ESTree.Expression): boolean {
18
+ const conditional = unwrapParentheses(node);
19
+
20
+ return (
21
+ conditional.type === "ConditionalExpression" &&
22
+ (isEmptyObjectExpression(conditional.consequent) ||
23
+ isEmptyObjectExpression(conditional.alternate))
24
+ );
25
+ }
26
+
27
+ /** Ban conditional empty-object spreads without changing their omission semantics. */
28
+ export const noConditionalEmptyObjectSpreadRule = defineRule({
29
+ meta: {
30
+ type: "suggestion",
31
+ docs: {
32
+ description:
33
+ "Disallow object spreads that conditionally spread an empty object to omit fields.",
34
+ },
35
+ messages: {
36
+ avoid:
37
+ "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
38
+ },
39
+ },
40
+ create(context) {
41
+ return {
42
+ SpreadElement(node) {
43
+ if (node.parent.type !== "ObjectExpression") return;
44
+
45
+ if (isConditionalEmptyObjectSpread(node.argument)) {
46
+ context.report({ node, messageId: "avoid" });
47
+ }
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,267 @@
1
+ import {
2
+ defineRule,
3
+ type ESTree,
4
+ type Scope,
5
+ type SourceCode,
6
+ type Variable,
7
+ } from "@oxlint/plugins";
8
+
9
+ import {
10
+ classifyWideningTarget,
11
+ createTypeEnvironment,
12
+ isKnownEvidenceExpression,
13
+ type TypeEnvironment,
14
+ type WideningTarget,
15
+ } from "../shared/dictionary-types.ts";
16
+
17
+ type FunctionExpression = ESTree.ArrowFunctionExpression | ESTree.Function;
18
+
19
+ function unwrapExpression(expression: ESTree.Expression): ESTree.Expression {
20
+ let current = expression;
21
+
22
+ while (
23
+ current.type === "ParenthesizedExpression" ||
24
+ current.type === "TSAsExpression" ||
25
+ current.type === "TSSatisfiesExpression" ||
26
+ current.type === "TSTypeAssertion" ||
27
+ current.type === "TSNonNullExpression"
28
+ ) {
29
+ current = current.expression;
30
+ }
31
+
32
+ return current;
33
+ }
34
+
35
+ function resolveVariable(
36
+ sourceCode: SourceCode,
37
+ identifier: ESTree.IdentifierReference,
38
+ ): Variable | null {
39
+ let scope: Scope | null = sourceCode.getScope(identifier);
40
+
41
+ while (scope !== null) {
42
+ const variable = scope.set.get(identifier.name);
43
+
44
+ if (variable !== undefined) return variable;
45
+ scope = scope.upper;
46
+ }
47
+
48
+ return null;
49
+ }
50
+
51
+ function variableDeclarator(variable: Variable): ESTree.VariableDeclarator | null {
52
+ if (variable.defs.length !== 1) return null;
53
+ const [definition] = variable.defs;
54
+
55
+ return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
56
+ ? definition.node
57
+ : null;
58
+ }
59
+
60
+ function isStableConstVariable(variable: Variable, declarator: ESTree.VariableDeclarator): boolean {
61
+ return (
62
+ declarator.parent.type === "VariableDeclaration" &&
63
+ declarator.parent.kind === "const" &&
64
+ variable.references.every((reference) => reference.init || !reference.isWrite())
65
+ );
66
+ }
67
+
68
+ function hasKnownEvidence(
69
+ sourceCode: SourceCode,
70
+ expression: ESTree.Expression,
71
+ visitedVariables = new Set<Variable>(),
72
+ ): boolean {
73
+ if (isKnownEvidenceExpression(expression)) return true;
74
+ const unwrapped = unwrapExpression(expression);
75
+
76
+ if (unwrapped.type !== "Identifier") return false;
77
+ const variable = resolveVariable(sourceCode, unwrapped);
78
+
79
+ if (variable === null || visitedVariables.has(variable)) return false;
80
+ const declarator = variableDeclarator(variable);
81
+
82
+ if (
83
+ declarator === null ||
84
+ declarator.init === null ||
85
+ !isStableConstVariable(variable, declarator)
86
+ ) {
87
+ return false;
88
+ }
89
+ visitedVariables.add(variable);
90
+
91
+ return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
92
+ }
93
+
94
+ function annotationTarget(
95
+ annotation: ESTree.TSTypeAnnotation | null | undefined,
96
+ environment: TypeEnvironment,
97
+ ): WideningTarget | null {
98
+ return annotation === null || annotation === undefined
99
+ ? null
100
+ : classifyWideningTarget(annotation.typeAnnotation, environment);
101
+ }
102
+
103
+ function enclosingFunction(node: ESTree.Node): FunctionExpression | null {
104
+ let current: ESTree.Node | null = node.parent;
105
+
106
+ while (current !== null && current.type !== "Program") {
107
+ if (
108
+ current.type === "ArrowFunctionExpression" ||
109
+ current.type === "FunctionDeclaration" ||
110
+ current.type === "FunctionExpression"
111
+ ) {
112
+ return current;
113
+ }
114
+ current = current.parent;
115
+ }
116
+
117
+ return null;
118
+ }
119
+
120
+ function sourceKeyName(sourceCode: SourceCode, key: ESTree.PropertyKey): string {
121
+ if (key.type === "Identifier" || key.type === "PrivateIdentifier") return key.name;
122
+ if (key.type === "Literal") return String(key.value);
123
+
124
+ return sourceCode.getText(key);
125
+ }
126
+
127
+ function functionName(sourceCode: SourceCode, owner: FunctionExpression | null): string {
128
+ if (owner === null) return "anonymous function";
129
+ if (owner.id !== null) return owner.id.name;
130
+ const parent = owner.parent;
131
+
132
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
133
+ return parent.id.name;
134
+ if (parent.type === "MethodDefinition") return sourceKeyName(sourceCode, parent.key);
135
+
136
+ return "anonymous function";
137
+ }
138
+
139
+ function isEmptyObjectExpression(expression: ESTree.Expression): boolean {
140
+ const unwrapped = unwrapExpression(expression);
141
+
142
+ return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
143
+ }
144
+
145
+ function isDictionaryAccumulatorTarget(destination: WideningTarget): boolean {
146
+ return destination.kind === "open dictionary" || destination.kind === "generic container";
147
+ }
148
+
149
+ function hasParentAssertion(node: ESTree.Node): boolean {
150
+ return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
151
+ }
152
+
153
+ /** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
154
+ export const noKnownValueWideningRule = defineRule({
155
+ meta: {
156
+ type: "problem",
157
+ docs: {
158
+ description:
159
+ "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
160
+ },
161
+ messages: {
162
+ widening:
163
+ "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
164
+ },
165
+ },
166
+ createOnce(context) {
167
+ let environment: TypeEnvironment | null = null;
168
+
169
+ const reportFlow = (
170
+ expression: ESTree.Expression,
171
+ destination: WideningTarget | null,
172
+ subject: string,
173
+ ) => {
174
+ if (destination === null) return;
175
+ if (isDictionaryAccumulatorTarget(destination) && isEmptyObjectExpression(expression)) {
176
+ return;
177
+ }
178
+ if (!hasKnownEvidence(context.sourceCode, expression)) return;
179
+ context.report({
180
+ node: expression,
181
+ messageId: "widening",
182
+ data: { subject, target: destination.kind },
183
+ });
184
+ };
185
+
186
+ const targetFromAnnotation = (annotation: ESTree.TSTypeAnnotation | null | undefined) =>
187
+ environment === null ? null : annotationTarget(annotation, environment);
188
+
189
+ return {
190
+ Program(node) {
191
+ environment = createTypeEnvironment(node);
192
+ },
193
+ VariableDeclarator(node) {
194
+ if (node.init === null || node.id.type !== "Identifier") return;
195
+ reportFlow(
196
+ node.init,
197
+ targetFromAnnotation(node.id.typeAnnotation),
198
+ `binding \`${node.id.name}\``,
199
+ );
200
+ },
201
+ PropertyDefinition(node) {
202
+ if (node.value === null) return;
203
+ reportFlow(
204
+ node.value,
205
+ targetFromAnnotation(node.typeAnnotation),
206
+ `property \`${sourceKeyName(context.sourceCode, node.key)}\``,
207
+ );
208
+ },
209
+ AccessorProperty(node) {
210
+ if (node.value === null) return;
211
+ reportFlow(
212
+ node.value,
213
+ targetFromAnnotation(node.typeAnnotation),
214
+ `property \`${sourceKeyName(context.sourceCode, node.key)}\``,
215
+ );
216
+ },
217
+ AssignmentExpression(node) {
218
+ if (node.operator !== "=" || node.left.type !== "Identifier") return;
219
+ const variable = resolveVariable(context.sourceCode, node.left);
220
+
221
+ if (variable === null) return;
222
+ const declarator = variableDeclarator(variable);
223
+
224
+ if (declarator === null || declarator.id.type !== "Identifier") return;
225
+ reportFlow(
226
+ node.right,
227
+ targetFromAnnotation(declarator.id.typeAnnotation),
228
+ `binding \`${declarator.id.name}\``,
229
+ );
230
+ },
231
+ ReturnStatement(node) {
232
+ if (node.argument === null) return;
233
+ const owner = enclosingFunction(node);
234
+
235
+ reportFlow(
236
+ node.argument,
237
+ targetFromAnnotation(owner?.returnType),
238
+ `return value of \`${functionName(context.sourceCode, owner)}\``,
239
+ );
240
+ },
241
+ ArrowFunctionExpression(node) {
242
+ if (node.body.type === "BlockStatement") return;
243
+ reportFlow(
244
+ node.body,
245
+ targetFromAnnotation(node.returnType),
246
+ `return value of \`${functionName(context.sourceCode, node)}\``,
247
+ );
248
+ },
249
+ TSAsExpression(node) {
250
+ if (environment === null || hasParentAssertion(node)) return;
251
+ reportFlow(
252
+ node.expression,
253
+ classifyWideningTarget(node.typeAnnotation, environment),
254
+ "assertion",
255
+ );
256
+ },
257
+ TSTypeAssertion(node) {
258
+ if (environment === null || hasParentAssertion(node)) return;
259
+ reportFlow(
260
+ node.expression,
261
+ classifyWideningTarget(node.typeAnnotation, environment),
262
+ "assertion",
263
+ );
264
+ },
265
+ };
266
+ },
267
+ });
@@ -0,0 +1,105 @@
1
+ import {
2
+ defineRule,
3
+ type ESTree,
4
+ type Scope,
5
+ type SourceCode,
6
+ type Variable,
7
+ } from "@oxlint/plugins";
8
+
9
+ const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
10
+
11
+ function resolveVariable(
12
+ sourceCode: SourceCode,
13
+ identifier: ESTree.IdentifierReference,
14
+ ): Variable | null {
15
+ let scope: Scope | null = sourceCode.getScope(identifier);
16
+
17
+ while (scope !== null) {
18
+ const variable = scope.set.get(identifier.name);
19
+
20
+ if (variable !== undefined) return variable;
21
+ scope = scope.upper;
22
+ }
23
+
24
+ return null;
25
+ }
26
+
27
+ function importedName(node: ESTree.Node): string | null {
28
+ if (node.type !== "ImportSpecifier") return null;
29
+
30
+ return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
31
+ }
32
+
33
+ function isTestFrameworkObject(
34
+ sourceCode: SourceCode,
35
+ expression: ESTree.Expression,
36
+ ): expression is ESTree.IdentifierReference {
37
+ if (expression.type !== "Identifier") return false;
38
+ if (
39
+ (expression.name === "vi" || expression.name === "jest") &&
40
+ sourceCode.isGlobalReference(expression)
41
+ ) {
42
+ return true;
43
+ }
44
+
45
+ const variable = resolveVariable(sourceCode, expression);
46
+
47
+ if (variable === null || variable.defs.length === 0) {
48
+ return expression.name === "vi" || expression.name === "jest";
49
+ }
50
+
51
+ return variable.defs.some((definition) => {
52
+ if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
53
+ return false;
54
+ }
55
+ const source = definition.parent.source.value;
56
+ const name = importedName(definition.node);
57
+
58
+ return (
59
+ (source === "vitest" && name === "vi") || (source === "@jest/globals" && name === "jest")
60
+ );
61
+ });
62
+ }
63
+
64
+ function moduleMockCall(sourceCode: SourceCode, callee: ESTree.Expression): boolean {
65
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
66
+ if (!isTestFrameworkObject(sourceCode, callee.object)) return false;
67
+ const property = callee.property;
68
+ const method = callee.computed
69
+ ? property.type === "Literal" &&
70
+ (property.value === "doMock" ||
71
+ property.value === "mock" ||
72
+ property.value === "unstable_mockModule")
73
+ ? property.value
74
+ : null
75
+ : property.type === "Identifier"
76
+ ? property.name
77
+ : null;
78
+
79
+ return method !== null && moduleMockMethods.has(method);
80
+ }
81
+
82
+ /** Ban test framework module mocking in favor of real dependency seams. */
83
+ export const noModuleMockingRule = defineRule({
84
+ meta: {
85
+ type: "problem",
86
+ docs: {
87
+ description:
88
+ "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
89
+ },
90
+ messages: {
91
+ moduleMock:
92
+ "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
93
+ },
94
+ },
95
+ create(context) {
96
+ return {
97
+ CallExpression(node) {
98
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
99
+ if (moduleMockCall(context.sourceCode, node.callee)) {
100
+ context.report({ node, messageId: "moduleMock" });
101
+ }
102
+ },
103
+ };
104
+ },
105
+ });
@@ -0,0 +1,141 @@
1
+ import { defineRule, type ESTree, type SourceCode } from "@oxlint/plugins";
2
+
3
+ type Parameter = ESTree.ParamPattern;
4
+ type ParameterOwner =
5
+ | ESTree.ArrowFunctionExpression
6
+ | ESTree.Function
7
+ | ESTree.TSCallSignatureDeclaration
8
+ | ESTree.TSConstructSignatureDeclaration
9
+ | ESTree.TSConstructorType
10
+ | ESTree.TSFunctionType
11
+ | ESTree.TSMethodSignature;
12
+
13
+ function parameterAnnotation(parameter: Parameter): ESTree.TSTypeAnnotation | null | undefined {
14
+ if (parameter.type === "TSParameterProperty") {
15
+ return parameterAnnotation(parameter.parameter);
16
+ }
17
+ if (parameter.type === "RestElement") {
18
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
19
+ }
20
+ if (parameter.type === "AssignmentPattern") {
21
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
22
+ }
23
+
24
+ return parameter.typeAnnotation;
25
+ }
26
+
27
+ function parameterName(parameter: Parameter, sourceCode: SourceCode): string {
28
+ return parameter.type === "Identifier"
29
+ ? parameter.name
30
+ : sourceCode.getText(parameter).replace(/\s*:\s*object\s*$/u, "");
31
+ }
32
+
33
+ function lexicalTypeParameterNames(node: ESTree.Node): ReadonlySet<string> {
34
+ const names = new Set<string>();
35
+ let current: ESTree.Node | null = node;
36
+
37
+ while (current !== null && current.type !== "Program") {
38
+ if ("typeParameters" in current) {
39
+ for (const parameter of current.typeParameters?.params ?? []) {
40
+ names.add(parameter.name.name);
41
+ }
42
+ }
43
+ if (current.type === "TSMappedType") names.add(current.key.name);
44
+ if (current.type === "TSInferType") names.add(current.typeParameter.name.name);
45
+ current = current.parent;
46
+ }
47
+
48
+ return names;
49
+ }
50
+
51
+ /** Ban the broad object type on function inputs, including local aliases to object. */
52
+ export const noObjectParametersRule = defineRule({
53
+ meta: {
54
+ type: "problem",
55
+ docs: {
56
+ description:
57
+ "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary.",
58
+ },
59
+ messages: {
60
+ objectParameter:
61
+ "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function.",
62
+ },
63
+ },
64
+ create(context) {
65
+ const aliases = new Map<string, ESTree.TSType>();
66
+
67
+ const resolvesToObject = (
68
+ type: ESTree.TSType,
69
+ shadowedAliases: ReadonlySet<string>,
70
+ visited = new Set<string>(),
71
+ ): boolean => {
72
+ if (type.type === "TSObjectKeyword") return true;
73
+ if (type.type === "TSParenthesizedType")
74
+ return resolvesToObject(type.typeAnnotation, shadowedAliases, visited);
75
+ if (type.type === "TSUnionType") {
76
+ return type.types.some((member) => resolvesToObject(member, shadowedAliases, visited));
77
+ }
78
+ if (
79
+ type.type !== "TSTypeReference" ||
80
+ type.typeName.type !== "Identifier" ||
81
+ (type.typeArguments !== null &&
82
+ type.typeArguments !== undefined &&
83
+ type.typeArguments.params.length > 0) ||
84
+ visited.has(type.typeName.name) ||
85
+ shadowedAliases.has(type.typeName.name)
86
+ ) {
87
+ return false;
88
+ }
89
+ const alias = aliases.get(type.typeName.name);
90
+
91
+ if (alias === undefined) return false;
92
+ const nextVisited = new Set(visited);
93
+
94
+ nextVisited.add(type.typeName.name);
95
+
96
+ return resolvesToObject(alias, shadowedAliases, nextVisited);
97
+ };
98
+
99
+ const checkParameters = (node: ParameterOwner) => {
100
+ const shadowedAliases = lexicalTypeParameterNames(node);
101
+
102
+ for (const parameter of node.params) {
103
+ const annotation = parameterAnnotation(parameter);
104
+
105
+ if (annotation === null || annotation === undefined) continue;
106
+ if (!resolvesToObject(annotation.typeAnnotation, shadowedAliases)) continue;
107
+ context.report({
108
+ node: annotation.typeAnnotation,
109
+ messageId: "objectParameter",
110
+ data: { parameter: parameterName(parameter, context.sourceCode) },
111
+ });
112
+ }
113
+ };
114
+
115
+ return {
116
+ Program(node) {
117
+ for (const statement of node.body) {
118
+ const declaration =
119
+ statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
120
+
121
+ if (
122
+ declaration?.type === "TSTypeAliasDeclaration" &&
123
+ (declaration.typeParameters === null || declaration.typeParameters === undefined)
124
+ ) {
125
+ aliases.set(declaration.id.name, declaration.typeAnnotation);
126
+ }
127
+ }
128
+ },
129
+ ArrowFunctionExpression: checkParameters,
130
+ FunctionDeclaration: checkParameters,
131
+ FunctionExpression: checkParameters,
132
+ TSCallSignatureDeclaration: checkParameters,
133
+ TSConstructSignatureDeclaration: checkParameters,
134
+ TSConstructorType: checkParameters,
135
+ TSDeclareFunction: checkParameters,
136
+ TSEmptyBodyFunctionExpression: checkParameters,
137
+ TSFunctionType: checkParameters,
138
+ TSMethodSignature: checkParameters,
139
+ };
140
+ },
141
+ });
@@ -0,0 +1,28 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.ts";
4
+
5
+ /** Ban Reflect.apply, which bypasses ordinary typed function calls. */
6
+ export const noReflectApplyRule = defineRule({
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description:
11
+ "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface.",
12
+ },
13
+ messages: {
14
+ reflectApply:
15
+ "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface.",
16
+ },
17
+ },
18
+ create(context) {
19
+ return {
20
+ CallExpression(node) {
21
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
22
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "apply")) {
23
+ context.report({ node, messageId: "reflectApply" });
24
+ }
25
+ },
26
+ };
27
+ },
28
+ });
@@ -0,0 +1,28 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.ts";
4
+
5
+ /** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
6
+ export const noReflectGetRule = defineRule({
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description:
11
+ "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type.",
12
+ },
13
+ messages: {
14
+ reflectGet:
15
+ "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it.",
16
+ },
17
+ },
18
+ create(context) {
19
+ return {
20
+ CallExpression(node) {
21
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
22
+ if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "get")) {
23
+ context.report({ node, messageId: "reflectGet" });
24
+ }
25
+ },
26
+ };
27
+ },
28
+ });
@@ -0,0 +1,25 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
4
+ export const noRuntimeTypeofRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description:
9
+ "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary.",
10
+ },
11
+ messages: {
12
+ runtimeTypeof:
13
+ "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
14
+ },
15
+ },
16
+ create(context) {
17
+ return {
18
+ UnaryExpression(node) {
19
+ if (node.operator === "typeof") {
20
+ context.report({ node, messageId: "runtimeTypeof" });
21
+ }
22
+ },
23
+ };
24
+ },
25
+ });
@@ -0,0 +1,38 @@
1
+ import { defineRule, type ESTree } from "@oxlint/plugins";
2
+
3
+ const FORBIDDEN_SYMBOL_NAME = "shape";
4
+
5
+ function containsForbiddenSymbolName(name: string): boolean {
6
+ return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
7
+ }
8
+
9
+ /** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
10
+ export const noForbiddenTermInSymbolNamesRule = defineRule({
11
+ meta: {
12
+ type: "problem",
13
+ docs: {
14
+ description:
15
+ 'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.',
16
+ },
17
+ messages: {
18
+ forbiddenSymbolName:
19
+ 'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.',
20
+ },
21
+ },
22
+ create(context) {
23
+ const reportForbiddenSymbolName = (node: ESTree.Node & { name: string }) => {
24
+ if (!containsForbiddenSymbolName(node.name)) return;
25
+ context.report({
26
+ node,
27
+ messageId: "forbiddenSymbolName",
28
+ data: { name: node.name },
29
+ });
30
+ };
31
+
32
+ return {
33
+ Identifier: reportForbiddenSymbolName,
34
+ PrivateIdentifier: reportForbiddenSymbolName,
35
+ JSXIdentifier: reportForbiddenSymbolName,
36
+ };
37
+ },
38
+ });