@jfalava/ts-standard 0.2.3 → 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/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 +13 -4
- package/src/lint.ts +11 -45
- 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,131 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
4
|
-
|
|
5
|
-
type TypeAssertion = ESTree.TSAsExpression | ESTree.TSTypeAssertion;
|
|
6
|
-
|
|
7
|
-
const DEFAULT_SAFETY_MARKERS = ["SAFETY"] as const;
|
|
8
|
-
|
|
9
|
-
const commentOwnerKinds = new Set([
|
|
10
|
-
"ExpressionStatement",
|
|
11
|
-
"PropertyDefinition",
|
|
12
|
-
"ReturnStatement",
|
|
13
|
-
"ThrowStatement",
|
|
14
|
-
"VariableDeclaration",
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
function isConstAssertion(node: TypeAssertion): boolean {
|
|
18
|
-
return (
|
|
19
|
-
node.typeAnnotation.type === "TSTypeReference" &&
|
|
20
|
-
node.typeAnnotation.typeName.type === "Identifier" &&
|
|
21
|
-
node.typeAnnotation.typeName.name === "const"
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function configuredSafetyMarkers(option: unknown): readonly string[] {
|
|
26
|
-
if (typeof option !== "object" || option === null || !("markers" in option)) {
|
|
27
|
-
return DEFAULT_SAFETY_MARKERS;
|
|
28
|
-
}
|
|
29
|
-
const configured = option.markers;
|
|
30
|
-
if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
|
|
31
|
-
const markers = configured.flatMap((marker) =>
|
|
32
|
-
typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : [],
|
|
33
|
-
);
|
|
34
|
-
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function markerPattern(markers: readonly string[]): RegExp {
|
|
38
|
-
const alternation = markers
|
|
39
|
-
.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`))
|
|
40
|
-
.join("|");
|
|
41
|
-
return new RegExp(
|
|
42
|
-
String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`,
|
|
43
|
-
"u",
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function hasSafetyJustificationBefore(
|
|
48
|
-
sourceCode: SourceCode,
|
|
49
|
-
owner: ESTree.Node,
|
|
50
|
-
assertion: TypeAssertion,
|
|
51
|
-
pattern: RegExp,
|
|
52
|
-
): boolean {
|
|
53
|
-
return sourceCode
|
|
54
|
-
.getCommentsBefore(owner)
|
|
55
|
-
.some(
|
|
56
|
-
(comment) => comment.end <= assertion.start && pattern.test(comment.value),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function hasSafetyComment(
|
|
61
|
-
sourceCode: SourceCode,
|
|
62
|
-
node: TypeAssertion,
|
|
63
|
-
pattern: RegExp,
|
|
64
|
-
): boolean {
|
|
65
|
-
let current: ESTree.Node = node;
|
|
66
|
-
while (true) {
|
|
67
|
-
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern)) return true;
|
|
68
|
-
if (commentOwnerKinds.has(current.type)) {
|
|
69
|
-
const exportDeclaration = current.parent;
|
|
70
|
-
return (
|
|
71
|
-
exportDeclaration.type === "ExportNamedDeclaration" &&
|
|
72
|
-
exportDeclaration.declaration === current &&
|
|
73
|
-
hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
if (current.parent.type === "Program") return false;
|
|
77
|
-
current = current.parent;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Require every non-const type assertion to state the invariant TypeScript cannot express. */
|
|
82
|
-
export const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
83
|
-
meta: {
|
|
84
|
-
type: "problem",
|
|
85
|
-
docs: {
|
|
86
|
-
description:
|
|
87
|
-
"Require a nearby SAFETY comment for every TypeScript type assertion except const assertions.",
|
|
88
|
-
},
|
|
89
|
-
messages: {
|
|
90
|
-
missingSafetyComment:
|
|
91
|
-
"This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement.",
|
|
92
|
-
},
|
|
93
|
-
schema: [
|
|
94
|
-
{
|
|
95
|
-
type: "object",
|
|
96
|
-
properties: {
|
|
97
|
-
markers: {
|
|
98
|
-
type: "array",
|
|
99
|
-
items: { type: "string", minLength: 1 },
|
|
100
|
-
minItems: 1,
|
|
101
|
-
uniqueItems: true,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
additionalProperties: false,
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
defaultOptions: [{ markers: ["SAFETY"] }],
|
|
108
|
-
},
|
|
109
|
-
createOnce(context) {
|
|
110
|
-
const patterns = new Map<string, RegExp>();
|
|
111
|
-
|
|
112
|
-
const checkAssertion = (node: TypeAssertion) => {
|
|
113
|
-
if (isConstAssertion(node)) return;
|
|
114
|
-
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
115
|
-
const patternKey = markers.join("\u0000");
|
|
116
|
-
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
117
|
-
patterns.set(patternKey, pattern);
|
|
118
|
-
if (hasSafetyComment(context.sourceCode, node, pattern)) return;
|
|
119
|
-
context.report({
|
|
120
|
-
node,
|
|
121
|
-
messageId: "missingSafetyComment",
|
|
122
|
-
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] },
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
TSAsExpression: checkAssertion,
|
|
128
|
-
TSTypeAssertion: checkAssertion,
|
|
129
|
-
};
|
|
130
|
-
},
|
|
131
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
export type FunctionParameter = ESTree.ParamPattern;
|
|
4
|
-
|
|
5
|
-
/** Return whether a type is or contains TypeScript's absorbing unknown top type. */
|
|
6
|
-
export function containsUnknownType(type: ESTree.TSType): boolean {
|
|
7
|
-
if (type.type === "TSUnknownKeyword") return true;
|
|
8
|
-
if (type.type === "TSParenthesizedType") return containsUnknownType(type.typeAnnotation);
|
|
9
|
-
return type.type === "TSUnionType" && type.types.some(containsUnknownType);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Return the TypeScript annotation attached to a function parameter or its wrapped binding. */
|
|
13
|
-
export function functionParameterTypeAnnotation(
|
|
14
|
-
parameter: FunctionParameter,
|
|
15
|
-
): ESTree.TSTypeAnnotation | null | undefined {
|
|
16
|
-
if (parameter.type === "TSParameterProperty") {
|
|
17
|
-
return functionParameterTypeAnnotation(parameter.parameter);
|
|
18
|
-
}
|
|
19
|
-
if (parameter.type === "RestElement") {
|
|
20
|
-
return parameter.typeAnnotation ?? functionParameterTypeAnnotation(parameter.argument);
|
|
21
|
-
}
|
|
22
|
-
if (parameter.type === "AssignmentPattern") {
|
|
23
|
-
return parameter.typeAnnotation ?? functionParameterTypeAnnotation(parameter.left);
|
|
24
|
-
}
|
|
25
|
-
return parameter.typeAnnotation;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Return only a function parameter's local binding, excluding its annotation and default value. */
|
|
29
|
-
export function functionParameterBindingName(
|
|
30
|
-
parameter: FunctionParameter,
|
|
31
|
-
sourceCode: SourceCode,
|
|
32
|
-
): string {
|
|
33
|
-
if (parameter.type === "TSParameterProperty") {
|
|
34
|
-
return functionParameterBindingName(parameter.parameter, sourceCode);
|
|
35
|
-
}
|
|
36
|
-
if (parameter.type === "AssignmentPattern") {
|
|
37
|
-
return functionParameterBindingName(parameter.left, sourceCode);
|
|
38
|
-
}
|
|
39
|
-
if (parameter.type === "RestElement") {
|
|
40
|
-
return functionParameterBindingName(parameter.argument, sourceCode);
|
|
41
|
-
}
|
|
42
|
-
if (parameter.type === "Identifier") return parameter.name;
|
|
43
|
-
|
|
44
|
-
const sourceText = sourceCode.getText(parameter);
|
|
45
|
-
const annotationStart = parameter.typeAnnotation?.start;
|
|
46
|
-
return annotationStart === undefined
|
|
47
|
-
? sourceText
|
|
48
|
-
: sourceText.slice(0, annotationStart - parameter.start).trimEnd();
|
|
49
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
/** Resolve an identifier to its binding by walking lexical scopes upward. */
|
|
4
|
-
export function resolveVariable(
|
|
5
|
-
sourceCode: SourceCode,
|
|
6
|
-
identifier: ESTree.IdentifierReference,
|
|
7
|
-
): Variable | null {
|
|
8
|
-
let scope: Scope | null = sourceCode.getScope(identifier);
|
|
9
|
-
while (scope !== null) {
|
|
10
|
-
const variable = scope.set.get(identifier.name);
|
|
11
|
-
if (variable !== undefined) return variable;
|
|
12
|
-
scope = scope.upper;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|