@ref0/workspace 0.0.0-stage → 0.2.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.
- package/LICENSE +201 -0
- package/README.md +169 -2
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +113 -0
- package/dist/docs-budget.mjs +122 -0
- package/dist/lint/anti-slop/LICENSE +21 -0
- package/dist/lint/anti-slop/UPSTREAM.md +11 -0
- package/dist/lint/anti-slop/effect/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/effect/plugin.mjs +19 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-effect-error-tag.mjs +33 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tag-comparison.mjs +32 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tagged-construction.mjs +22 -0
- package/dist/lint/anti-slop/effect/rules/no-service-constructor-imports.mjs +36 -0
- package/dist/lint/anti-slop/effect/rules/prefer-effect-match.mjs +40 -0
- package/dist/lint/anti-slop/effect/shared/tagged-values.mjs +40 -0
- package/dist/lint/anti-slop/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/plugin.mjs +45 -0
- package/dist/lint/anti-slop/rules/no-array-filter-map.mjs +31 -0
- package/dist/lint/anti-slop/rules/no-chained-type-assertions.mjs +56 -0
- package/dist/lint/anti-slop/rules/no-conditional-empty-object-spread.mjs +32 -0
- package/dist/lint/anti-slop/rules/no-known-value-widening.mjs +236 -0
- package/dist/lint/anti-slop/rules/no-module-mocking.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-object-parameters.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-reduce-accumulator-copy.mjs +85 -0
- package/dist/lint/anti-slop/rules/no-reflect-apply.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-reflect-get.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-runtime-typeof.mjs +52 -0
- package/dist/lint/anti-slop/rules/no-shape-in-symbol-names.mjs +36 -0
- package/dist/lint/anti-slop/rules/no-unknown-parameters.mjs +44 -0
- package/dist/lint/anti-slop/rules/no-unknown-returns.mjs +47 -0
- package/dist/lint/anti-slop/rules/no-unknown-type-aliases.mjs +33 -0
- package/dist/lint/anti-slop/rules/no-unsafe-dictionary-type.mjs +121 -0
- package/dist/lint/anti-slop/rules/no-widen-then-assert.mjs +191 -0
- package/dist/lint/anti-slop/rules/require-readable-spacing.mjs +86 -0
- package/dist/lint/anti-slop/rules/require-safety-comment-for-type-assertion.mjs +82 -0
- package/dist/lint/anti-slop/shared/array-method.mjs +70 -0
- package/dist/lint/anti-slop/shared/child-nodes.mjs +24 -0
- package/dist/lint/anti-slop/shared/dictionary-types.mjs +248 -0
- package/dist/lint/anti-slop/shared/function-parameters.mjs +25 -0
- package/dist/lint/anti-slop/shared/lexical-type-parameters.mjs +21 -0
- package/dist/lint/anti-slop/shared/reflect-method.mjs +16 -0
- package/dist/lint/anti-slop/shared/scope.mjs +12 -0
- package/dist/lint/anti-slop/shared/string-literal.mjs +6 -0
- package/dist/lint/anti-slop/shared/type-alias-resolution.mjs +134 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +29 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-ast.mjs +32 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.mjs +608 -0
- package/dist/lint/config.d.mts +20 -0
- package/dist/lint/config.mjs +135 -0
- package/dist/lint/generic/effect-encoding.mjs +45 -0
- package/dist/lint/generic/entry-reexports.mjs +81 -0
- package/dist/lint/generic/env-at-entrypoints.mjs +65 -0
- package/dist/lint/generic/export-type-side-effects.mjs +22 -0
- package/dist/lint/generic/index-barrel.mjs +14 -0
- package/dist/lint/generic/log-messages.mjs +39 -0
- package/dist/lint/generic/plugin.d.mts +6 -0
- package/dist/lint/generic/plugin.mjs +26 -0
- package/dist/lint/generic/seeded-properties.mjs +78 -0
- package/dist/lint/plugins.d.mts +9 -0
- package/dist/lint/plugins.mjs +14 -0
- package/dist/lint/t3code/LICENSE +21 -0
- package/dist/lint/t3code/UPSTREAM.md +24 -0
- package/dist/lint/t3code/plugin.d.mts +2 -0
- package/dist/lint/t3code/plugin.mjs +20 -0
- package/dist/lint/t3code/rules/no-global-process-runtime.mjs +76 -0
- package/dist/lint/t3code/rules/no-inline-schema-compile.mjs +112 -0
- package/dist/lint/t3code/rules/no-manual-effect-runtime-in-tests.mjs +67 -0
- package/dist/lint/t3code/rules/no-native-title-tooltip.mjs +33 -0
- package/dist/lint/t3code/rules/no-test-in-loop.mjs +69 -0
- package/dist/lint/t3code/rules/no-unscoped-has.mjs +147 -0
- package/dist/lint/t3code/utils.mjs +21 -0
- package/dist/package-exports.mjs +157 -0
- package/dist/symbols/check.mjs +209 -0
- package/dist/symbols/find.mjs +63 -0
- package/dist/symbols/symbols.mjs +390 -0
- package/dist/type-coverage.mjs +68 -0
- package/dist/types/cache.mjs +157 -0
- package/dist/types/inputs.mjs +71 -0
- package/dist/types/projects.mjs +65 -0
- package/dist/types/types.mjs +175 -0
- package/package.json +68 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { resolveVariable } from "../shared/scope.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-module-mocking.ts
|
|
4
|
+
const moduleMockMethods = /* @__PURE__ */ new Set([
|
|
5
|
+
"doMock",
|
|
6
|
+
"mock",
|
|
7
|
+
"unstable_mockModule"
|
|
8
|
+
]);
|
|
9
|
+
function importedName(node) {
|
|
10
|
+
if (node.type !== "ImportSpecifier") return null;
|
|
11
|
+
return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
|
|
12
|
+
}
|
|
13
|
+
function isTestFrameworkObject(sourceCode, expression) {
|
|
14
|
+
if (expression.type !== "Identifier") return false;
|
|
15
|
+
if ((expression.name === "vi" || expression.name === "jest") && sourceCode.isGlobalReference(expression)) return true;
|
|
16
|
+
const variable = resolveVariable(sourceCode, expression);
|
|
17
|
+
if (variable === null || variable.defs.length === 0) return expression.name === "vi" || expression.name === "jest";
|
|
18
|
+
return variable.defs.some((definition) => {
|
|
19
|
+
if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") return false;
|
|
20
|
+
const source = definition.parent.source.value;
|
|
21
|
+
const name = importedName(definition.node);
|
|
22
|
+
return source === "vitest" && name === "vi" || source === "@jest/globals" && name === "jest";
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function moduleMockCall(sourceCode, callee) {
|
|
26
|
+
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
|
|
27
|
+
const property = callee.property;
|
|
28
|
+
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;
|
|
29
|
+
return method !== null && moduleMockMethods.has(method) && isTestFrameworkObject(sourceCode, callee.object);
|
|
30
|
+
}
|
|
31
|
+
/** Ban test framework module mocking in favor of real dependency seams. */
|
|
32
|
+
const noModuleMockingRule = defineRule({
|
|
33
|
+
meta: {
|
|
34
|
+
type: "problem",
|
|
35
|
+
docs: { description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces." },
|
|
36
|
+
messages: { moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation." }
|
|
37
|
+
},
|
|
38
|
+
createOnce(context) {
|
|
39
|
+
return { CallExpression(node) {
|
|
40
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
|
|
41
|
+
if (moduleMockCall(context.sourceCode, node.callee)) context.report({
|
|
42
|
+
node,
|
|
43
|
+
messageId: "moduleMock"
|
|
44
|
+
});
|
|
45
|
+
} };
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
export { noModuleMockingRule };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { functionParameterBindingName, functionParameterTypeAnnotation } from "../shared/function-parameters.mjs";
|
|
2
|
+
import { createTypeAliasEnvironment, resolvedTypeMatches } from "../shared/type-alias-resolution.mjs";
|
|
3
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
4
|
+
// src/lint/anti-slop/rules/no-object-parameters.ts
|
|
5
|
+
/** Ban the broad object type on function inputs, including local aliases to object. */
|
|
6
|
+
const noObjectParametersRule = defineRule({
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: { description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary." },
|
|
10
|
+
messages: { objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function." }
|
|
11
|
+
},
|
|
12
|
+
createOnce(context) {
|
|
13
|
+
let environment = null;
|
|
14
|
+
const resolvesToObject = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
|
|
15
|
+
if (resolved.type === "TSObjectKeyword") return true;
|
|
16
|
+
if (resolved.type === "TSParenthesizedType") return matches(resolved.typeAnnotation);
|
|
17
|
+
return resolved.type === "TSUnionType" && resolved.types.some(matches);
|
|
18
|
+
});
|
|
19
|
+
const checkParameters = (node) => {
|
|
20
|
+
for (const parameter of node.params) {
|
|
21
|
+
const annotation = functionParameterTypeAnnotation(parameter);
|
|
22
|
+
if (annotation === null || annotation === void 0) continue;
|
|
23
|
+
if (!resolvesToObject(annotation.typeAnnotation)) continue;
|
|
24
|
+
context.report({
|
|
25
|
+
node: annotation.typeAnnotation,
|
|
26
|
+
messageId: "objectParameter",
|
|
27
|
+
data: { parameter: functionParameterBindingName(parameter, context.sourceCode) }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
Program(node) {
|
|
33
|
+
environment = createTypeAliasEnvironment(node, context.sourceCode.visitorKeys);
|
|
34
|
+
},
|
|
35
|
+
ArrowFunctionExpression: checkParameters,
|
|
36
|
+
FunctionDeclaration: checkParameters,
|
|
37
|
+
FunctionExpression: checkParameters,
|
|
38
|
+
TSCallSignatureDeclaration: checkParameters,
|
|
39
|
+
TSConstructSignatureDeclaration: checkParameters,
|
|
40
|
+
TSConstructorType: checkParameters,
|
|
41
|
+
TSDeclareFunction: checkParameters,
|
|
42
|
+
TSEmptyBodyFunctionExpression: checkParameters,
|
|
43
|
+
TSFunctionType: checkParameters,
|
|
44
|
+
TSMethodSignature: checkParameters
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
export { noObjectParametersRule };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { arrayMethodTarget, isKnownArrayExpression, resolveArrayBinding, unwrapArrayExpression } from "../shared/array-method.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-reduce-accumulator-copy.ts
|
|
4
|
+
function enclosingReducer(node) {
|
|
5
|
+
let parent = node.parent;
|
|
6
|
+
while (parent !== null) {
|
|
7
|
+
if (parent.type === "FunctionDeclaration") 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) owner = owner.parent;
|
|
12
|
+
if (owner?.type !== "CallExpression") return null;
|
|
13
|
+
const method = arrayMethodTarget(owner.callee);
|
|
14
|
+
const firstArgument = owner.arguments[0];
|
|
15
|
+
if (method === null || method.name !== "reduce" && method.name !== "reduceRight" || owner.arguments.length > 2 || firstArgument === void 0 || unwrapArrayExpression(firstArgument) !== callback) return null;
|
|
16
|
+
const firstParameter = callback.params[0];
|
|
17
|
+
const accumulator = firstParameter?.type === "AssignmentPattern" ? firstParameter.left : firstParameter;
|
|
18
|
+
if (accumulator?.type !== "Identifier") return null;
|
|
19
|
+
return {
|
|
20
|
+
callback,
|
|
21
|
+
accumulator,
|
|
22
|
+
initialValue: owner.arguments[1]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
parent = parent.parent;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function referencesAccumulator(sourceCode, node, accumulator, visited = /* @__PURE__ */ new Set()) {
|
|
30
|
+
const variable = resolveArrayBinding(sourceCode, node);
|
|
31
|
+
if (variable === null || visited.has(variable)) return false;
|
|
32
|
+
if (variable === accumulator) return true;
|
|
33
|
+
visited.add(variable);
|
|
34
|
+
if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
35
|
+
for (const definition of variable.defs) 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") return referencesAccumulator(sourceCode, definition.node.init, accumulator, visited);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
function isGlobalCopyOwner(sourceCode, node, name) {
|
|
39
|
+
node = unwrapArrayExpression(node);
|
|
40
|
+
if (node.type !== "Identifier" || node.name !== name) return false;
|
|
41
|
+
const variable = resolveArrayBinding(sourceCode, node);
|
|
42
|
+
return variable === null || variable.defs.length === 0;
|
|
43
|
+
}
|
|
44
|
+
/** Reject non-spread copies of reducer accumulators; pair with oxc/no-accumulating-spread. */
|
|
45
|
+
const noReduceAccumulatorCopyRule = defineRule({
|
|
46
|
+
meta: {
|
|
47
|
+
type: "problem",
|
|
48
|
+
docs: { description: "Disallow copying growing reducer accumulators with Object.assign, Array.from, or array copy methods." },
|
|
49
|
+
messages: { 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." }
|
|
50
|
+
},
|
|
51
|
+
createOnce(context) {
|
|
52
|
+
return { CallExpression(node) {
|
|
53
|
+
const method = arrayMethodTarget(node.callee);
|
|
54
|
+
if (method === null) return;
|
|
55
|
+
const reducer = enclosingReducer(node);
|
|
56
|
+
if (reducer === null) return;
|
|
57
|
+
const accumulator = context.sourceCode.getDeclaredVariables(reducer.callback).find((variable) => variable.identifiers.some((identifier) => identifier.start === reducer.accumulator.start));
|
|
58
|
+
if (accumulator === void 0) return;
|
|
59
|
+
const isAccumulator = (expression) => referencesAccumulator(context.sourceCode, expression, accumulator);
|
|
60
|
+
let copiesAccumulator = false;
|
|
61
|
+
if (method.name === "assign" && isGlobalCopyOwner(context.sourceCode, method.object, "Object")) {
|
|
62
|
+
const target = node.arguments[0];
|
|
63
|
+
copiesAccumulator = target !== void 0 && unwrapArrayExpression(target).type === "ObjectExpression" && node.arguments.slice(1).some(isAccumulator);
|
|
64
|
+
} else if (method.name === "from" && isGlobalCopyOwner(context.sourceCode, method.object, "Array")) {
|
|
65
|
+
const source = node.arguments[0];
|
|
66
|
+
copiesAccumulator = source !== void 0 && isAccumulator(source);
|
|
67
|
+
} else if ([
|
|
68
|
+
"concat",
|
|
69
|
+
"slice",
|
|
70
|
+
"toSpliced",
|
|
71
|
+
"toSorted",
|
|
72
|
+
"toReversed",
|
|
73
|
+
"with"
|
|
74
|
+
].includes(method.name)) {
|
|
75
|
+
const initialValue = reducer.initialValue;
|
|
76
|
+
copiesAccumulator = initialValue !== void 0 && isKnownArrayExpression(context.sourceCode, initialValue) && isAccumulator(method.object);
|
|
77
|
+
}
|
|
78
|
+
if (copiesAccumulator) context.report({
|
|
79
|
+
node,
|
|
80
|
+
messageId: "accumulatorCopy"
|
|
81
|
+
});
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
export { noReduceAccumulatorCopyRule };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isGlobalReflectMethodCall } from "../shared/reflect-method.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-reflect-apply.ts
|
|
4
|
+
/** Ban Reflect.apply, which bypasses ordinary typed function calls. */
|
|
5
|
+
const noReflectApplyRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface." },
|
|
9
|
+
messages: { reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
return { CallExpression(node) {
|
|
13
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
|
|
14
|
+
if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "apply")) context.report({
|
|
15
|
+
node,
|
|
16
|
+
messageId: "reflectApply"
|
|
17
|
+
});
|
|
18
|
+
} };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export { noReflectApplyRule };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isGlobalReflectMethodCall } from "../shared/reflect-method.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-reflect-get.ts
|
|
4
|
+
/** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
|
|
5
|
+
const noReflectGetRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type." },
|
|
9
|
+
messages: { reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
return { CallExpression(node) {
|
|
13
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
|
|
14
|
+
if (isGlobalReflectMethodCall(context.sourceCode, node.callee, "get")) context.report({
|
|
15
|
+
node,
|
|
16
|
+
messageId: "reflectGet"
|
|
17
|
+
});
|
|
18
|
+
} };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export { noReflectGetRule };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
// src/lint/anti-slop/rules/no-runtime-typeof.ts
|
|
4
|
+
function isRuntimeFunction(node) {
|
|
5
|
+
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
|
6
|
+
}
|
|
7
|
+
function isInsideTypeGuard(node) {
|
|
8
|
+
let current = node.parent;
|
|
9
|
+
while (current !== null && current.type !== "Program") {
|
|
10
|
+
if (isRuntimeFunction(current)) return current.returnType?.typeAnnotation.type === "TSTypePredicate";
|
|
11
|
+
current = current.parent;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
/** Return whether typeof safely probes for the existence of a possibly absent binding. */
|
|
16
|
+
function isExistenceProbe(node) {
|
|
17
|
+
const parent = node.parent;
|
|
18
|
+
if (parent.type !== "BinaryExpression") return false;
|
|
19
|
+
if (![
|
|
20
|
+
"===",
|
|
21
|
+
"!==",
|
|
22
|
+
"==",
|
|
23
|
+
"!="
|
|
24
|
+
].includes(parent.operator)) return false;
|
|
25
|
+
const other = parent.left === node ? parent.right : parent.left;
|
|
26
|
+
return other.type === "Literal" && other.value === "undefined";
|
|
27
|
+
}
|
|
28
|
+
const allowsTypeGuards = Schema.is(Schema.Struct({ allowInTypeGuards: Schema.Literal(true) }));
|
|
29
|
+
/** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
|
|
30
|
+
const noRuntimeTypeofRule = defineRule({
|
|
31
|
+
meta: {
|
|
32
|
+
type: "problem",
|
|
33
|
+
docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary." },
|
|
34
|
+
messages: { runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value." },
|
|
35
|
+
schema: [{
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: { allowInTypeGuards: { type: "boolean" } },
|
|
38
|
+
additionalProperties: false
|
|
39
|
+
}],
|
|
40
|
+
defaultOptions: [{ allowInTypeGuards: false }]
|
|
41
|
+
},
|
|
42
|
+
createOnce(context) {
|
|
43
|
+
return { UnaryExpression(node) {
|
|
44
|
+
const allowInTypeGuards = allowsTypeGuards(context.options?.[0]);
|
|
45
|
+
if (node.operator === "typeof" && !isExistenceProbe(node) && (!allowInTypeGuards || !isInsideTypeGuard(node))) context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: "runtimeTypeof"
|
|
48
|
+
});
|
|
49
|
+
} };
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
export { noRuntimeTypeofRule };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/rules/no-shape-in-symbol-names.ts
|
|
3
|
+
const FORBIDDEN_SYMBOL_NAME = "shape";
|
|
4
|
+
function containsForbiddenSymbolName(name) {
|
|
5
|
+
return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
|
|
6
|
+
}
|
|
7
|
+
/** Return whether an identifier names a statically accessed member owned by another value. */
|
|
8
|
+
function isBorrowedMemberName(node) {
|
|
9
|
+
const parent = node.parent;
|
|
10
|
+
if (parent === null || parent.type !== "MemberExpression") return false;
|
|
11
|
+
return parent.property === node && parent.computed === false;
|
|
12
|
+
}
|
|
13
|
+
/** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
|
|
14
|
+
const noForbiddenTermInSymbolNamesRule = defineRule({
|
|
15
|
+
meta: {
|
|
16
|
+
type: "problem",
|
|
17
|
+
docs: { description: "Disallow the case-insensitive substring \"shape\" in JavaScript, TypeScript, private, and JSX symbol names." },
|
|
18
|
+
messages: { forbiddenSymbolName: "Rename symbol \"{{name}}\" for its domain role; \"shape\" describes structure rather than ownership." }
|
|
19
|
+
},
|
|
20
|
+
createOnce(context) {
|
|
21
|
+
const reportForbiddenSymbolName = (node) => {
|
|
22
|
+
if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
|
|
23
|
+
context.report({
|
|
24
|
+
node,
|
|
25
|
+
messageId: "forbiddenSymbolName",
|
|
26
|
+
data: { name: node.name }
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
Identifier: reportForbiddenSymbolName,
|
|
31
|
+
PrivateIdentifier: reportForbiddenSymbolName,
|
|
32
|
+
JSXIdentifier: reportForbiddenSymbolName
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export { noForbiddenTermInSymbolNamesRule };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { containsUnknownType, functionParameterBindingName, functionParameterTypeAnnotation } from "../shared/function-parameters.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-unknown-parameters.ts
|
|
4
|
+
function isTypePredicateSubject(owner, parameterName) {
|
|
5
|
+
const predicate = owner.returnType?.typeAnnotation;
|
|
6
|
+
return predicate?.type === "TSTypePredicate" && predicate.parameterName.type === "Identifier" && predicate.parameterName.name === parameterName;
|
|
7
|
+
}
|
|
8
|
+
/** Disallow unknown inputs except explicitly named error-cause enrichment. */
|
|
9
|
+
const noUnknownParametersRule = defineRule({
|
|
10
|
+
meta: {
|
|
11
|
+
type: "problem",
|
|
12
|
+
docs: { description: "Disallow explicitly unknown function parameters except `cause` and type-predicate subjects; decode unknown input at its I/O boundary instead." },
|
|
13
|
+
messages: { 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." }
|
|
14
|
+
},
|
|
15
|
+
createOnce(context) {
|
|
16
|
+
const checkParameters = (node) => {
|
|
17
|
+
for (const parameter of node.params) {
|
|
18
|
+
const annotation = functionParameterTypeAnnotation(parameter);
|
|
19
|
+
if (annotation === null || annotation === void 0) continue;
|
|
20
|
+
if (!containsUnknownType(annotation.typeAnnotation)) continue;
|
|
21
|
+
const name = functionParameterBindingName(parameter, context.sourceCode);
|
|
22
|
+
if (name === "cause" || isTypePredicateSubject(node, name)) continue;
|
|
23
|
+
context.report({
|
|
24
|
+
node: annotation.typeAnnotation,
|
|
25
|
+
messageId: "unknownParameter",
|
|
26
|
+
data: { parameter: name }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
ArrowFunctionExpression: checkParameters,
|
|
32
|
+
FunctionDeclaration: checkParameters,
|
|
33
|
+
FunctionExpression: checkParameters,
|
|
34
|
+
TSCallSignatureDeclaration: checkParameters,
|
|
35
|
+
TSConstructSignatureDeclaration: checkParameters,
|
|
36
|
+
TSConstructorType: checkParameters,
|
|
37
|
+
TSDeclareFunction: checkParameters,
|
|
38
|
+
TSEmptyBodyFunctionExpression: checkParameters,
|
|
39
|
+
TSFunctionType: checkParameters,
|
|
40
|
+
TSMethodSignature: checkParameters
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
export { noUnknownParametersRule };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createTypeAliasEnvironment, resolvedTypeMatches } from "../shared/type-alias-resolution.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-unknown-returns.ts
|
|
4
|
+
/** Ban function contracts that return unknown instead of a parsed domain type. */
|
|
5
|
+
const noUnknownReturnsRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Disallow functions whose explicit return contract is unknown or Promise<unknown>." },
|
|
9
|
+
messages: { unknownReturn: "This function exposes `unknown` to its caller. Parse the value at its boundary and return a named domain type." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
let environment = null;
|
|
13
|
+
const resolvesToUnknown = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
|
|
14
|
+
if (resolved.type === "TSUnknownKeyword") return true;
|
|
15
|
+
if (resolved.type === "TSParenthesizedType") return matches(resolved.typeAnnotation);
|
|
16
|
+
if (resolved.type === "TSUnionType") return resolved.types.some(matches);
|
|
17
|
+
if (resolved.type !== "TSTypeReference" || resolved.typeName.type !== "Identifier" || resolved.typeName.name !== "Promise" && resolved.typeName.name !== "PromiseLike") return false;
|
|
18
|
+
const value = resolved.typeArguments?.params[0];
|
|
19
|
+
return value !== void 0 && matches(value);
|
|
20
|
+
});
|
|
21
|
+
const checkReturnType = (node) => {
|
|
22
|
+
const annotation = node.returnType;
|
|
23
|
+
if (annotation === null || annotation === void 0) return;
|
|
24
|
+
if (!resolvesToUnknown(annotation.typeAnnotation)) return;
|
|
25
|
+
context.report({
|
|
26
|
+
node: annotation.typeAnnotation,
|
|
27
|
+
messageId: "unknownReturn"
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
Program(node) {
|
|
32
|
+
environment = createTypeAliasEnvironment(node, context.sourceCode.visitorKeys);
|
|
33
|
+
},
|
|
34
|
+
ArrowFunctionExpression: checkReturnType,
|
|
35
|
+
FunctionDeclaration: checkReturnType,
|
|
36
|
+
FunctionExpression: checkReturnType,
|
|
37
|
+
TSCallSignatureDeclaration: checkReturnType,
|
|
38
|
+
TSConstructSignatureDeclaration: checkReturnType,
|
|
39
|
+
TSConstructorType: checkReturnType,
|
|
40
|
+
TSDeclareFunction: checkReturnType,
|
|
41
|
+
TSEmptyBodyFunctionExpression: checkReturnType,
|
|
42
|
+
TSFunctionType: checkReturnType,
|
|
43
|
+
TSMethodSignature: checkReturnType
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
export { noUnknownReturnsRule };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createTypeAliasEnvironment, resolvedTypeMatches } from "../shared/type-alias-resolution.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-unknown-type-aliases.ts
|
|
4
|
+
/** Ban named aliases that merely conceal TypeScript's unknown top type. */
|
|
5
|
+
const noUnknownTypeAliasesRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Disallow type aliases whose resolved type is unknown; unknown must remain visible at an allowed boundary." },
|
|
9
|
+
messages: { 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." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
let environment = null;
|
|
13
|
+
const resolvesToUnknown = (type) => environment !== null && resolvedTypeMatches(type, environment, (resolved, matches) => {
|
|
14
|
+
if (resolved.type === "TSUnknownKeyword") return true;
|
|
15
|
+
if (resolved.type === "TSParenthesizedType") return matches(resolved.typeAnnotation);
|
|
16
|
+
return resolved.type === "TSUnionType" && resolved.types.some(matches);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
Program(node) {
|
|
20
|
+
environment = createTypeAliasEnvironment(node, context.sourceCode.visitorKeys);
|
|
21
|
+
},
|
|
22
|
+
TSTypeAliasDeclaration(node) {
|
|
23
|
+
if (!resolvesToUnknown(node.typeAnnotation)) return;
|
|
24
|
+
context.report({
|
|
25
|
+
node: node.id,
|
|
26
|
+
messageId: "unknownAlias",
|
|
27
|
+
data: { alias: node.id.name }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export { noUnknownTypeAliasesRule };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { classifyUnsafeDictionary, classifyUnsafeDictionaryValue, createTypeEnvironment } from "../shared/dictionary-types.mjs";
|
|
2
|
+
import { visibleTypeAlias } from "../shared/type-alias-resolution.mjs";
|
|
3
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
4
|
+
// src/lint/anti-slop/rules/no-unsafe-dictionary-type.ts
|
|
5
|
+
const typeNodeKinds = /* @__PURE__ */ new Set([
|
|
6
|
+
"JSDocNonNullableType",
|
|
7
|
+
"JSDocNullableType",
|
|
8
|
+
"JSDocUnknownType",
|
|
9
|
+
"TSAnyKeyword",
|
|
10
|
+
"TSArrayType",
|
|
11
|
+
"TSBigIntKeyword",
|
|
12
|
+
"TSBooleanKeyword",
|
|
13
|
+
"TSConditionalType",
|
|
14
|
+
"TSConstructorType",
|
|
15
|
+
"TSFunctionType",
|
|
16
|
+
"TSImportType",
|
|
17
|
+
"TSIndexedAccessType",
|
|
18
|
+
"TSInferType",
|
|
19
|
+
"TSIntersectionType",
|
|
20
|
+
"TSIntrinsicKeyword",
|
|
21
|
+
"TSLiteralType",
|
|
22
|
+
"TSMappedType",
|
|
23
|
+
"TSNamedTupleMember",
|
|
24
|
+
"TSNeverKeyword",
|
|
25
|
+
"TSNullKeyword",
|
|
26
|
+
"TSNumberKeyword",
|
|
27
|
+
"TSObjectKeyword",
|
|
28
|
+
"TSParenthesizedType",
|
|
29
|
+
"TSStringKeyword",
|
|
30
|
+
"TSSymbolKeyword",
|
|
31
|
+
"TSTemplateLiteralType",
|
|
32
|
+
"TSThisType",
|
|
33
|
+
"TSTupleType",
|
|
34
|
+
"TSTypeLiteral",
|
|
35
|
+
"TSTypeOperator",
|
|
36
|
+
"TSTypePredicate",
|
|
37
|
+
"TSTypeQuery",
|
|
38
|
+
"TSTypeReference",
|
|
39
|
+
"TSUndefinedKeyword",
|
|
40
|
+
"TSUnionType",
|
|
41
|
+
"TSUnknownKeyword",
|
|
42
|
+
"TSVoidKeyword"
|
|
43
|
+
]);
|
|
44
|
+
function isTypeNode(node) {
|
|
45
|
+
return typeNodeKinds.has(node.type);
|
|
46
|
+
}
|
|
47
|
+
function typeReferenceName(type) {
|
|
48
|
+
return type.typeName.type === "Identifier" ? type.typeName.name : null;
|
|
49
|
+
}
|
|
50
|
+
function isInsideTypeAliasDeclaration(node) {
|
|
51
|
+
let current = node.parent;
|
|
52
|
+
while (current !== null && current.type !== "Program") {
|
|
53
|
+
if (current.type === "TSTypeAliasDeclaration") return true;
|
|
54
|
+
current = current.parent;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function isPlainAliasConsumerUse(node, environment) {
|
|
59
|
+
if (node.type !== "TSTypeReference" || node.typeArguments?.params.length) return false;
|
|
60
|
+
const name = typeReferenceName(node);
|
|
61
|
+
return name !== null && visibleTypeAlias(name, node, environment.typeAliases) !== null && !isInsideTypeAliasDeclaration(node);
|
|
62
|
+
}
|
|
63
|
+
function isInsideTypeParameterConstraint(node) {
|
|
64
|
+
let child = node;
|
|
65
|
+
let parent = child.parent;
|
|
66
|
+
while (parent !== null && parent.type !== "Program") {
|
|
67
|
+
if (parent.type === "TSTypeParameter" && parent.constraint === child) return true;
|
|
68
|
+
child = parent;
|
|
69
|
+
parent = child.parent;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function shouldReportType(node, environment) {
|
|
74
|
+
if (isInsideTypeParameterConstraint(node)) return false;
|
|
75
|
+
if (isPlainAliasConsumerUse(node, environment)) return false;
|
|
76
|
+
if (classifyUnsafeDictionary(node, environment) === null) return false;
|
|
77
|
+
let current = node.parent;
|
|
78
|
+
while (current !== null && current.type !== "Program") {
|
|
79
|
+
if (isTypeNode(current) && classifyUnsafeDictionary(current, environment) !== null) return false;
|
|
80
|
+
current = current.parent;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/** Disallow object-dictionary contracts whose direct value type is an unsafe escape hatch. */
|
|
85
|
+
const noUnsafeDictionaryTypeRule = defineRule({
|
|
86
|
+
meta: {
|
|
87
|
+
type: "problem",
|
|
88
|
+
docs: { description: "Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches." },
|
|
89
|
+
messages: { 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." }
|
|
90
|
+
},
|
|
91
|
+
createOnce(context) {
|
|
92
|
+
let environment = null;
|
|
93
|
+
const report = (node, value) => {
|
|
94
|
+
context.report({
|
|
95
|
+
node,
|
|
96
|
+
messageId: "unsafeDictionary",
|
|
97
|
+
data: { value }
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const reportIfUnsafe = (node) => {
|
|
101
|
+
if (environment === null || !shouldReportType(node, environment)) return;
|
|
102
|
+
const unsafe = classifyUnsafeDictionary(node, environment);
|
|
103
|
+
if (unsafe === null) return;
|
|
104
|
+
report(node, unsafe.unsafeValue);
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
Program(node) {
|
|
108
|
+
environment = createTypeEnvironment(node, context.sourceCode.visitorKeys);
|
|
109
|
+
},
|
|
110
|
+
TSTypeReference: reportIfUnsafe,
|
|
111
|
+
TSTypeLiteral: reportIfUnsafe,
|
|
112
|
+
TSMappedType: reportIfUnsafe,
|
|
113
|
+
TSIndexSignature(node) {
|
|
114
|
+
if (environment === null || node.typeAnnotation === null || node.parent.type === "TSTypeLiteral") return;
|
|
115
|
+
const unsafe = classifyUnsafeDictionaryValue(node.typeAnnotation.typeAnnotation, environment);
|
|
116
|
+
if (unsafe !== null) report(node, unsafe.unsafeValue);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
export { noUnsafeDictionaryTypeRule };
|