@jfalava/ts-standard 0.2.2 → 0.3.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 +21 -0
- package/dist/oxlint/effect/index.js +254 -0
- package/dist/oxlint/index.js +183 -0
- package/oxlint/LICENSE +21 -0
- package/oxlint/UPSTREAM.md +9 -0
- package/package.json +14 -4
- package/src/lint.ts +11 -45
- package/src/pins.ts +8 -3
- package/reference/anti-slop/UPSTREAM.md +0 -8
- package/reference/anti-slop/effect/index.ts +0 -21
- package/reference/anti-slop/effect/rules/no-manual-effect-error-tag.ts +0 -52
- package/reference/anti-slop/effect/rules/no-manual-tag-comparison.ts +0 -45
- package/reference/anti-slop/effect/rules/no-manual-tagged-construction.ts +0 -37
- package/reference/anti-slop/effect/rules/no-service-constructor-imports.ts +0 -52
- package/reference/anti-slop/effect/rules/prefer-effect-match.ts +0 -54
- package/reference/anti-slop/effect/shared/tagged-values.ts +0 -97
- package/reference/anti-slop/index.ts +0 -24
- package/reference/anti-slop/rules/no-module-mocking.ts +0 -80
- package/reference/anti-slop/rules/no-runtime-typeof.ts +0 -77
- package/reference/anti-slop/rules/no-shape-in-symbol-names.ts +0 -46
- package/reference/anti-slop/rules/no-unknown-parameters.ts +0 -69
- package/reference/anti-slop/rules/require-safety-comment-for-type-assertion.ts +0 -131
- package/reference/anti-slop/shared/function-parameters.ts +0 -49
- package/reference/anti-slop/shared/scope.ts +0 -15
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isInsideBroadEffectHandler,
|
|
5
|
-
isReasonTagMember,
|
|
6
|
-
isTagMember,
|
|
7
|
-
tagMemberFromComparison,
|
|
8
|
-
} from "../shared/tagged-values.ts";
|
|
9
|
-
|
|
10
|
-
export const noManualEffectErrorTagRule = defineRule({
|
|
11
|
-
meta: {
|
|
12
|
-
type: "problem",
|
|
13
|
-
docs: {
|
|
14
|
-
description:
|
|
15
|
-
"Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",
|
|
16
|
-
},
|
|
17
|
-
messages: {
|
|
18
|
-
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
19
|
-
reason:
|
|
20
|
-
"Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler.",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
createOnce(context) {
|
|
24
|
-
return {
|
|
25
|
-
BinaryExpression(node) {
|
|
26
|
-
const tagMember = tagMemberFromComparison(node);
|
|
27
|
-
if (
|
|
28
|
-
tagMember === undefined ||
|
|
29
|
-
!isInsideBroadEffectHandler(node)
|
|
30
|
-
) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
context.report({
|
|
34
|
-
node,
|
|
35
|
-
messageId: isReasonTagMember(tagMember) ? "reason" : "tag",
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
SwitchStatement(node) {
|
|
39
|
-
if (
|
|
40
|
-
!isTagMember(node.discriminant) ||
|
|
41
|
-
!isInsideBroadEffectHandler(node)
|
|
42
|
-
) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
context.report({
|
|
46
|
-
node,
|
|
47
|
-
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag",
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isInsideBroadEffectHandler,
|
|
5
|
-
isTagMember,
|
|
6
|
-
tagMemberFromComparison,
|
|
7
|
-
} from "../shared/tagged-values.ts";
|
|
8
|
-
|
|
9
|
-
export const noManualTagComparisonRule = defineRule({
|
|
10
|
-
meta: {
|
|
11
|
-
type: "problem",
|
|
12
|
-
docs: {
|
|
13
|
-
description:
|
|
14
|
-
"Use Effect Match or Predicate helpers instead of manually branching on `_tag`.",
|
|
15
|
-
},
|
|
16
|
-
messages: {
|
|
17
|
-
manualComparison:
|
|
18
|
-
"Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
19
|
-
manualSwitch:
|
|
20
|
-
"Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`.",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
createOnce(context) {
|
|
24
|
-
return {
|
|
25
|
-
BinaryExpression(node) {
|
|
26
|
-
if (
|
|
27
|
-
tagMemberFromComparison(node) === undefined ||
|
|
28
|
-
isInsideBroadEffectHandler(node)
|
|
29
|
-
) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
context.report({ node, messageId: "manualComparison" });
|
|
33
|
-
},
|
|
34
|
-
SwitchStatement(node) {
|
|
35
|
-
if (
|
|
36
|
-
!isTagMember(node.discriminant) ||
|
|
37
|
-
isInsideBroadEffectHandler(node)
|
|
38
|
-
) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
context.report({ node, messageId: "manualSwitch" });
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isMatchPatternObject,
|
|
5
|
-
isStringLiteral,
|
|
6
|
-
propertyName,
|
|
7
|
-
} from "../shared/tagged-values.ts";
|
|
8
|
-
|
|
9
|
-
export const noManualTaggedConstructionRule = defineRule({
|
|
10
|
-
meta: {
|
|
11
|
-
type: "problem",
|
|
12
|
-
docs: {
|
|
13
|
-
description:
|
|
14
|
-
"Construct tagged values with their existing Effect constructor instead of writing `_tag` manually.",
|
|
15
|
-
},
|
|
16
|
-
messages: {
|
|
17
|
-
manualConstruction:
|
|
18
|
-
"Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object.",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
createOnce(context) {
|
|
22
|
-
return {
|
|
23
|
-
ObjectExpression(node) {
|
|
24
|
-
if (isMatchPatternObject(node)) return;
|
|
25
|
-
const tag = node.properties.find(
|
|
26
|
-
(property) =>
|
|
27
|
-
property.type === "Property" &&
|
|
28
|
-
propertyName(property) === "_tag" &&
|
|
29
|
-
isStringLiteral(property.value),
|
|
30
|
-
);
|
|
31
|
-
if (tag !== undefined) {
|
|
32
|
-
context.report({ node: tag, messageId: "manualConstruction" });
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
6
|
-
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
7
|
-
|
|
8
|
-
function isProjectLocalImport(source: string): boolean {
|
|
9
|
-
return source.startsWith("./") || source.startsWith("../");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function getImportedName(specifier: ESTree.ImportSpecifier): string {
|
|
13
|
-
if (specifier.imported.type === "Identifier") return specifier.imported.name;
|
|
14
|
-
return specifier.imported.value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
18
|
-
export const noServiceConstructorImportsRule = defineRule({
|
|
19
|
-
meta: {
|
|
20
|
-
type: "problem",
|
|
21
|
-
docs: {
|
|
22
|
-
description:
|
|
23
|
-
"Disallow project-local make<CapabilityName> imports outside test and spec files.",
|
|
24
|
-
},
|
|
25
|
-
messages: {
|
|
26
|
-
serviceConstructorImport:
|
|
27
|
-
'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.',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
create(context) {
|
|
31
|
-
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
ImportDeclaration(node) {
|
|
35
|
-
if (isTestFile || !isProjectLocalImport(node.source.value)) return;
|
|
36
|
-
|
|
37
|
-
for (const specifier of node.specifiers) {
|
|
38
|
-
if (specifier.type !== "ImportSpecifier") continue;
|
|
39
|
-
|
|
40
|
-
const importedName = getImportedName(specifier);
|
|
41
|
-
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
|
|
42
|
-
|
|
43
|
-
context.report({
|
|
44
|
-
node: specifier,
|
|
45
|
-
messageId: "serviceConstructorImport",
|
|
46
|
-
data: { name: importedName },
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { defineRule, type ESTree } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
4
|
-
|
|
5
|
-
export const preferEffectMatchRule = defineRule({
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description:
|
|
10
|
-
"Use Match from Effect for chained literal ternaries over the same value.",
|
|
11
|
-
},
|
|
12
|
-
messages: {
|
|
13
|
-
preferMatch:
|
|
14
|
-
"Use Match from Effect instead of a chained literal ternary.",
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
createOnce(context) {
|
|
18
|
-
const isLiteral = (node: ESTree.Node): boolean =>
|
|
19
|
-
node.type === "Literal" ||
|
|
20
|
-
(node.type === "TemplateLiteral" && node.expressions.length === 0);
|
|
21
|
-
|
|
22
|
-
const comparedValue = (node: ESTree.Expression): string | undefined => {
|
|
23
|
-
if (
|
|
24
|
-
node.type !== "BinaryExpression" ||
|
|
25
|
-
!equalityOperators.has(node.operator)
|
|
26
|
-
) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
if (isLiteral(node.left)) return context.sourceCode.getText(node.right);
|
|
30
|
-
if (isLiteral(node.right)) return context.sourceCode.getText(node.left);
|
|
31
|
-
return undefined;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
ConditionalExpression(node) {
|
|
36
|
-
if (node.parent?.type === "ConditionalExpression") return;
|
|
37
|
-
const value = comparedValue(node.test);
|
|
38
|
-
if (value === undefined) return;
|
|
39
|
-
|
|
40
|
-
let alternate = node.alternate;
|
|
41
|
-
let literalChecks = 1;
|
|
42
|
-
while (alternate.type === "ConditionalExpression") {
|
|
43
|
-
if (comparedValue(alternate.test) !== value) return;
|
|
44
|
-
literalChecks += 1;
|
|
45
|
-
alternate = alternate.alternate;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (literalChecks > 1) {
|
|
49
|
-
context.report({ node, messageId: "preferMatch" });
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
4
|
-
const broadEffectCatchMethods = new Set(["catch", "catchAll", "catchIf"]);
|
|
5
|
-
|
|
6
|
-
export const isStringLiteral = (
|
|
7
|
-
node: ESTree.Node | null | undefined,
|
|
8
|
-
): node is ESTree.StringLiteral =>
|
|
9
|
-
node?.type === "Literal" && typeof node.value === "string";
|
|
10
|
-
|
|
11
|
-
export const isTagMember = (
|
|
12
|
-
node: ESTree.Node | null | undefined,
|
|
13
|
-
): node is ESTree.MemberExpression =>
|
|
14
|
-
node?.type === "MemberExpression" &&
|
|
15
|
-
((!node.computed &&
|
|
16
|
-
node.property.type === "Identifier" &&
|
|
17
|
-
node.property.name === "_tag") ||
|
|
18
|
-
(node.computed &&
|
|
19
|
-
isStringLiteral(node.property) &&
|
|
20
|
-
node.property.value === "_tag"));
|
|
21
|
-
|
|
22
|
-
export const tagMemberFromComparison = (
|
|
23
|
-
node: ESTree.BinaryExpression,
|
|
24
|
-
): ESTree.MemberExpression | undefined => {
|
|
25
|
-
if (!equalityOperators.has(node.operator)) return undefined;
|
|
26
|
-
if (isTagMember(node.left) && isStringLiteral(node.right)) return node.left;
|
|
27
|
-
if (isTagMember(node.right) && isStringLiteral(node.left)) return node.right;
|
|
28
|
-
return undefined;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const isBroadEffectCatchCall = (
|
|
32
|
-
node: ESTree.Node | null | undefined,
|
|
33
|
-
): node is ESTree.CallExpression =>
|
|
34
|
-
node?.type === "CallExpression" &&
|
|
35
|
-
node.callee.type === "MemberExpression" &&
|
|
36
|
-
node.callee.object.type === "Identifier" &&
|
|
37
|
-
node.callee.object.name === "Effect" &&
|
|
38
|
-
!node.callee.computed &&
|
|
39
|
-
node.callee.property.type === "Identifier" &&
|
|
40
|
-
broadEffectCatchMethods.has(node.callee.property.name);
|
|
41
|
-
|
|
42
|
-
export const isInsideBroadEffectHandler = (node: ESTree.Node): boolean => {
|
|
43
|
-
let current: ESTree.Node | null | undefined = node.parent;
|
|
44
|
-
while (current !== null && current !== undefined) {
|
|
45
|
-
if (
|
|
46
|
-
current.type === "ArrowFunctionExpression" ||
|
|
47
|
-
current.type === "FunctionExpression"
|
|
48
|
-
) {
|
|
49
|
-
return (
|
|
50
|
-
isBroadEffectCatchCall(current.parent) &&
|
|
51
|
-
current.parent.arguments.includes(current)
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
current = current.parent;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const isReasonTagMember = (node: ESTree.MemberExpression): boolean =>
|
|
60
|
-
node.object.type === "MemberExpression" &&
|
|
61
|
-
((!node.object.computed &&
|
|
62
|
-
node.object.property.type === "Identifier" &&
|
|
63
|
-
node.object.property.name === "reason") ||
|
|
64
|
-
(node.object.computed &&
|
|
65
|
-
isStringLiteral(node.object.property) &&
|
|
66
|
-
node.object.property.value === "reason"));
|
|
67
|
-
|
|
68
|
-
export const propertyName = (
|
|
69
|
-
property: ESTree.ObjectProperty,
|
|
70
|
-
): string | undefined => {
|
|
71
|
-
if (!property.computed && property.key.type === "Identifier") {
|
|
72
|
-
return property.key.name;
|
|
73
|
-
}
|
|
74
|
-
if (
|
|
75
|
-
property.key.type === "Literal" &&
|
|
76
|
-
typeof property.key.value === "string"
|
|
77
|
-
) {
|
|
78
|
-
return property.key.value;
|
|
79
|
-
}
|
|
80
|
-
return undefined;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const isMatchPatternObject = (node: ESTree.ObjectExpression): boolean => {
|
|
84
|
-
const call = node.parent;
|
|
85
|
-
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
const callee = call.callee;
|
|
89
|
-
return (
|
|
90
|
-
callee.type === "MemberExpression" &&
|
|
91
|
-
callee.object.type === "Identifier" &&
|
|
92
|
-
callee.object.name === "Match" &&
|
|
93
|
-
!callee.computed &&
|
|
94
|
-
callee.property.type === "Identifier" &&
|
|
95
|
-
(callee.property.name === "when" || callee.property.name === "not")
|
|
96
|
-
);
|
|
97
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
|
|
4
|
-
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
|
|
5
|
-
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
|
|
6
|
-
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
|
|
7
|
-
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The anti-slop rules that @cloudflare/oxlint-config does not carry. The rest of anti-slop ships
|
|
11
|
-
* in that preset as `quality/*`.
|
|
12
|
-
*/
|
|
13
|
-
const antiSlopPlugin = eslintCompatPlugin({
|
|
14
|
-
meta: { name: "anti-slop" },
|
|
15
|
-
rules: {
|
|
16
|
-
"no-module-mocking": noModuleMockingRule,
|
|
17
|
-
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
18
|
-
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
|
|
19
|
-
"no-unknown-parameters": noUnknownParametersRule,
|
|
20
|
-
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export default antiSlopPlugin;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import { resolveVariable } from "../shared/scope.ts";
|
|
4
|
-
|
|
5
|
-
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
6
|
-
|
|
7
|
-
const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
|
|
8
|
-
|
|
9
|
-
function importedName(node: ESTree.Node): string | null {
|
|
10
|
-
if (node.type !== "ImportSpecifier") return null;
|
|
11
|
-
return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function isTestFrameworkObject(
|
|
15
|
-
sourceCode: SourceCode,
|
|
16
|
-
expression: ESTree.Expression,
|
|
17
|
-
): expression is ESTree.IdentifierReference {
|
|
18
|
-
if (expression.type !== "Identifier") return false;
|
|
19
|
-
if (
|
|
20
|
-
(expression.name === "vi" || expression.name === "jest") &&
|
|
21
|
-
sourceCode.isGlobalReference(expression)
|
|
22
|
-
) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const variable = resolveVariable(sourceCode, expression);
|
|
27
|
-
if (variable === null || variable.defs.length === 0) {
|
|
28
|
-
return expression.name === "vi" || expression.name === "jest";
|
|
29
|
-
}
|
|
30
|
-
return variable.defs.some((definition) => {
|
|
31
|
-
if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
const source = definition.parent.source.value;
|
|
35
|
-
const name = importedName(definition.node);
|
|
36
|
-
return (source === "vitest" && name === "vi") || (source === "@jest/globals" && name === "jest");
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function moduleMockCall(sourceCode: SourceCode, callee: ESTree.Expression): boolean {
|
|
41
|
-
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
|
|
42
|
-
if (!isTestFrameworkObject(sourceCode, callee.object)) return false;
|
|
43
|
-
const property = callee.property;
|
|
44
|
-
const method = callee.computed
|
|
45
|
-
? property.type === "Literal" &&
|
|
46
|
-
(property.value === "doMock" ||
|
|
47
|
-
property.value === "mock" ||
|
|
48
|
-
property.value === "unstable_mockModule")
|
|
49
|
-
? property.value
|
|
50
|
-
: null
|
|
51
|
-
: property.type === "Identifier"
|
|
52
|
-
? property.name
|
|
53
|
-
: null;
|
|
54
|
-
return method !== null && moduleMockMethods.has(method);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Ban test framework module mocking in favor of real dependency seams. */
|
|
58
|
-
export const noModuleMockingRule = defineRule({
|
|
59
|
-
meta: {
|
|
60
|
-
type: "problem",
|
|
61
|
-
docs: {
|
|
62
|
-
description:
|
|
63
|
-
"Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
|
|
64
|
-
},
|
|
65
|
-
messages: {
|
|
66
|
-
moduleMock:
|
|
67
|
-
"Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
createOnce(context) {
|
|
71
|
-
return {
|
|
72
|
-
CallExpression(node) {
|
|
73
|
-
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
|
|
74
|
-
if (moduleMockCall(context.sourceCode, node.callee)) {
|
|
75
|
-
context.report({ node, messageId: "moduleMock" });
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
type RuntimeFunction = ESTree.ArrowFunctionExpression | ESTree.Function;
|
|
6
|
-
|
|
7
|
-
function isRuntimeFunction(node: ESTree.Node): node is RuntimeFunction {
|
|
8
|
-
return (
|
|
9
|
-
node.type === "ArrowFunctionExpression" ||
|
|
10
|
-
node.type === "FunctionDeclaration" ||
|
|
11
|
-
node.type === "FunctionExpression"
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function isInsideTypeGuard(node: ESTree.Node): boolean {
|
|
16
|
-
let current: ESTree.Node | null = node.parent;
|
|
17
|
-
while (current !== null && current.type !== "Program") {
|
|
18
|
-
if (isRuntimeFunction(current)) {
|
|
19
|
-
return current.returnType?.typeAnnotation.type === "TSTypePredicate";
|
|
20
|
-
}
|
|
21
|
-
current = current.parent;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Return whether typeof safely probes for the existence of a possibly absent binding. */
|
|
27
|
-
function isExistenceProbe(node: ESTree.UnaryExpression): boolean {
|
|
28
|
-
const parent = node.parent;
|
|
29
|
-
if (parent.type !== "BinaryExpression") return false;
|
|
30
|
-
if (!["===", "!==", "==", "!="].includes(parent.operator)) return false;
|
|
31
|
-
const other = parent.left === node ? parent.right : parent.left;
|
|
32
|
-
return other.type === "Literal" && other.value === "undefined";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
|
|
36
|
-
export const noRuntimeTypeofRule = defineRule({
|
|
37
|
-
meta: {
|
|
38
|
-
type: "problem",
|
|
39
|
-
docs: {
|
|
40
|
-
description:
|
|
41
|
-
"Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary.",
|
|
42
|
-
},
|
|
43
|
-
messages: {
|
|
44
|
-
runtimeTypeof:
|
|
45
|
-
"A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
|
|
46
|
-
},
|
|
47
|
-
schema: [
|
|
48
|
-
{
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
allowInTypeGuards: { type: "boolean" },
|
|
52
|
-
},
|
|
53
|
-
additionalProperties: false,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
defaultOptions: [{ allowInTypeGuards: false }],
|
|
57
|
-
},
|
|
58
|
-
createOnce(context) {
|
|
59
|
-
return {
|
|
60
|
-
UnaryExpression(node) {
|
|
61
|
-
const option = context.options?.[0];
|
|
62
|
-
const allowInTypeGuards =
|
|
63
|
-
typeof option === "object" &&
|
|
64
|
-
option !== null &&
|
|
65
|
-
!Array.isArray(option) &&
|
|
66
|
-
option.allowInTypeGuards === true;
|
|
67
|
-
if (
|
|
68
|
-
node.operator === "typeof" &&
|
|
69
|
-
!isExistenceProbe(node) &&
|
|
70
|
-
(!allowInTypeGuards || !isInsideTypeGuard(node))
|
|
71
|
-
) {
|
|
72
|
-
context.report({ node, messageId: "runtimeTypeof" });
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
-
|
|
4
|
-
const FORBIDDEN_SYMBOL_NAME = "shape";
|
|
5
|
-
|
|
6
|
-
function containsForbiddenSymbolName(name: string): boolean {
|
|
7
|
-
return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** Return whether an identifier names a statically accessed member owned by another value. */
|
|
11
|
-
function isBorrowedMemberName(node: ESTree.Node): boolean {
|
|
12
|
-
const parent = node.parent;
|
|
13
|
-
if (parent === null || parent.type !== "MemberExpression") return false;
|
|
14
|
-
return parent.property === node && parent.computed === false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
|
|
18
|
-
export const noForbiddenTermInSymbolNamesRule = defineRule({
|
|
19
|
-
meta: {
|
|
20
|
-
type: "problem",
|
|
21
|
-
docs: {
|
|
22
|
-
description:
|
|
23
|
-
'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.',
|
|
24
|
-
},
|
|
25
|
-
messages: {
|
|
26
|
-
forbiddenSymbolName:
|
|
27
|
-
'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
createOnce(context) {
|
|
31
|
-
const reportForbiddenSymbolName = (node: ESTree.Node & { name: string }) => {
|
|
32
|
-
if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
|
|
33
|
-
context.report({
|
|
34
|
-
node,
|
|
35
|
-
messageId: "forbiddenSymbolName",
|
|
36
|
-
data: { name: node.name },
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
Identifier: reportForbiddenSymbolName,
|
|
42
|
-
PrivateIdentifier: reportForbiddenSymbolName,
|
|
43
|
-
JSXIdentifier: reportForbiddenSymbolName,
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
containsUnknownType,
|
|
6
|
-
functionParameterBindingName,
|
|
7
|
-
functionParameterTypeAnnotation,
|
|
8
|
-
} from "../shared/function-parameters.ts";
|
|
9
|
-
type ParameterOwner =
|
|
10
|
-
| ESTree.ArrowFunctionExpression
|
|
11
|
-
| ESTree.Function
|
|
12
|
-
| ESTree.TSCallSignatureDeclaration
|
|
13
|
-
| ESTree.TSConstructSignatureDeclaration
|
|
14
|
-
| ESTree.TSConstructorType
|
|
15
|
-
| ESTree.TSFunctionType
|
|
16
|
-
| ESTree.TSMethodSignature;
|
|
17
|
-
|
|
18
|
-
function isTypePredicateSubject(owner: ParameterOwner, parameterName: string): boolean {
|
|
19
|
-
const predicate = owner.returnType?.typeAnnotation;
|
|
20
|
-
return (
|
|
21
|
-
predicate?.type === "TSTypePredicate" &&
|
|
22
|
-
predicate.parameterName.type === "Identifier" &&
|
|
23
|
-
predicate.parameterName.name === parameterName
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Disallow unknown inputs except explicitly named error-cause enrichment. */
|
|
28
|
-
export const noUnknownParametersRule = defineRule({
|
|
29
|
-
meta: {
|
|
30
|
-
type: "problem",
|
|
31
|
-
docs: {
|
|
32
|
-
description:
|
|
33
|
-
"Disallow explicitly unknown function parameters except `cause` and type-predicate subjects; decode unknown input at its I/O boundary instead.",
|
|
34
|
-
},
|
|
35
|
-
messages: {
|
|
36
|
-
unknownParameter:
|
|
37
|
-
"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.",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
createOnce(context) {
|
|
41
|
-
const checkParameters = (node: ParameterOwner) => {
|
|
42
|
-
for (const parameter of node.params) {
|
|
43
|
-
const annotation = functionParameterTypeAnnotation(parameter);
|
|
44
|
-
if (annotation === null || annotation === undefined) continue;
|
|
45
|
-
if (!containsUnknownType(annotation.typeAnnotation)) continue;
|
|
46
|
-
const name = functionParameterBindingName(parameter, context.sourceCode);
|
|
47
|
-
if (name === "cause" || isTypePredicateSubject(node, name)) continue;
|
|
48
|
-
context.report({
|
|
49
|
-
node: annotation.typeAnnotation,
|
|
50
|
-
messageId: "unknownParameter",
|
|
51
|
-
data: { parameter: name },
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
ArrowFunctionExpression: checkParameters,
|
|
58
|
-
FunctionDeclaration: checkParameters,
|
|
59
|
-
FunctionExpression: checkParameters,
|
|
60
|
-
TSCallSignatureDeclaration: checkParameters,
|
|
61
|
-
TSConstructSignatureDeclaration: checkParameters,
|
|
62
|
-
TSConstructorType: checkParameters,
|
|
63
|
-
TSDeclareFunction: checkParameters,
|
|
64
|
-
TSEmptyBodyFunctionExpression: checkParameters,
|
|
65
|
-
TSFunctionType: checkParameters,
|
|
66
|
-
TSMethodSignature: checkParameters,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
});
|