@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,19 @@
|
|
|
1
|
+
import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.mjs";
|
|
2
|
+
import { noManualTagComparisonRule } from "./rules/no-manual-tag-comparison.mjs";
|
|
3
|
+
import { noManualTaggedConstructionRule } from "./rules/no-manual-tagged-construction.mjs";
|
|
4
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.mjs";
|
|
5
|
+
import { preferEffectMatchRule } from "./rules/prefer-effect-match.mjs";
|
|
6
|
+
import { eslintCompatPlugin } from "vite-plus/lint/plugins";
|
|
7
|
+
// src/lint/anti-slop/effect/plugin.ts
|
|
8
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
9
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
10
|
+
meta: { name: "anti-slop-effect" },
|
|
11
|
+
rules: {
|
|
12
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
13
|
+
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
14
|
+
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
15
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
16
|
+
"prefer-effect-match": preferEffectMatchRule
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
export { antiSlopEffectPlugin as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isInsideBroadEffectHandler, isReasonTagMember, isTagMember, tagMemberFromComparison } from "../shared/tagged-values.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/effect/rules/no-manual-effect-error-tag.ts
|
|
4
|
+
const noManualEffectErrorTagRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: { description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler." },
|
|
8
|
+
messages: {
|
|
9
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
10
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
BinaryExpression(node) {
|
|
16
|
+
const tagMember = tagMemberFromComparison(node);
|
|
17
|
+
if (tagMember === void 0 || !isInsideBroadEffectHandler(node)) return;
|
|
18
|
+
context.report({
|
|
19
|
+
node,
|
|
20
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag"
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
SwitchStatement(node) {
|
|
24
|
+
if (!isTagMember(node.discriminant) || !isInsideBroadEffectHandler(node)) return;
|
|
25
|
+
context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export { noManualEffectErrorTagRule };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isInsideBroadEffectHandler, isTagMember, tagMemberFromComparison } from "../shared/tagged-values.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/effect/rules/no-manual-tag-comparison.ts
|
|
4
|
+
const noManualTagComparisonRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: { description: "Use Effect Match or Predicate helpers instead of manually branching on `_tag`." },
|
|
8
|
+
messages: {
|
|
9
|
+
manualComparison: "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
10
|
+
manualSwitch: "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
BinaryExpression(node) {
|
|
16
|
+
if (tagMemberFromComparison(node) === void 0 || isInsideBroadEffectHandler(node)) return;
|
|
17
|
+
context.report({
|
|
18
|
+
node,
|
|
19
|
+
messageId: "manualComparison"
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
SwitchStatement(node) {
|
|
23
|
+
if (!isTagMember(node.discriminant) || isInsideBroadEffectHandler(node)) return;
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: "manualSwitch"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export { noManualTagComparisonRule };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isStringLiteral } from "../../shared/string-literal.mjs";
|
|
2
|
+
import { isMatchPatternObject, propertyName } from "../shared/tagged-values.mjs";
|
|
3
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
4
|
+
// src/lint/anti-slop/effect/rules/no-manual-tagged-construction.ts
|
|
5
|
+
const noManualTaggedConstructionRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually." },
|
|
9
|
+
messages: { manualConstruction: "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
return { ObjectExpression(node) {
|
|
13
|
+
if (isMatchPatternObject(node)) return;
|
|
14
|
+
const tag = node.properties.find((property) => property.type === "Property" && propertyName(property) === "_tag" && isStringLiteral(property.value));
|
|
15
|
+
if (tag !== void 0) context.report({
|
|
16
|
+
node: tag,
|
|
17
|
+
messageId: "manualConstruction"
|
|
18
|
+
});
|
|
19
|
+
} };
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export { noManualTaggedConstructionRule };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/effect/rules/no-service-constructor-imports.ts
|
|
3
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
4
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
5
|
+
function isProjectLocalImport(source) {
|
|
6
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
7
|
+
}
|
|
8
|
+
function getImportedName(specifier) {
|
|
9
|
+
if (specifier.imported.type === "Identifier") return specifier.imported.name;
|
|
10
|
+
return specifier.imported.value;
|
|
11
|
+
}
|
|
12
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
13
|
+
const noServiceConstructorImportsRule = defineRule({
|
|
14
|
+
meta: {
|
|
15
|
+
type: "problem",
|
|
16
|
+
docs: { description: "Disallow project-local make<CapabilityName> imports outside test and spec files." },
|
|
17
|
+
messages: { serviceConstructorImport: "Do not import Effect service constructor \"{{name}}\" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root." }
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
21
|
+
return { ImportDeclaration(node) {
|
|
22
|
+
if (isTestFile || !isProjectLocalImport(node.source.value)) return;
|
|
23
|
+
for (const specifier of node.specifiers) {
|
|
24
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
25
|
+
const importedName = getImportedName(specifier);
|
|
26
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
|
|
27
|
+
context.report({
|
|
28
|
+
node: specifier,
|
|
29
|
+
messageId: "serviceConstructorImport",
|
|
30
|
+
data: { name: importedName }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export { noServiceConstructorImportsRule };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/effect/rules/prefer-effect-match.ts
|
|
3
|
+
const equalityOperators = /* @__PURE__ */ new Set([
|
|
4
|
+
"==",
|
|
5
|
+
"===",
|
|
6
|
+
"!=",
|
|
7
|
+
"!=="
|
|
8
|
+
]);
|
|
9
|
+
const preferEffectMatchRule = defineRule({
|
|
10
|
+
meta: {
|
|
11
|
+
type: "problem",
|
|
12
|
+
docs: { description: "Use Match from Effect for chained literal ternaries over the same value." },
|
|
13
|
+
messages: { preferMatch: "Use Match from Effect instead of a chained literal ternary." }
|
|
14
|
+
},
|
|
15
|
+
createOnce(context) {
|
|
16
|
+
const isLiteral = (node) => node.type === "Literal" || node.type === "TemplateLiteral" && node.expressions.length === 0;
|
|
17
|
+
const comparedValue = (node) => {
|
|
18
|
+
if (node.type !== "BinaryExpression" || !equalityOperators.has(node.operator)) return;
|
|
19
|
+
if (isLiteral(node.left)) return context.sourceCode.getText(node.right);
|
|
20
|
+
if (isLiteral(node.right)) return context.sourceCode.getText(node.left);
|
|
21
|
+
};
|
|
22
|
+
return { ConditionalExpression(node) {
|
|
23
|
+
if (node.parent?.type === "ConditionalExpression") return;
|
|
24
|
+
const value = comparedValue(node.test);
|
|
25
|
+
if (value === void 0) return;
|
|
26
|
+
let alternate = node.alternate;
|
|
27
|
+
let literalChecks = 1;
|
|
28
|
+
while (alternate.type === "ConditionalExpression") {
|
|
29
|
+
if (comparedValue(alternate.test) !== value) return;
|
|
30
|
+
literalChecks += 1;
|
|
31
|
+
alternate = alternate.alternate;
|
|
32
|
+
}
|
|
33
|
+
if (literalChecks > 1) context.report({
|
|
34
|
+
node,
|
|
35
|
+
messageId: "preferMatch"
|
|
36
|
+
});
|
|
37
|
+
} };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
export { preferEffectMatchRule };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isStringLiteral } from "../../shared/string-literal.mjs";
|
|
2
|
+
// src/lint/anti-slop/effect/shared/tagged-values.ts
|
|
3
|
+
const equalityOperators = /* @__PURE__ */ new Set([
|
|
4
|
+
"==",
|
|
5
|
+
"===",
|
|
6
|
+
"!=",
|
|
7
|
+
"!=="
|
|
8
|
+
]);
|
|
9
|
+
const broadEffectCatchMethods = /* @__PURE__ */ new Set([
|
|
10
|
+
"catch",
|
|
11
|
+
"catchAll",
|
|
12
|
+
"catchIf"
|
|
13
|
+
]);
|
|
14
|
+
const isTagMember = (node) => node?.type === "MemberExpression" && (!node.computed && node.property.type === "Identifier" && node.property.name === "_tag" || node.computed && isStringLiteral(node.property) && node.property.value === "_tag");
|
|
15
|
+
const tagMemberFromComparison = (node) => {
|
|
16
|
+
if (!equalityOperators.has(node.operator)) return void 0;
|
|
17
|
+
if (isTagMember(node.left) && isStringLiteral(node.right)) return node.left;
|
|
18
|
+
if (isTagMember(node.right) && isStringLiteral(node.left)) return node.right;
|
|
19
|
+
};
|
|
20
|
+
const isBroadEffectCatchCall = (node) => node?.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "Effect" && !node.callee.computed && node.callee.property.type === "Identifier" && broadEffectCatchMethods.has(node.callee.property.name);
|
|
21
|
+
const isInsideBroadEffectHandler = (node) => {
|
|
22
|
+
let current = node.parent;
|
|
23
|
+
while (current !== null && current !== void 0) {
|
|
24
|
+
if (current.type === "ArrowFunctionExpression" || current.type === "FunctionExpression") return isBroadEffectCatchCall(current.parent) && current.parent.arguments.includes(current);
|
|
25
|
+
current = current.parent;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
const isReasonTagMember = (node) => node.object.type === "MemberExpression" && (!node.object.computed && node.object.property.type === "Identifier" && node.object.property.name === "reason" || node.object.computed && isStringLiteral(node.object.property) && node.object.property.value === "reason");
|
|
30
|
+
const propertyName = (property) => {
|
|
31
|
+
if (!property.computed && property.key.type === "Identifier") return property.key.name;
|
|
32
|
+
if (isStringLiteral(property.key)) return property.key.value;
|
|
33
|
+
};
|
|
34
|
+
const isMatchPatternObject = (node) => {
|
|
35
|
+
const call = node.parent;
|
|
36
|
+
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) return false;
|
|
37
|
+
const callee = call.callee;
|
|
38
|
+
return callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "Match" && !callee.computed && callee.property.type === "Identifier" && (callee.property.name === "when" || callee.property.name === "not");
|
|
39
|
+
};
|
|
40
|
+
export { isInsideBroadEffectHandler, isMatchPatternObject, isReasonTagMember, isTagMember, propertyName, tagMemberFromComparison };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { noArrayFilterMapRule } from "./rules/no-array-filter-map.mjs";
|
|
2
|
+
import { noReduceAccumulatorCopyRule } from "./rules/no-reduce-accumulator-copy.mjs";
|
|
3
|
+
import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.mjs";
|
|
4
|
+
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.mjs";
|
|
5
|
+
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.mjs";
|
|
6
|
+
import { noModuleMockingRule } from "./rules/no-module-mocking.mjs";
|
|
7
|
+
import { noObjectParametersRule } from "./rules/no-object-parameters.mjs";
|
|
8
|
+
import { noReflectApplyRule } from "./rules/no-reflect-apply.mjs";
|
|
9
|
+
import { noReflectGetRule } from "./rules/no-reflect-get.mjs";
|
|
10
|
+
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.mjs";
|
|
11
|
+
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.mjs";
|
|
12
|
+
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.mjs";
|
|
13
|
+
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.mjs";
|
|
14
|
+
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.mjs";
|
|
15
|
+
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.mjs";
|
|
16
|
+
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.mjs";
|
|
17
|
+
import { requireReadableSpacingRule } from "./rules/require-readable-spacing.mjs";
|
|
18
|
+
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.mjs";
|
|
19
|
+
import { eslintCompatPlugin } from "vite-plus/lint/plugins";
|
|
20
|
+
// src/lint/anti-slop/plugin.ts
|
|
21
|
+
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
22
|
+
const antiSlopPlugin = eslintCompatPlugin({
|
|
23
|
+
meta: { name: "anti-slop" },
|
|
24
|
+
rules: {
|
|
25
|
+
"no-array-filter-map": noArrayFilterMapRule,
|
|
26
|
+
"no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
|
|
27
|
+
"no-chained-type-assertions": noChainedTypeAssertionsRule,
|
|
28
|
+
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
|
|
29
|
+
"no-known-value-widening": noKnownValueWideningRule,
|
|
30
|
+
"no-module-mocking": noModuleMockingRule,
|
|
31
|
+
"no-object-parameters": noObjectParametersRule,
|
|
32
|
+
"no-reflect-apply": noReflectApplyRule,
|
|
33
|
+
"no-reflect-get": noReflectGetRule,
|
|
34
|
+
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
35
|
+
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
|
|
36
|
+
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
|
|
37
|
+
"no-unknown-parameters": noUnknownParametersRule,
|
|
38
|
+
"no-unknown-returns": noUnknownReturnsRule,
|
|
39
|
+
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
|
|
40
|
+
"no-widen-then-assert": noWidenThenAssertRule,
|
|
41
|
+
"require-readable-spacing": requireReadableSpacingRule,
|
|
42
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export { antiSlopPlugin as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { arrayMethodTarget, isKnownArrayExpression, unwrapArrayExpression } from "../shared/array-method.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/rules/no-array-filter-map.ts
|
|
4
|
+
/** Reject eager array filter/map pipelines; lazy iterator helpers remain allowed. */
|
|
5
|
+
const noArrayFilterMapRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "suggestion",
|
|
8
|
+
docs: { description: "Disallow adjacent array filter/map passes in favor of lazy iterator helpers or a single transformation." },
|
|
9
|
+
messages: { arrayFilterMap: "Avoid consecutive array `{{first}}` and `{{second}}` passes. Prefer `.values().{{first}}(...).{{second}}(...).toArray()` where iterator helpers are supported, or a single `flatMap`/mutating reducer. Preserve callback ordering, indexes, and filtering semantics." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
return { CallExpression(node) {
|
|
13
|
+
const outer = arrayMethodTarget(node.callee);
|
|
14
|
+
if (outer === null || outer.name !== "map" && outer.name !== "filter") return;
|
|
15
|
+
const innerCall = unwrapArrayExpression(outer.object);
|
|
16
|
+
if (innerCall.type !== "CallExpression") return;
|
|
17
|
+
const inner = arrayMethodTarget(innerCall.callee);
|
|
18
|
+
if (inner === null || inner.name !== (outer.name === "map" ? "filter" : "map")) return;
|
|
19
|
+
if (!isKnownArrayExpression(context.sourceCode, inner.object)) return;
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: "arrayFilterMap",
|
|
23
|
+
data: {
|
|
24
|
+
first: inner.name,
|
|
25
|
+
second: outer.name
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
} };
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export { noArrayFilterMapRule };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/rules/no-chained-type-assertions.ts
|
|
3
|
+
function isTypeAssertionExpression(node) {
|
|
4
|
+
return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
|
|
5
|
+
}
|
|
6
|
+
function unwrapParenthesizedExpression(expression) {
|
|
7
|
+
let current = expression;
|
|
8
|
+
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
11
|
+
function isConstAssertion(node) {
|
|
12
|
+
const { typeAnnotation } = node;
|
|
13
|
+
return typeAnnotation.type === "TSTypeReference" && typeAnnotation.typeName.type === "Identifier" && typeAnnotation.typeName.name === "const";
|
|
14
|
+
}
|
|
15
|
+
function isOutermostAssertionInChain(node) {
|
|
16
|
+
let current = node;
|
|
17
|
+
let parent = node.parent;
|
|
18
|
+
while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
|
|
19
|
+
current = parent;
|
|
20
|
+
parent = parent.parent;
|
|
21
|
+
}
|
|
22
|
+
return !isTypeAssertionExpression(parent) || parent.expression !== current;
|
|
23
|
+
}
|
|
24
|
+
function isForbiddenAssertionChain(node) {
|
|
25
|
+
let assertionCount = 0;
|
|
26
|
+
let hasNonConstAssertion = false;
|
|
27
|
+
let current = node;
|
|
28
|
+
while (isTypeAssertionExpression(current)) {
|
|
29
|
+
assertionCount += 1;
|
|
30
|
+
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
31
|
+
current = unwrapParenthesizedExpression(current.expression);
|
|
32
|
+
}
|
|
33
|
+
return assertionCount > 1 && hasNonConstAssertion;
|
|
34
|
+
}
|
|
35
|
+
/** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
|
|
36
|
+
const noChainedTypeAssertionsRule = defineRule({
|
|
37
|
+
meta: {
|
|
38
|
+
type: "problem",
|
|
39
|
+
docs: { description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains." },
|
|
40
|
+
messages: { chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it." }
|
|
41
|
+
},
|
|
42
|
+
createOnce(context) {
|
|
43
|
+
const checkTypeAssertion = (node) => {
|
|
44
|
+
if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node)) return;
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: "chained"
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
TSAsExpression: checkTypeAssertion,
|
|
52
|
+
TSTypeAssertion: checkTypeAssertion
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export { noChainedTypeAssertionsRule };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/rules/no-conditional-empty-object-spread.ts
|
|
3
|
+
function unwrapParentheses(node) {
|
|
4
|
+
let current = node;
|
|
5
|
+
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
6
|
+
return current;
|
|
7
|
+
}
|
|
8
|
+
function isEmptyObjectExpression(node) {
|
|
9
|
+
return node.type === "ObjectExpression" && node.properties.length === 0;
|
|
10
|
+
}
|
|
11
|
+
function isConditionalEmptyObjectSpread(node) {
|
|
12
|
+
const conditional = unwrapParentheses(node);
|
|
13
|
+
return conditional.type === "ConditionalExpression" && (isEmptyObjectExpression(conditional.consequent) || isEmptyObjectExpression(conditional.alternate));
|
|
14
|
+
}
|
|
15
|
+
/** Ban conditional empty-object spreads without changing their omission semantics. */
|
|
16
|
+
const noConditionalEmptyObjectSpreadRule = defineRule({
|
|
17
|
+
meta: {
|
|
18
|
+
type: "suggestion",
|
|
19
|
+
docs: { description: "Disallow object spreads that conditionally spread an empty object to omit fields." },
|
|
20
|
+
messages: { avoid: "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present." }
|
|
21
|
+
},
|
|
22
|
+
createOnce(context) {
|
|
23
|
+
return { SpreadElement(node) {
|
|
24
|
+
if (node.parent.type !== "ObjectExpression") return;
|
|
25
|
+
if (isConditionalEmptyObjectSpread(node.argument)) context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: "avoid"
|
|
28
|
+
});
|
|
29
|
+
} };
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export { noConditionalEmptyObjectSpreadRule };
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { classifyUnsafeDictionaryValue, classifyWideningTarget, createTypeEnvironment, isKnownEvidenceExpression } from "../shared/dictionary-types.mjs";
|
|
2
|
+
import { containsUnknownType, functionParameterBindingName, functionParameterTypeAnnotation } from "../shared/function-parameters.mjs";
|
|
3
|
+
import { resolveVariable } from "../shared/scope.mjs";
|
|
4
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
5
|
+
// src/lint/anti-slop/rules/no-known-value-widening.ts
|
|
6
|
+
function unwrapExpression(expression) {
|
|
7
|
+
let current = expression;
|
|
8
|
+
while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") current = current.expression;
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
11
|
+
function variableDeclarator(variable) {
|
|
12
|
+
if (variable.defs.length !== 1) return null;
|
|
13
|
+
const [definition] = variable.defs;
|
|
14
|
+
return definition?.type === "Variable" && definition.node.type === "VariableDeclarator" ? definition.node : null;
|
|
15
|
+
}
|
|
16
|
+
function isStableConstVariable(variable, declarator) {
|
|
17
|
+
return declarator.parent.type === "VariableDeclaration" && declarator.parent.kind === "const" && variable.references.every((reference) => reference.init || !reference.isWrite());
|
|
18
|
+
}
|
|
19
|
+
function hasKnownEvidence(sourceCode, expression, visitedVariables = /* @__PURE__ */ new Set()) {
|
|
20
|
+
if (isKnownEvidenceExpression(expression)) return true;
|
|
21
|
+
const unwrapped = unwrapExpression(expression);
|
|
22
|
+
if (unwrapped.type !== "Identifier") return false;
|
|
23
|
+
const variable = resolveVariable(sourceCode, unwrapped);
|
|
24
|
+
if (variable === null || visitedVariables.has(variable)) return false;
|
|
25
|
+
const declarator = variableDeclarator(variable);
|
|
26
|
+
if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) return false;
|
|
27
|
+
visitedVariables.add(variable);
|
|
28
|
+
return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
|
|
29
|
+
}
|
|
30
|
+
function isFunctionExpression(node) {
|
|
31
|
+
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "TSDeclareFunction" || node.type === "TSEmptyBodyFunctionExpression";
|
|
32
|
+
}
|
|
33
|
+
function localFunctionForCall(sourceCode, callee) {
|
|
34
|
+
const unwrapped = unwrapExpression(callee);
|
|
35
|
+
if (isFunctionExpression(unwrapped)) return unwrapped;
|
|
36
|
+
if (unwrapped.type !== "Identifier") return null;
|
|
37
|
+
const variable = resolveVariable(sourceCode, unwrapped);
|
|
38
|
+
if (variable === null || variable.defs.length !== 1) return null;
|
|
39
|
+
const [definition] = variable.defs;
|
|
40
|
+
if (definition === void 0) return null;
|
|
41
|
+
if (definition.type === "FunctionName" && isFunctionExpression(definition.node)) return definition.node;
|
|
42
|
+
if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator") return null;
|
|
43
|
+
const initializer = definition.node.init;
|
|
44
|
+
if (initializer === null) return null;
|
|
45
|
+
const unwrappedInitializer = unwrapExpression(initializer);
|
|
46
|
+
return isFunctionExpression(unwrappedInitializer) ? unwrappedInitializer : null;
|
|
47
|
+
}
|
|
48
|
+
function variableTypeAnnotation(sourceCode, variable) {
|
|
49
|
+
if (variable.defs.length !== 1) return null;
|
|
50
|
+
const [definition] = variable.defs;
|
|
51
|
+
if (definition === void 0) return null;
|
|
52
|
+
if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier") return definition.node.id.typeAnnotation ?? null;
|
|
53
|
+
if (definition.type !== "Parameter" || !isFunctionExpression(definition.node)) return null;
|
|
54
|
+
const parameter = definition.node.params.find((candidate) => functionParameterBindingName(candidate, sourceCode) === variable.name);
|
|
55
|
+
return parameter === void 0 ? null : functionParameterTypeAnnotation(parameter) ?? null;
|
|
56
|
+
}
|
|
57
|
+
function hasInformativeType(type, environment) {
|
|
58
|
+
return classifyUnsafeDictionaryValue(type, environment) === null;
|
|
59
|
+
}
|
|
60
|
+
function hasKnownCallArgumentEvidence(sourceCode, expression, environment, visitedVariables = /* @__PURE__ */ new Set()) {
|
|
61
|
+
if (expression.type === "ParenthesizedExpression" || expression.type === "TSNonNullExpression") return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
|
|
62
|
+
if (expression.type === "TSAsExpression" || expression.type === "TSTypeAssertion") return hasInformativeType(expression.typeAnnotation, environment);
|
|
63
|
+
if (expression.type === "TSSatisfiesExpression") return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
|
|
64
|
+
if (expression.type === "CallExpression") {
|
|
65
|
+
const returnType = localFunctionForCall(sourceCode, expression.callee)?.returnType?.typeAnnotation;
|
|
66
|
+
return returnType !== void 0 && hasInformativeType(returnType, environment);
|
|
67
|
+
}
|
|
68
|
+
if (expression.type !== "Identifier") return isKnownEvidenceExpression(expression);
|
|
69
|
+
const variable = resolveVariable(sourceCode, expression);
|
|
70
|
+
if (variable === null || visitedVariables.has(variable)) return false;
|
|
71
|
+
const annotation = variableTypeAnnotation(sourceCode, variable);
|
|
72
|
+
if (annotation !== null) return hasInformativeType(annotation.typeAnnotation, environment);
|
|
73
|
+
const declarator = variableDeclarator(variable);
|
|
74
|
+
if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) return false;
|
|
75
|
+
visitedVariables.add(variable);
|
|
76
|
+
return hasKnownCallArgumentEvidence(sourceCode, declarator.init, environment, visitedVariables);
|
|
77
|
+
}
|
|
78
|
+
function typePredicateSubjectIndex(sourceCode, owner) {
|
|
79
|
+
const predicate = owner.returnType?.typeAnnotation;
|
|
80
|
+
if (predicate?.type !== "TSTypePredicate" || predicate.parameterName.type !== "Identifier") return null;
|
|
81
|
+
const predicateParameterName = predicate.parameterName.name;
|
|
82
|
+
const index = owner.params.findIndex((parameter) => functionParameterBindingName(parameter, sourceCode) === predicateParameterName);
|
|
83
|
+
return index === -1 ? null : index;
|
|
84
|
+
}
|
|
85
|
+
function annotationTarget(annotation, environment) {
|
|
86
|
+
return annotation === null || annotation === void 0 ? null : classifyWideningTarget(annotation.typeAnnotation, environment);
|
|
87
|
+
}
|
|
88
|
+
function enclosingFunction(node) {
|
|
89
|
+
let current = node.parent;
|
|
90
|
+
while (current !== null && current.type !== "Program") {
|
|
91
|
+
if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") return current;
|
|
92
|
+
current = current.parent;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function sourceKeyName(sourceCode, key) {
|
|
97
|
+
if (key.type === "Identifier" || key.type === "PrivateIdentifier") return key.name;
|
|
98
|
+
if (key.type === "Literal") return String(key.value);
|
|
99
|
+
return sourceCode.getText(key);
|
|
100
|
+
}
|
|
101
|
+
function functionName(sourceCode, owner) {
|
|
102
|
+
if (owner === null) return "anonymous function";
|
|
103
|
+
if (owner.id !== null) return owner.id.name;
|
|
104
|
+
const parent = owner.parent;
|
|
105
|
+
if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") return parent.id.name;
|
|
106
|
+
if (parent.type === "MethodDefinition") return sourceKeyName(sourceCode, parent.key);
|
|
107
|
+
return "anonymous function";
|
|
108
|
+
}
|
|
109
|
+
function isEmptyObjectExpression(expression) {
|
|
110
|
+
const unwrapped = unwrapExpression(expression);
|
|
111
|
+
return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
|
|
112
|
+
}
|
|
113
|
+
function isDictionaryAccumulatorTarget(destination) {
|
|
114
|
+
return destination.kind === "open dictionary" || destination.kind === "generic container";
|
|
115
|
+
}
|
|
116
|
+
function hasParentAssertion(node) {
|
|
117
|
+
return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
|
|
118
|
+
}
|
|
119
|
+
/** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
|
|
120
|
+
const noKnownValueWideningRule = defineRule({
|
|
121
|
+
meta: {
|
|
122
|
+
type: "problem",
|
|
123
|
+
docs: { description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence." },
|
|
124
|
+
messages: { widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract." }
|
|
125
|
+
},
|
|
126
|
+
createOnce(context) {
|
|
127
|
+
let environment = null;
|
|
128
|
+
let calls = [];
|
|
129
|
+
let assignments = [];
|
|
130
|
+
let declaresPredicate = false;
|
|
131
|
+
let declaresWideningBinding = false;
|
|
132
|
+
const notePredicate = (node) => {
|
|
133
|
+
if (node.returnType?.typeAnnotation.type === "TSTypePredicate") declaresPredicate = true;
|
|
134
|
+
};
|
|
135
|
+
const reportFlow = (expression, destination, subject) => {
|
|
136
|
+
if (destination === null) return;
|
|
137
|
+
if (isDictionaryAccumulatorTarget(destination) && isEmptyObjectExpression(expression)) return;
|
|
138
|
+
if (!hasKnownEvidence(context.sourceCode, expression)) return;
|
|
139
|
+
context.report({
|
|
140
|
+
node: expression,
|
|
141
|
+
messageId: "widening",
|
|
142
|
+
data: {
|
|
143
|
+
subject,
|
|
144
|
+
target: destination.kind
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const targetFromAnnotation = (annotation) => environment === null ? null : annotationTarget(annotation, environment);
|
|
149
|
+
const checkCall = (node) => {
|
|
150
|
+
if (environment === null) return;
|
|
151
|
+
const owner = localFunctionForCall(context.sourceCode, node.callee);
|
|
152
|
+
if (owner === null) return;
|
|
153
|
+
const parameterIndex = typePredicateSubjectIndex(context.sourceCode, owner);
|
|
154
|
+
if (parameterIndex === null) return;
|
|
155
|
+
const parameter = owner.params[parameterIndex];
|
|
156
|
+
const argument = node.arguments[parameterIndex];
|
|
157
|
+
if (parameter === void 0 || argument === void 0 || argument.type === "SpreadElement") return;
|
|
158
|
+
const parameterAnnotation = functionParameterTypeAnnotation(parameter);
|
|
159
|
+
if (parameterAnnotation === null || parameterAnnotation === void 0 || !containsUnknownType(parameterAnnotation.typeAnnotation)) return;
|
|
160
|
+
if (!hasKnownCallArgumentEvidence(context.sourceCode, argument, environment)) return;
|
|
161
|
+
context.report({
|
|
162
|
+
node: argument,
|
|
163
|
+
messageId: "widening",
|
|
164
|
+
data: {
|
|
165
|
+
subject: `argument for parameter \`${functionParameterBindingName(parameter, context.sourceCode)}\` of \`${functionName(context.sourceCode, owner)}\``,
|
|
166
|
+
target: "unknown"
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
const checkAssignment = (node) => {
|
|
171
|
+
if (node.left.type !== "Identifier") return;
|
|
172
|
+
const variable = resolveVariable(context.sourceCode, node.left);
|
|
173
|
+
if (variable === null) return;
|
|
174
|
+
const declarator = variableDeclarator(variable);
|
|
175
|
+
if (declarator === null || declarator.id.type !== "Identifier") return;
|
|
176
|
+
reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
Program(node) {
|
|
180
|
+
calls = [];
|
|
181
|
+
assignments = [];
|
|
182
|
+
declaresPredicate = false;
|
|
183
|
+
declaresWideningBinding = false;
|
|
184
|
+
environment = createTypeEnvironment(node, context.sourceCode.visitorKeys);
|
|
185
|
+
},
|
|
186
|
+
VariableDeclarator(node) {
|
|
187
|
+
if (node.id.type !== "Identifier") return;
|
|
188
|
+
const target = targetFromAnnotation(node.id.typeAnnotation);
|
|
189
|
+
if (target !== null) declaresWideningBinding = true;
|
|
190
|
+
if (node.init === null) return;
|
|
191
|
+
reportFlow(node.init, target, `binding \`${node.id.name}\``);
|
|
192
|
+
},
|
|
193
|
+
PropertyDefinition(node) {
|
|
194
|
+
if (node.value === null) return;
|
|
195
|
+
reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
|
|
196
|
+
},
|
|
197
|
+
AccessorProperty(node) {
|
|
198
|
+
if (node.value === null) return;
|
|
199
|
+
reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
|
|
200
|
+
},
|
|
201
|
+
AssignmentExpression(node) {
|
|
202
|
+
if (node.operator === "=" && node.left.type === "Identifier") assignments.push(node);
|
|
203
|
+
},
|
|
204
|
+
CallExpression(node) {
|
|
205
|
+
calls.push(node);
|
|
206
|
+
},
|
|
207
|
+
"Program:exit"() {
|
|
208
|
+
if (declaresPredicate) for (const call of calls) checkCall(call);
|
|
209
|
+
if (declaresWideningBinding) for (const assignment of assignments) checkAssignment(assignment);
|
|
210
|
+
},
|
|
211
|
+
FunctionDeclaration: notePredicate,
|
|
212
|
+
FunctionExpression: notePredicate,
|
|
213
|
+
TSDeclareFunction: notePredicate,
|
|
214
|
+
TSEmptyBodyFunctionExpression: notePredicate,
|
|
215
|
+
ReturnStatement(node) {
|
|
216
|
+
if (node.argument === null) return;
|
|
217
|
+
const owner = enclosingFunction(node);
|
|
218
|
+
reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
|
|
219
|
+
},
|
|
220
|
+
ArrowFunctionExpression(node) {
|
|
221
|
+
notePredicate(node);
|
|
222
|
+
if (node.body.type === "BlockStatement") return;
|
|
223
|
+
reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
|
|
224
|
+
},
|
|
225
|
+
TSAsExpression(node) {
|
|
226
|
+
if (environment === null || hasParentAssertion(node)) return;
|
|
227
|
+
reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
|
|
228
|
+
},
|
|
229
|
+
TSTypeAssertion(node) {
|
|
230
|
+
if (environment === null || hasParentAssertion(node)) return;
|
|
231
|
+
reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
export { noKnownValueWideningRule };
|