@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
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// anti-slop rules from github.com/dmmulroy/anti-slop, MIT, Copyright (c) 2026 Dillon Mulroy. See oxlint/LICENSE.
|
|
2
|
+
|
|
3
|
+
// oxlint/effect/index.ts
|
|
4
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
5
|
+
|
|
6
|
+
// oxlint/effect/rules/no-manual-effect-error-tag.ts
|
|
7
|
+
import { defineRule } from "@oxlint/plugins";
|
|
8
|
+
|
|
9
|
+
// oxlint/effect/shared/tagged-values.ts
|
|
10
|
+
var equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
11
|
+
var broadEffectCatchMethods = new Set(["catch", "catchAll", "catchIf"]);
|
|
12
|
+
var isStringLiteral = (node) => node?.type === "Literal" && typeof node.value === "string";
|
|
13
|
+
var isTagMember = (node) => node?.type === "MemberExpression" && (!node.computed && node.property.type === "Identifier" && node.property.name === "_tag" || node.computed && isStringLiteral(node.property) && node.property.value === "_tag");
|
|
14
|
+
var tagMemberFromComparison = (node) => {
|
|
15
|
+
if (!equalityOperators.has(node.operator))
|
|
16
|
+
return;
|
|
17
|
+
if (isTagMember(node.left) && isStringLiteral(node.right))
|
|
18
|
+
return node.left;
|
|
19
|
+
if (isTagMember(node.right) && isStringLiteral(node.left))
|
|
20
|
+
return node.right;
|
|
21
|
+
return;
|
|
22
|
+
};
|
|
23
|
+
var 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);
|
|
24
|
+
var isInsideBroadEffectHandler = (node) => {
|
|
25
|
+
let current = node.parent;
|
|
26
|
+
while (current !== null && current !== undefined) {
|
|
27
|
+
if (current.type === "ArrowFunctionExpression" || current.type === "FunctionExpression") {
|
|
28
|
+
return isBroadEffectCatchCall(current.parent) && current.parent.arguments.includes(current);
|
|
29
|
+
}
|
|
30
|
+
current = current.parent;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
var 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");
|
|
35
|
+
var propertyName = (property) => {
|
|
36
|
+
if (!property.computed && property.key.type === "Identifier") {
|
|
37
|
+
return property.key.name;
|
|
38
|
+
}
|
|
39
|
+
if (property.key.type === "Literal" && typeof property.key.value === "string") {
|
|
40
|
+
return property.key.value;
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
};
|
|
44
|
+
var isMatchPatternObject = (node) => {
|
|
45
|
+
const call = node.parent;
|
|
46
|
+
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const callee = call.callee;
|
|
50
|
+
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");
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// oxlint/effect/rules/no-manual-effect-error-tag.ts
|
|
54
|
+
var noManualEffectErrorTagRule = defineRule({
|
|
55
|
+
meta: {
|
|
56
|
+
type: "problem",
|
|
57
|
+
docs: {
|
|
58
|
+
description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler."
|
|
59
|
+
},
|
|
60
|
+
messages: {
|
|
61
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
62
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
createOnce(context) {
|
|
66
|
+
return {
|
|
67
|
+
BinaryExpression(node) {
|
|
68
|
+
const tagMember = tagMemberFromComparison(node);
|
|
69
|
+
if (tagMember === undefined || !isInsideBroadEffectHandler(node)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
context.report({
|
|
73
|
+
node,
|
|
74
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag"
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
SwitchStatement(node) {
|
|
78
|
+
if (!isTagMember(node.discriminant) || !isInsideBroadEffectHandler(node)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
context.report({
|
|
82
|
+
node,
|
|
83
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// oxlint/effect/rules/no-manual-tag-comparison.ts
|
|
91
|
+
import { defineRule as defineRule2 } from "@oxlint/plugins";
|
|
92
|
+
var noManualTagComparisonRule = defineRule2({
|
|
93
|
+
meta: {
|
|
94
|
+
type: "problem",
|
|
95
|
+
docs: {
|
|
96
|
+
description: "Use Effect Match or Predicate helpers instead of manually branching on `_tag`."
|
|
97
|
+
},
|
|
98
|
+
messages: {
|
|
99
|
+
manualComparison: "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
100
|
+
manualSwitch: "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`."
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
createOnce(context) {
|
|
104
|
+
return {
|
|
105
|
+
BinaryExpression(node) {
|
|
106
|
+
if (tagMemberFromComparison(node) === undefined || isInsideBroadEffectHandler(node)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
context.report({ node, messageId: "manualComparison" });
|
|
110
|
+
},
|
|
111
|
+
SwitchStatement(node) {
|
|
112
|
+
if (!isTagMember(node.discriminant) || isInsideBroadEffectHandler(node)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
context.report({ node, messageId: "manualSwitch" });
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// oxlint/effect/rules/no-manual-tagged-construction.ts
|
|
122
|
+
import { defineRule as defineRule3 } from "@oxlint/plugins";
|
|
123
|
+
var noManualTaggedConstructionRule = defineRule3({
|
|
124
|
+
meta: {
|
|
125
|
+
type: "problem",
|
|
126
|
+
docs: {
|
|
127
|
+
description: "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually."
|
|
128
|
+
},
|
|
129
|
+
messages: {
|
|
130
|
+
manualConstruction: "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object."
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
createOnce(context) {
|
|
134
|
+
return {
|
|
135
|
+
ObjectExpression(node) {
|
|
136
|
+
if (isMatchPatternObject(node))
|
|
137
|
+
return;
|
|
138
|
+
const tag = node.properties.find((property) => property.type === "Property" && propertyName(property) === "_tag" && isStringLiteral(property.value));
|
|
139
|
+
if (tag !== undefined) {
|
|
140
|
+
context.report({ node: tag, messageId: "manualConstruction" });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// oxlint/effect/rules/no-service-constructor-imports.ts
|
|
148
|
+
import { defineRule as defineRule4 } from "@oxlint/plugins";
|
|
149
|
+
var SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
150
|
+
var TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
151
|
+
function isProjectLocalImport(source) {
|
|
152
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
153
|
+
}
|
|
154
|
+
function getImportedName(specifier) {
|
|
155
|
+
if (specifier.imported.type === "Identifier")
|
|
156
|
+
return specifier.imported.name;
|
|
157
|
+
return specifier.imported.value;
|
|
158
|
+
}
|
|
159
|
+
var noServiceConstructorImportsRule = defineRule4({
|
|
160
|
+
meta: {
|
|
161
|
+
type: "problem",
|
|
162
|
+
docs: {
|
|
163
|
+
description: "Disallow project-local make<CapabilityName> imports outside test and spec files."
|
|
164
|
+
},
|
|
165
|
+
messages: {
|
|
166
|
+
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.'
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
create(context) {
|
|
170
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
171
|
+
return {
|
|
172
|
+
ImportDeclaration(node) {
|
|
173
|
+
if (isTestFile || !isProjectLocalImport(node.source.value))
|
|
174
|
+
return;
|
|
175
|
+
for (const specifier of node.specifiers) {
|
|
176
|
+
if (specifier.type !== "ImportSpecifier")
|
|
177
|
+
continue;
|
|
178
|
+
const importedName = getImportedName(specifier);
|
|
179
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName))
|
|
180
|
+
continue;
|
|
181
|
+
context.report({
|
|
182
|
+
node: specifier,
|
|
183
|
+
messageId: "serviceConstructorImport",
|
|
184
|
+
data: { name: importedName }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// oxlint/effect/rules/prefer-effect-match.ts
|
|
193
|
+
import { defineRule as defineRule5 } from "@oxlint/plugins";
|
|
194
|
+
var equalityOperators2 = new Set(["==", "===", "!=", "!=="]);
|
|
195
|
+
var preferEffectMatchRule = defineRule5({
|
|
196
|
+
meta: {
|
|
197
|
+
type: "problem",
|
|
198
|
+
docs: {
|
|
199
|
+
description: "Use Match from Effect for chained literal ternaries over the same value."
|
|
200
|
+
},
|
|
201
|
+
messages: {
|
|
202
|
+
preferMatch: "Use Match from Effect instead of a chained literal ternary."
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
createOnce(context) {
|
|
206
|
+
const isLiteral = (node) => node.type === "Literal" || node.type === "TemplateLiteral" && node.expressions.length === 0;
|
|
207
|
+
const comparedValue = (node) => {
|
|
208
|
+
if (node.type !== "BinaryExpression" || !equalityOperators2.has(node.operator)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (isLiteral(node.left))
|
|
212
|
+
return context.sourceCode.getText(node.right);
|
|
213
|
+
if (isLiteral(node.right))
|
|
214
|
+
return context.sourceCode.getText(node.left);
|
|
215
|
+
return;
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
ConditionalExpression(node) {
|
|
219
|
+
if (node.parent?.type === "ConditionalExpression")
|
|
220
|
+
return;
|
|
221
|
+
const value = comparedValue(node.test);
|
|
222
|
+
if (value === undefined)
|
|
223
|
+
return;
|
|
224
|
+
let alternate = node.alternate;
|
|
225
|
+
let literalChecks = 1;
|
|
226
|
+
while (alternate.type === "ConditionalExpression") {
|
|
227
|
+
if (comparedValue(alternate.test) !== value)
|
|
228
|
+
return;
|
|
229
|
+
literalChecks += 1;
|
|
230
|
+
alternate = alternate.alternate;
|
|
231
|
+
}
|
|
232
|
+
if (literalChecks > 1) {
|
|
233
|
+
context.report({ node, messageId: "preferMatch" });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// oxlint/effect/index.ts
|
|
241
|
+
var antiSlopEffectPlugin = eslintCompatPlugin({
|
|
242
|
+
meta: { name: "anti-slop-effect" },
|
|
243
|
+
rules: {
|
|
244
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
245
|
+
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
246
|
+
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
247
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
248
|
+
"prefer-effect-match": preferEffectMatchRule
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
var effect_default = antiSlopEffectPlugin;
|
|
252
|
+
export {
|
|
253
|
+
effect_default as default
|
|
254
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// anti-slop rules from github.com/dmmulroy/anti-slop, MIT, Copyright (c) 2026 Dillon Mulroy. See oxlint/LICENSE.
|
|
2
|
+
|
|
3
|
+
// oxlint/index.ts
|
|
4
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
5
|
+
|
|
6
|
+
// oxlint/rules/no-module-mocking.ts
|
|
7
|
+
import { defineRule } from "@oxlint/plugins";
|
|
8
|
+
|
|
9
|
+
// oxlint/shared/scope.ts
|
|
10
|
+
function resolveVariable(sourceCode, identifier) {
|
|
11
|
+
let scope = sourceCode.getScope(identifier);
|
|
12
|
+
while (scope !== null) {
|
|
13
|
+
const variable = scope.set.get(identifier.name);
|
|
14
|
+
if (variable !== undefined)
|
|
15
|
+
return variable;
|
|
16
|
+
scope = scope.upper;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// oxlint/rules/no-module-mocking.ts
|
|
22
|
+
var moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
|
|
23
|
+
function importedName(node) {
|
|
24
|
+
if (node.type !== "ImportSpecifier")
|
|
25
|
+
return null;
|
|
26
|
+
return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
|
|
27
|
+
}
|
|
28
|
+
function isTestFrameworkObject(sourceCode, expression) {
|
|
29
|
+
if (expression.type !== "Identifier")
|
|
30
|
+
return false;
|
|
31
|
+
if ((expression.name === "vi" || expression.name === "jest") && sourceCode.isGlobalReference(expression)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
const variable = resolveVariable(sourceCode, expression);
|
|
35
|
+
if (variable === null || variable.defs.length === 0) {
|
|
36
|
+
return expression.name === "vi" || expression.name === "jest";
|
|
37
|
+
}
|
|
38
|
+
return variable.defs.some((definition) => {
|
|
39
|
+
if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const source = definition.parent.source.value;
|
|
43
|
+
const name = importedName(definition.node);
|
|
44
|
+
return source === "vitest" && name === "vi" || source === "@jest/globals" && name === "jest";
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function moduleMockCall(sourceCode, callee) {
|
|
48
|
+
if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
|
|
49
|
+
return false;
|
|
50
|
+
if (!isTestFrameworkObject(sourceCode, callee.object))
|
|
51
|
+
return false;
|
|
52
|
+
const property = callee.property;
|
|
53
|
+
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;
|
|
54
|
+
return method !== null && moduleMockMethods.has(method);
|
|
55
|
+
}
|
|
56
|
+
var noModuleMockingRule = defineRule({
|
|
57
|
+
meta: {
|
|
58
|
+
type: "problem",
|
|
59
|
+
docs: {
|
|
60
|
+
description: "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces."
|
|
61
|
+
},
|
|
62
|
+
messages: {
|
|
63
|
+
moduleMock: "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation."
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
createOnce(context) {
|
|
67
|
+
return {
|
|
68
|
+
CallExpression(node) {
|
|
69
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
|
|
70
|
+
return;
|
|
71
|
+
if (moduleMockCall(context.sourceCode, node.callee)) {
|
|
72
|
+
context.report({ node, messageId: "moduleMock" });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// oxlint/rules/require-safety-comment-for-type-assertion.ts
|
|
80
|
+
import { defineRule as defineRule2 } from "@oxlint/plugins";
|
|
81
|
+
var DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
82
|
+
var commentOwnerKinds = new Set([
|
|
83
|
+
"ExpressionStatement",
|
|
84
|
+
"PropertyDefinition",
|
|
85
|
+
"ReturnStatement",
|
|
86
|
+
"ThrowStatement",
|
|
87
|
+
"VariableDeclaration"
|
|
88
|
+
]);
|
|
89
|
+
function isConstAssertion(node) {
|
|
90
|
+
return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
|
|
91
|
+
}
|
|
92
|
+
function configuredSafetyMarkers(option) {
|
|
93
|
+
if (typeof option !== "object" || option === null || !("markers" in option)) {
|
|
94
|
+
return DEFAULT_SAFETY_MARKERS;
|
|
95
|
+
}
|
|
96
|
+
const configured = option.markers;
|
|
97
|
+
if (!Array.isArray(configured))
|
|
98
|
+
return DEFAULT_SAFETY_MARKERS;
|
|
99
|
+
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
100
|
+
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
101
|
+
}
|
|
102
|
+
function markerPattern(markers) {
|
|
103
|
+
const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
|
|
104
|
+
return new RegExp(String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
105
|
+
}
|
|
106
|
+
function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
|
|
107
|
+
return sourceCode.getCommentsBefore(owner).some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
108
|
+
}
|
|
109
|
+
function hasSafetyComment(sourceCode, node, pattern) {
|
|
110
|
+
let current = node;
|
|
111
|
+
while (true) {
|
|
112
|
+
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern))
|
|
113
|
+
return true;
|
|
114
|
+
if (commentOwnerKinds.has(current.type)) {
|
|
115
|
+
const exportDeclaration = current.parent;
|
|
116
|
+
return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern);
|
|
117
|
+
}
|
|
118
|
+
if (current.parent.type === "Program")
|
|
119
|
+
return false;
|
|
120
|
+
current = current.parent;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
var requireSafetyCommentForTypeAssertionRule = defineRule2({
|
|
124
|
+
meta: {
|
|
125
|
+
type: "problem",
|
|
126
|
+
docs: {
|
|
127
|
+
description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions."
|
|
128
|
+
},
|
|
129
|
+
messages: {
|
|
130
|
+
missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement."
|
|
131
|
+
},
|
|
132
|
+
schema: [
|
|
133
|
+
{
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
markers: {
|
|
137
|
+
type: "array",
|
|
138
|
+
items: { type: "string", minLength: 1 },
|
|
139
|
+
minItems: 1,
|
|
140
|
+
uniqueItems: true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
additionalProperties: false
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
defaultOptions: [{ markers: ["SAFETY"] }]
|
|
147
|
+
},
|
|
148
|
+
createOnce(context) {
|
|
149
|
+
const patterns = new Map;
|
|
150
|
+
const checkAssertion = (node) => {
|
|
151
|
+
if (isConstAssertion(node))
|
|
152
|
+
return;
|
|
153
|
+
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
154
|
+
const patternKey = markers.join("\x00");
|
|
155
|
+
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
156
|
+
patterns.set(patternKey, pattern);
|
|
157
|
+
if (hasSafetyComment(context.sourceCode, node, pattern))
|
|
158
|
+
return;
|
|
159
|
+
context.report({
|
|
160
|
+
node,
|
|
161
|
+
messageId: "missingSafetyComment",
|
|
162
|
+
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
TSAsExpression: checkAssertion,
|
|
167
|
+
TSTypeAssertion: checkAssertion
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// oxlint/index.ts
|
|
173
|
+
var antiSlopPlugin = eslintCompatPlugin({
|
|
174
|
+
meta: { name: "anti-slop" },
|
|
175
|
+
rules: {
|
|
176
|
+
"no-module-mocking": noModuleMockingRule,
|
|
177
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
var oxlint_default = antiSlopPlugin;
|
|
181
|
+
export {
|
|
182
|
+
oxlint_default as default
|
|
183
|
+
};
|
package/oxlint/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dillon Mulroy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# anti-slop remainder
|
|
2
|
+
|
|
3
|
+
- Source: https://github.com/dmmulroy/anti-slop at `63dbb09` (2026-11-20), `skills/install-anti-slop/assets/anti-slop/`, by Dillon Mulroy under the MIT license in `LICENSE` beside this file. Its rule files are identical to `13909c9`.
|
|
4
|
+
- Only the rules that `@cloudflare/oxlint-config` does not carry and the standard keeps are here, unchanged:
|
|
5
|
+
- `anti-slop` (`index.ts`, published as `@jfalava/ts-standard/oxlint`): `no-module-mocking` and `require-safety-comment-for-type-assertion`, with `shared/scope.ts`. `index.ts` is upstream's with the other rules removed.
|
|
6
|
+
- `anti-slop-effect` (`effect/index.ts`, published as `@jfalava/ts-standard/oxlint/effect`): all five rules and `effect/shared/tagged-values.ts`. `effect/index.ts` is upstream's.
|
|
7
|
+
- Dropped: `no-runtime-typeof`, `no-shape-in-symbol-names` and `no-unknown-parameters`. The other twelve generic rules are in the preset as `quality/*`; `require-readable-spacing` is not kept.
|
|
8
|
+
- None of the five `anti-slop-effect` rules is in the `@effect/tsgo` `recommended` oxlint preset. Its `catch-all-tag-dispatch-to-catch-tag` and `catch-tag-to-catch-reason` flag only catch-all handlers that re-fail unmatched tags, a narrower case than `no-manual-effect-error-tag`.
|
|
9
|
+
- oxlint loads JS plugins in Node, which does not strip types under `node_modules`, so `bun run build:oxlint` bundles each plugin into `dist/oxlint/` for publishing, leaving `@oxlint/plugins` to the consuming repo.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jfalava/ts-standard",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Checks a Bun repo against the TypeScript scripts and workflows standard: package.json scripts, pins, tsconfig and GitHub workflows.",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Checks a Bun repo against the TypeScript scripts and workflows standard: package.json scripts, pins, tsconfig, lint setup and GitHub workflows. Also ships the anti-slop oxlint plugins the standard uses.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,16 +12,22 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"src",
|
|
15
|
-
"reference"
|
|
15
|
+
"reference",
|
|
16
|
+
"dist",
|
|
17
|
+
"oxlint/LICENSE",
|
|
18
|
+
"oxlint/UPSTREAM.md"
|
|
16
19
|
],
|
|
17
20
|
"type": "module",
|
|
18
21
|
"exports": {
|
|
19
|
-
".": "./src/config.ts"
|
|
22
|
+
".": "./src/config.ts",
|
|
23
|
+
"./oxlint": "./dist/oxlint/index.js",
|
|
24
|
+
"./oxlint/effect": "./dist/oxlint/effect/index.js"
|
|
20
25
|
},
|
|
21
26
|
"publishConfig": {
|
|
22
27
|
"access": "public"
|
|
23
28
|
},
|
|
24
29
|
"scripts": {
|
|
30
|
+
"build:oxlint": "bun build oxlint/index.ts oxlint/effect/index.ts --outdir dist/oxlint --target node --format esm --external @oxlint/plugins --banner '// anti-slop rules from github.com/dmmulroy/anti-slop, MIT, Copyright (c) 2026 Dillon Mulroy. See oxlint/LICENSE.'",
|
|
25
31
|
"check": "bun run lint && bun run format:check && bun run typecheck && bun run test && bun run standard:check",
|
|
26
32
|
"fix": "bun run lint:fix && bun run format",
|
|
27
33
|
"format": "oxfmt",
|
|
@@ -42,5 +48,8 @@
|
|
|
42
48
|
"oxlint": "1.95.0",
|
|
43
49
|
"tsrs": "7.1.0-beta.tsrs5"
|
|
44
50
|
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@oxlint/plugins": "^1.95.0"
|
|
53
|
+
},
|
|
45
54
|
"packageManager": "bun@1.4.5"
|
|
46
55
|
}
|
package/src/lint.ts
CHANGED
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
2
|
import { join, relative } from "node:path";
|
|
4
3
|
|
|
5
4
|
import type { Finding } from "./finding.ts";
|
|
6
5
|
import type { Repo } from "./repo.ts";
|
|
7
6
|
|
|
8
7
|
const PRESET = "@cloudflare/oxlint-config";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const filesUnder = (dir: string): string[] =>
|
|
15
|
-
readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
16
|
-
.filter((entry) => entry.isFile())
|
|
17
|
-
.map((entry) => relative(dir, join(entry.parentPath, entry.name)))
|
|
18
|
-
.sort();
|
|
19
|
-
|
|
20
|
-
/** SHA-256 over every file's relative path and bytes, in path order. */
|
|
21
|
-
export const treeHash = (dir: string): string => {
|
|
22
|
-
const hash = createHash("sha256");
|
|
23
|
-
for (const file of filesUnder(dir)) {
|
|
24
|
-
hash.update(`${file}\0`);
|
|
25
|
-
hash.update(readFileSync(join(dir, file)));
|
|
26
|
-
hash.update("\0");
|
|
27
|
-
}
|
|
28
|
-
return hash.digest("hex");
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const ignores = (text: string): boolean =>
|
|
32
|
-
/["'](tools\/\*\*|tools\/oxlint\/anti-slop\/\*\*)["']/.test(text);
|
|
8
|
+
/** The anti-slop rules the preset does not carry, as this package publishes them. */
|
|
9
|
+
const ANTI_SLOP = "@jfalava/ts-standard/oxlint";
|
|
10
|
+
/** Where repos vendored those rules before this package published them. */
|
|
11
|
+
const VENDORED = "tools/oxlint/anti-slop";
|
|
33
12
|
|
|
34
13
|
export const lintRules = (repo: Repo): Finding[] => {
|
|
35
14
|
const out: Finding[] = [];
|
|
@@ -62,12 +41,8 @@ export const lintRules = (repo: Repo): Finding[] => {
|
|
|
62
41
|
"set `categories.correctness`; the preset turns the category off",
|
|
63
42
|
);
|
|
64
43
|
}
|
|
65
|
-
if (!
|
|
66
|
-
f(
|
|
67
|
-
"lint/anti-slop-remainder",
|
|
68
|
-
"oxlint.config.ts",
|
|
69
|
-
`\`ignorePatterns\` lacks \`${REMAINDER}\``,
|
|
70
|
-
);
|
|
44
|
+
if (!text.includes(`"${ANTI_SLOP}"`) && !text.includes(`'${ANTI_SLOP}'`)) {
|
|
45
|
+
f("lint/anti-slop", "oxlint.config.ts", `does not load the \`${ANTI_SLOP}\` plugin`);
|
|
71
46
|
}
|
|
72
47
|
}
|
|
73
48
|
for (const pkg of [repo.rootPkg, ...repo.workspaces]) {
|
|
@@ -81,21 +56,12 @@ export const lintRules = (repo: Repo): Finding[] => {
|
|
|
81
56
|
}
|
|
82
57
|
}
|
|
83
58
|
|
|
84
|
-
|
|
85
|
-
if (!existsSync(remainder)) {
|
|
86
|
-
f("lint/anti-slop-remainder", REMAINDER, "missing");
|
|
87
|
-
} else if (treeHash(remainder) !== treeHash(REFERENCE_REMAINDER)) {
|
|
59
|
+
if (existsSync(join(repo.root, VENDORED))) {
|
|
88
60
|
f(
|
|
89
|
-
"lint/anti-slop
|
|
90
|
-
|
|
91
|
-
|
|
61
|
+
"lint/anti-slop",
|
|
62
|
+
VENDORED,
|
|
63
|
+
`a vendored copy; load \`${ANTI_SLOP}\` (and \`${ANTI_SLOP}/effect\`) and delete it`,
|
|
92
64
|
);
|
|
93
65
|
}
|
|
94
|
-
const oxfmt = OXFMT_CONFIGS.find((name) => existsSync(join(repo.root, name)));
|
|
95
|
-
if (oxfmt === undefined) {
|
|
96
|
-
f("lint/anti-slop-remainder", ".", "no oxfmt config");
|
|
97
|
-
} else if (!ignores(readFileSync(join(repo.root, oxfmt), "utf8"))) {
|
|
98
|
-
f("lint/anti-slop-remainder", oxfmt, `\`ignorePatterns\` lacks \`${REMAINDER}\``);
|
|
99
|
-
}
|
|
100
66
|
return out;
|
|
101
67
|
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# anti-slop remainder
|
|
2
|
-
|
|
3
|
-
- Source: https://github.com/dmmulroy/anti-slop at `63dbb09` (2026-11-20), `skills/install-anti-slop/assets/anti-slop/`. Its rule files are identical to `13909c9`.
|
|
4
|
-
- Only the rules that `@cloudflare/oxlint-config` does not carry are vendored, unchanged:
|
|
5
|
-
- `anti-slop`: `no-module-mocking`, `no-runtime-typeof`, `no-shape-in-symbol-names`, `no-unknown-parameters`, `require-safety-comment-for-type-assertion`, with `shared/function-parameters.ts` and `shared/scope.ts`.
|
|
6
|
-
- `anti-slop-effect`: all five rules and `effect/shared/tagged-values.ts`. `effect/index.ts` is upstream's.
|
|
7
|
-
- `index.ts` is upstream's with the other rules removed. The other twelve generic rules are in the preset as `quality/*`; `require-readable-spacing` is not kept.
|
|
8
|
-
- This directory is the same in every repo that follows the TypeScript scripts and workflows standard. Change it in all of them at once.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.ts";
|
|
4
|
-
import { noManualTagComparisonRule } from "./rules/no-manual-tag-comparison.ts";
|
|
5
|
-
import { noManualTaggedConstructionRule } from "./rules/no-manual-tagged-construction.ts";
|
|
6
|
-
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.ts";
|
|
7
|
-
import { preferEffectMatchRule } from "./rules/prefer-effect-match.ts";
|
|
8
|
-
|
|
9
|
-
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
10
|
-
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
11
|
-
meta: { name: "anti-slop-effect" },
|
|
12
|
-
rules: {
|
|
13
|
-
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
14
|
-
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
15
|
-
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
16
|
-
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
17
|
-
"prefer-effect-match": preferEffectMatchRule,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export default antiSlopEffectPlugin;
|