@hailstails/hone 1.2.0 → 1.4.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/ADOPTING.md +6 -6
- package/CHANGELOG.md +38 -0
- package/MIGRATING.md +28 -5
- package/README.md +41 -14
- package/api/audit.d.ts +1 -1
- package/api/testing.js +3 -3
- package/chunks/chunk-335ITLPO.js +7 -0
- package/chunks/{chunk-5VXHQC4A.js → chunk-6SM3HKWO.js} +302 -637
- package/chunks/{chunk-PL2PNPAR.js → chunk-E6VR3VRV.js} +1 -6
- package/chunks/{chunk-H4V72FCW.js → chunk-FEWCJU7H.js} +9 -1
- package/chunks/chunk-WF3PPYRR.js +27 -0
- package/core/check/tool-command.js +797 -88
- package/core/mechanism-port/runner-result-types.d.ts +6 -0
- package/docs/adding-a-discipline-or-mechanism.md +4 -4
- package/docs/extending.md +5 -5
- package/docs/output-contract.md +60 -14
- package/mechanisms/audit/CD-27/test-body-logic.js +394 -46
- package/mechanisms/audit/runner/runner.js +1 -1
- package/mechanisms/audit/runner/typescript-parse.d.ts +2 -0
- package/mechanisms/audit/runner/walker-piece.d.ts +2 -1
- package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +7 -4
- package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +21 -11
- package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +15 -5
- package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +7 -3
- package/mechanisms/eslint/CD-41/README.md +1 -1
- package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +100 -28
- package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +8 -4
- package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +8 -4
- package/mechanisms/eslint/runner/README.md +10 -3
- package/mechanisms/eslint/runner/runner.js +1410 -1351
- package/methods/lenses/di-discipline.md +4 -5
- package/methods/lenses/test-discipline.md +1 -1
- package/package.json +1 -1
- package/rules/CD-1/CHECKS.md +2 -0
- package/rules/CD-10/CHECKS.md +2 -2
- package/rules/CD-12/README.md +1 -1
- package/rules/CD-14/CHECKS.md +2 -2
- package/rules/CD-15/CHECKS.md +4 -2
- package/rules/CD-17/CHECKS.md +2 -2
- package/rules/CD-17/README.md +3 -3
- package/rules/CD-19/CHECKS.md +2 -2
- package/rules/CD-2/CHECKS.md +4 -2
- package/rules/CD-23/CHECKS.md +2 -2
- package/rules/CD-25/CHECKS.md +3 -3
- package/rules/CD-25/README.md +3 -3
- package/rules/CD-26/CHECKS.md +2 -2
- package/rules/CD-27/CHECKS.md +384 -8
- package/rules/CD-27/README.md +1 -1
- package/rules/CD-27/discipline.json +130 -0
- package/rules/CD-3/CHECKS.md +2 -2
- package/rules/CD-40/CHECKS.md +2 -2
- package/rules/CD-41/CHECKS.md +12 -2
- package/rules/CD-41/README.md +2 -0
- package/rules/CD-41/discipline.json +14 -0
- package/rules/CD-42/CHECKS.md +2 -2
- package/rules/CD-43/CHECKS.md +2 -2
- package/rules/CD-44/CHECKS.md +2 -2
- package/rules/CD-47/CHECKS.md +2 -2
- package/rules/CD-5/CHECKS.md +2 -2
- package/rules/CD-6/CHECKS.md +2 -2
- package/rules/CD-7/CHECKS.md +2 -2
- package/rules/CD-7a/CHECKS.md +2 -2
- package/rules/CD-8/CHECKS.md +2 -2
- package/chunks/chunk-YLZ73C7O.js +0 -0
|
@@ -16,28 +16,108 @@ var testFileEligibility = (request) => {
|
|
|
16
16
|
return request.file.endsWith(".test.ts") || request.file.endsWith(".test.tsx") ? "eligible" : "skipped";
|
|
17
17
|
};
|
|
18
18
|
var SECOND_EDITION = editionSchema.parse("2");
|
|
19
|
-
var
|
|
19
|
+
var ALLOWED_FORMS_PAGE = "CHECKS.md";
|
|
20
|
+
var onAllowedFormsPage = (section) => ({ fix: section.fix, page: ALLOWED_FORMS_PAGE, section: section.section });
|
|
21
|
+
var firstEdition = (section) => ({ introducedIn: FIRST_EDITION, remedy: onAllowedFormsPage(section) });
|
|
22
|
+
var secondEdition = (section) => ({ introducedIn: SECOND_EDITION, remedy: onAllowedFormsPage(section) });
|
|
23
|
+
var BRANCHING = firstEdition({
|
|
24
|
+
fix: "write one test per case, or one it.each table; to narrow a value that may be missing, assert.isDefined it",
|
|
25
|
+
section: "branching-with-if"
|
|
26
|
+
});
|
|
27
|
+
var TRY_BLOCK = firstEdition({
|
|
28
|
+
fix: "assert the throw with expect(() => act()).toThrow or await expect(act()).rejects, or assert the failure the unit returns",
|
|
29
|
+
section: "a-try-block"
|
|
30
|
+
});
|
|
31
|
+
var TERNARY = firstEdition({ fix: "write the value out, or give each case its own it.each row", section: "a-ternary" });
|
|
32
|
+
var LET = firstEdition({ fix: "use const; record calls with vi.fn and assert them with toHaveBeenCalledWith", section: "a-let" });
|
|
33
|
+
var PICKING_METHOD = firstEdition({
|
|
34
|
+
fix: "assert on the whole array with toEqual, toContain, toContainEqual or expect.arrayContaining",
|
|
35
|
+
section: "a-method-that-picks-or-tests-an-element"
|
|
36
|
+
});
|
|
37
|
+
var COMPUTING_METHOD = firstEdition({
|
|
38
|
+
fix: "write the expected value out, or match part of it with toMatchObject, toHaveLength or expect.stringContaining",
|
|
39
|
+
section: "a-method-that-computes-a-value"
|
|
40
|
+
});
|
|
41
|
+
var MUTATING_METHOD = firstEdition({ fix: "write the finished array out as a literal", section: "a-method-that-mutates" });
|
|
42
|
+
var SHORT_CIRCUIT = secondEdition({
|
|
43
|
+
fix: "write the value it gives; to narrow a value that may be missing, assert.isDefined it",
|
|
44
|
+
section: "a-short-circuit"
|
|
45
|
+
});
|
|
46
|
+
var INDEXED_OPTIONAL_CHAIN = secondEdition({
|
|
47
|
+
fix: "compare the whole element with toMatchObject, or destructure it and assert.isDefined it before reading it",
|
|
48
|
+
section: "an-optional-chain-after-an-index"
|
|
49
|
+
});
|
|
50
|
+
var MOCK_CALL_OPTIONAL_CHAIN = secondEdition({
|
|
51
|
+
fix: "assert the call with toHaveBeenNthCalledWith or toHaveBeenLastCalledWith",
|
|
52
|
+
section: "an-optional-chain-on-a-mock-call"
|
|
53
|
+
});
|
|
54
|
+
var MOCK_RESULT_OPTIONAL_CHAIN = secondEdition({
|
|
55
|
+
fix: "assert what it returned with toHaveNthReturnedWith or toHaveLastReturnedWith",
|
|
56
|
+
section: "an-optional-chain-on-a-mock-result"
|
|
57
|
+
});
|
|
58
|
+
var PROPERTY_OPTIONAL_CHAIN = secondEdition({
|
|
59
|
+
fix: "compare the whole value with toMatchObject, or destructure it and assert.isDefined it before reading it",
|
|
60
|
+
section: "an-optional-chain-on-a-property"
|
|
61
|
+
});
|
|
62
|
+
var OPTIONAL_CALL = secondEdition({ fix: "assert.isDefined the function, then call it", section: "an-optional-call" });
|
|
63
|
+
var SWITCH = secondEdition({ fix: "write one test per case, or one it.each table", section: "a-switch" });
|
|
64
|
+
var JSON_CALL = secondEdition({ fix: "CD-19 is the rule for the runtime's standard library", section: "serialising-or-parsing-json" });
|
|
65
|
+
var OBJECT_ASSIGN = secondEdition({ fix: "write the object out, spreading what it copies; to give an Error a property, assign it", section: "merging-objects" });
|
|
66
|
+
var OBJECT_FROM_ENTRIES = secondEdition({ fix: "write the object out as a literal", section: "building-an-object-from-entries" });
|
|
67
|
+
var ARRAY_FROM = secondEdition({ fix: "write a short array out as a literal; the page shows no form for a long one", section: "building-an-array-from-a-length" });
|
|
68
|
+
var MATH_CALL = secondEdition({ fix: "write the number out", section: "a-math-call" });
|
|
69
|
+
var PASSED_ON_FUNCTION = onAllowedFormsPage({
|
|
70
|
+
fix: "make it a vi.fn spy with a written-out mockReturnValue, and assert what it was asked with toHaveBeenCalledExactlyOnceWith; CD-25 is the rule for test doubles",
|
|
71
|
+
section: "logic-inside-a-function-the-test-passes-on"
|
|
72
|
+
});
|
|
73
|
+
var FORMS_IN_PAGE_ORDER = [
|
|
74
|
+
BRANCHING,
|
|
75
|
+
TRY_BLOCK,
|
|
76
|
+
TERNARY,
|
|
77
|
+
LET,
|
|
78
|
+
PICKING_METHOD,
|
|
79
|
+
COMPUTING_METHOD,
|
|
80
|
+
MUTATING_METHOD,
|
|
81
|
+
SHORT_CIRCUIT,
|
|
82
|
+
INDEXED_OPTIONAL_CHAIN,
|
|
83
|
+
MOCK_CALL_OPTIONAL_CHAIN,
|
|
84
|
+
MOCK_RESULT_OPTIONAL_CHAIN,
|
|
85
|
+
PROPERTY_OPTIONAL_CHAIN,
|
|
86
|
+
OPTIONAL_CALL,
|
|
87
|
+
SWITCH,
|
|
88
|
+
JSON_CALL,
|
|
89
|
+
OBJECT_ASSIGN,
|
|
90
|
+
OBJECT_FROM_ENTRIES,
|
|
91
|
+
ARRAY_FROM,
|
|
92
|
+
MATH_CALL
|
|
93
|
+
];
|
|
94
|
+
var TEST_BODY_REMEDIES = [...FORMS_IN_PAGE_ORDER.map((form) => form.remedy), PASSED_ON_FUNCTION];
|
|
95
|
+
var TEST_BODY_SECTIONS = TEST_BODY_REMEDIES.map((remedy) => remedy.section);
|
|
96
|
+
var PICKING_METHODS = [
|
|
20
97
|
"at",
|
|
21
|
-
"charAt",
|
|
22
|
-
"charCodeAt",
|
|
23
|
-
"codePointAt",
|
|
24
|
-
"concat",
|
|
25
|
-
"endsWith",
|
|
26
|
-
"entries",
|
|
27
98
|
"every",
|
|
28
99
|
"filter",
|
|
29
100
|
"find",
|
|
30
101
|
"findIndex",
|
|
31
102
|
"findLast",
|
|
32
103
|
"findLastIndex",
|
|
104
|
+
"includes",
|
|
105
|
+
"indexOf",
|
|
106
|
+
"lastIndexOf",
|
|
107
|
+
"some"
|
|
108
|
+
];
|
|
109
|
+
var COMPUTING_METHODS = [
|
|
110
|
+
"charAt",
|
|
111
|
+
"charCodeAt",
|
|
112
|
+
"codePointAt",
|
|
113
|
+
"concat",
|
|
114
|
+
"endsWith",
|
|
115
|
+
"entries",
|
|
33
116
|
"flat",
|
|
34
117
|
"flatMap",
|
|
35
118
|
"forEach",
|
|
36
|
-
"includes",
|
|
37
|
-
"indexOf",
|
|
38
119
|
"join",
|
|
39
120
|
"keys",
|
|
40
|
-
"lastIndexOf",
|
|
41
121
|
"localeCompare",
|
|
42
122
|
"map",
|
|
43
123
|
"match",
|
|
@@ -52,7 +132,6 @@ var BANNED_DYNAMIC_METHODS = [
|
|
|
52
132
|
"replaceAll",
|
|
53
133
|
"search",
|
|
54
134
|
"slice",
|
|
55
|
-
"some",
|
|
56
135
|
"sort",
|
|
57
136
|
"split",
|
|
58
137
|
"startsWith",
|
|
@@ -71,21 +150,15 @@ var BANNED_DYNAMIC_METHODS = [
|
|
|
71
150
|
"values",
|
|
72
151
|
"with"
|
|
73
152
|
];
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
["JSON",
|
|
78
|
-
["Object
|
|
79
|
-
["
|
|
80
|
-
["
|
|
153
|
+
var MUTATING_METHODS = ["copyWithin", "fill", "pop", "push", "reverse", "shift", "splice", "unshift"];
|
|
154
|
+
var NAMESPACE_CALLS = /* @__PURE__ */ new Map([
|
|
155
|
+
["JSON.stringify", JSON_CALL],
|
|
156
|
+
["JSON.parse", JSON_CALL],
|
|
157
|
+
["Object.assign", OBJECT_ASSIGN],
|
|
158
|
+
["Object.fromEntries", OBJECT_FROM_ENTRIES],
|
|
159
|
+
["Array.from", ARRAY_FROM]
|
|
81
160
|
]);
|
|
82
|
-
var
|
|
83
|
-
const { syntaxApi, node } = request;
|
|
84
|
-
const isStructural = syntaxApi.isIfStatement(node) || syntaxApi.isTryStatement(node) || syntaxApi.isConditionalExpression(node) || syntaxApi.isVariableStatement(node) && (node.declarationList.flags & syntaxApi.NodeFlags.Let) === syntaxApi.NodeFlags.Let;
|
|
85
|
-
const methodName = syntaxApi.isCallExpression(node) && syntaxApi.isPropertyAccessExpression(node.expression) ? node.expression.name.text : void 0;
|
|
86
|
-
return isStructural || methodName !== void 0 && (BANNED_DYNAMIC_METHODS.includes(methodName) || BANNED_MUTATION_METHODS.includes(methodName)) ? "logic" : "plain";
|
|
87
|
-
};
|
|
88
|
-
var shortCircuitOperators = (request) => [
|
|
161
|
+
var SHORT_CIRCUIT_TOKENS = (request) => [
|
|
89
162
|
request.syntaxApi.SyntaxKind.QuestionQuestionToken,
|
|
90
163
|
request.syntaxApi.SyntaxKind.BarBarToken,
|
|
91
164
|
request.syntaxApi.SyntaxKind.AmpersandAmpersandToken,
|
|
@@ -93,25 +166,297 @@ var shortCircuitOperators = (request) => [
|
|
|
93
166
|
request.syntaxApi.SyntaxKind.BarBarEqualsToken,
|
|
94
167
|
request.syntaxApi.SyntaxKind.AmpersandAmpersandEqualsToken
|
|
95
168
|
];
|
|
96
|
-
var
|
|
169
|
+
var mockRecordNamed = (request) => {
|
|
170
|
+
const { syntaxApi, node } = request;
|
|
171
|
+
const isMockProperty = syntaxApi.isPropertyAccessExpression(node) && syntaxApi.isPropertyAccessExpression(node.expression) && node.expression.name.text === "mock";
|
|
172
|
+
if (!isMockProperty) return "other";
|
|
173
|
+
if (node.name.text === "calls") return "calls";
|
|
174
|
+
return node.name.text === "results" ? "results" : "other";
|
|
175
|
+
};
|
|
176
|
+
var mockRecordReading = (request) => {
|
|
177
|
+
const { syntaxApi, node } = request;
|
|
178
|
+
const readsLastCall = syntaxApi.isPropertyAccessExpression(node) && node.name.text === "lastCall" && syntaxApi.isPropertyAccessExpression(node.expression) && node.expression.name.text === "mock";
|
|
179
|
+
if (readsLastCall) return "calls";
|
|
180
|
+
return syntaxApi.isElementAccessExpression(node) ? mockRecordNamed({ syntaxApi, node: node.expression }) : "other";
|
|
181
|
+
};
|
|
182
|
+
var statementForm = (request) => {
|
|
183
|
+
const { syntaxApi, node } = request;
|
|
184
|
+
if (syntaxApi.isIfStatement(node)) return BRANCHING;
|
|
185
|
+
if (syntaxApi.isTryStatement(node)) return TRY_BLOCK;
|
|
186
|
+
if (syntaxApi.isSwitchStatement(node)) return SWITCH;
|
|
187
|
+
const isLet = syntaxApi.isVariableStatement(node) && (node.declarationList.flags & syntaxApi.NodeFlags.Let) === syntaxApi.NodeFlags.Let;
|
|
188
|
+
return isLet ? LET : void 0;
|
|
189
|
+
};
|
|
190
|
+
var methodForm = (request) => {
|
|
191
|
+
if (PICKING_METHODS.includes(request.name)) return PICKING_METHOD;
|
|
192
|
+
if (COMPUTING_METHODS.includes(request.name)) return COMPUTING_METHOD;
|
|
193
|
+
return MUTATING_METHODS.includes(request.name) ? MUTATING_METHOD : void 0;
|
|
194
|
+
};
|
|
195
|
+
var namespaceForm = (request) => {
|
|
196
|
+
if (!request.syntaxApi.isIdentifier(request.node)) return void 0;
|
|
197
|
+
if (request.node.text === "Math") return MATH_CALL;
|
|
198
|
+
return NAMESPACE_CALLS.get(`${request.node.text}.${request.name}`);
|
|
199
|
+
};
|
|
200
|
+
var BUILT_IN_NAMESPACES = [
|
|
201
|
+
"Array",
|
|
202
|
+
"Atomics",
|
|
203
|
+
"Buffer",
|
|
204
|
+
"Date",
|
|
205
|
+
"Intl",
|
|
206
|
+
"JSON",
|
|
207
|
+
"Map",
|
|
208
|
+
"Math",
|
|
209
|
+
"Number",
|
|
210
|
+
"Object",
|
|
211
|
+
"Promise",
|
|
212
|
+
"Reflect",
|
|
213
|
+
"Set",
|
|
214
|
+
"String",
|
|
215
|
+
"Symbol",
|
|
216
|
+
"URL",
|
|
217
|
+
"URLSearchParams",
|
|
218
|
+
"console",
|
|
219
|
+
"crypto",
|
|
220
|
+
"globalThis",
|
|
221
|
+
"performance",
|
|
222
|
+
"process"
|
|
223
|
+
];
|
|
224
|
+
var MOST_ARGUMENTS = new Map([
|
|
225
|
+
...["keys", "values", "entries", "pop", "shift", "reverse", "toReversed", "trim", "trimStart", "trimEnd", "toLowerCase", "toUpperCase"].map((name) => [name, 0]),
|
|
226
|
+
...[
|
|
227
|
+
"join",
|
|
228
|
+
"at",
|
|
229
|
+
"charAt",
|
|
230
|
+
"charCodeAt",
|
|
231
|
+
"codePointAt",
|
|
232
|
+
"flat",
|
|
233
|
+
"sort",
|
|
234
|
+
"toSorted",
|
|
235
|
+
"repeat",
|
|
236
|
+
"normalize",
|
|
237
|
+
"toLocaleLowerCase",
|
|
238
|
+
"toLocaleUpperCase",
|
|
239
|
+
"match",
|
|
240
|
+
"matchAll",
|
|
241
|
+
"search"
|
|
242
|
+
].map((name) => [name, 1]),
|
|
243
|
+
...[
|
|
244
|
+
"split",
|
|
245
|
+
"slice",
|
|
246
|
+
"substring",
|
|
247
|
+
"substr",
|
|
248
|
+
"padStart",
|
|
249
|
+
"padEnd",
|
|
250
|
+
"startsWith",
|
|
251
|
+
"endsWith",
|
|
252
|
+
"replace",
|
|
253
|
+
"replaceAll",
|
|
254
|
+
"map",
|
|
255
|
+
"filter",
|
|
256
|
+
"find",
|
|
257
|
+
"findIndex",
|
|
258
|
+
"findLast",
|
|
259
|
+
"findLastIndex",
|
|
260
|
+
"every",
|
|
261
|
+
"some",
|
|
262
|
+
"forEach",
|
|
263
|
+
"flatMap",
|
|
264
|
+
"reduce",
|
|
265
|
+
"reduceRight",
|
|
266
|
+
"with"
|
|
267
|
+
].map((name) => [name, 2]),
|
|
268
|
+
...["includes", "indexOf", "lastIndexOf", "copyWithin", "localeCompare"].map((name) => [name, 3]),
|
|
269
|
+
["fill", 4]
|
|
270
|
+
]);
|
|
271
|
+
var CALLBACK_METHODS_TAKING_THIS = [
|
|
272
|
+
"every",
|
|
273
|
+
"filter",
|
|
274
|
+
"find",
|
|
275
|
+
"findIndex",
|
|
276
|
+
"findLast",
|
|
277
|
+
"findLastIndex",
|
|
278
|
+
"flatMap",
|
|
279
|
+
"forEach",
|
|
280
|
+
"map",
|
|
281
|
+
"some"
|
|
282
|
+
];
|
|
283
|
+
var SYMBOL_PROTOCOL_METHODS = ["match", "matchAll", "replace", "replaceAll", "search", "split"];
|
|
284
|
+
var OBJECT_POSITIONS = new Map([
|
|
285
|
+
...CALLBACK_METHODS_TAKING_THIS.map((name) => [name, { at: [1] }]),
|
|
286
|
+
...SYMBOL_PROTOCOL_METHODS.map((name) => [name, { at: [0] }]),
|
|
287
|
+
["includes", { at: [0] }],
|
|
288
|
+
["indexOf", { at: [0] }],
|
|
289
|
+
["lastIndexOf", { at: [0] }],
|
|
290
|
+
["fill", { at: [0] }],
|
|
291
|
+
["reduce", { at: [1] }],
|
|
292
|
+
["reduceRight", { at: [1] }],
|
|
293
|
+
["with", { at: [1] }],
|
|
294
|
+
["localeCompare", { at: [2] }],
|
|
295
|
+
["splice", { from: 2 }],
|
|
296
|
+
["toSpliced", { from: 2 }],
|
|
297
|
+
["push", { from: 0 }],
|
|
298
|
+
["unshift", { from: 0 }],
|
|
299
|
+
["concat", { from: 0 }]
|
|
300
|
+
]);
|
|
301
|
+
var objectFitsBuiltIn = (request) => {
|
|
302
|
+
const positions = OBJECT_POSITIONS.get(request.name);
|
|
303
|
+
if (positions === void 0) return "never-fits";
|
|
304
|
+
const fits = "from" in positions ? request.position >= positions.from : positions.at.includes(request.position);
|
|
305
|
+
return fits ? "fits" : "never-fits";
|
|
306
|
+
};
|
|
307
|
+
var moduleTarget = (request) => request.specifier.startsWith(".") ? "own-api" : "built-in-or-library";
|
|
308
|
+
var loadedModuleOf = (request) => {
|
|
309
|
+
const { syntaxApi, node } = request;
|
|
310
|
+
if (!syntaxApi.isCallExpression(node)) return void 0;
|
|
311
|
+
const loads = node.expression.kind === syntaxApi.SyntaxKind.ImportKeyword || syntaxApi.isIdentifier(node.expression) && node.expression.text === "require";
|
|
312
|
+
const [specifier] = node.arguments;
|
|
313
|
+
return loads && specifier !== void 0 && syntaxApi.isStringLiteralLike(specifier) ? specifier.text : void 0;
|
|
314
|
+
};
|
|
315
|
+
var bindsName = (request) => {
|
|
316
|
+
const { syntaxApi, binding, name } = request;
|
|
317
|
+
if (syntaxApi.isIdentifier(binding)) return binding.text === name ? "binds" : "other";
|
|
318
|
+
if (!syntaxApi.isObjectBindingPattern(binding) && !syntaxApi.isArrayBindingPattern(binding)) return "other";
|
|
319
|
+
const binds = binding.elements.some((element) => syntaxApi.isBindingElement(element) && bindsName({ syntaxApi, binding: element.name, name }) === "binds");
|
|
320
|
+
return binds ? "binds" : "other";
|
|
321
|
+
};
|
|
322
|
+
var declarationsNamed = (request) => {
|
|
323
|
+
const { syntaxApi, name } = request;
|
|
324
|
+
const declarations = [];
|
|
325
|
+
const visit = (node) => {
|
|
326
|
+
const declares = syntaxApi.isVariableDeclaration(node) && bindsName({ syntaxApi, binding: node.name, name }) === "binds" || syntaxApi.isImportEqualsDeclaration(node) && node.name.text === name;
|
|
327
|
+
if (declares) declarations.push(node);
|
|
328
|
+
syntaxApi.forEachChild(node, visit);
|
|
329
|
+
};
|
|
330
|
+
visit(request.node.getSourceFile());
|
|
331
|
+
return declarations;
|
|
332
|
+
};
|
|
333
|
+
var declarationTarget = (request) => {
|
|
334
|
+
const { syntaxApi, node, visited } = request;
|
|
335
|
+
if (syntaxApi.isImportEqualsDeclaration(node)) {
|
|
336
|
+
const reference = node.moduleReference;
|
|
337
|
+
return syntaxApi.isExternalModuleReference(reference) && syntaxApi.isStringLiteralLike(reference.expression) ? moduleTarget({ specifier: reference.expression.text }) : "own-api";
|
|
338
|
+
}
|
|
339
|
+
if (!syntaxApi.isVariableDeclaration(node) || node.initializer === void 0) return "own-api";
|
|
340
|
+
return originTarget({ syntaxApi, node: node.initializer, visited });
|
|
341
|
+
};
|
|
342
|
+
var nameTarget = (request) => {
|
|
343
|
+
const { syntaxApi, node, name, visited } = request;
|
|
344
|
+
if (visited.includes(name)) return "own-api";
|
|
345
|
+
if (BUILT_IN_NAMESPACES.includes(name) || packageBindingsOf({ syntaxApi, node }).includes(name)) return "built-in-or-library";
|
|
346
|
+
const fromLibrary = declarationsNamed({ syntaxApi, node, name }).some((declaration) => declarationTarget({ syntaxApi, node: declaration, visited: [...visited, name] }) === "built-in-or-library");
|
|
347
|
+
return fromLibrary ? "built-in-or-library" : "own-api";
|
|
348
|
+
};
|
|
349
|
+
var memberTarget = (request) => {
|
|
350
|
+
const { syntaxApi, member, visited } = request;
|
|
351
|
+
if (syntaxApi.isShorthandPropertyAssignment(member)) {
|
|
352
|
+
return nameTarget({ syntaxApi, node: member, name: member.name.text, visited });
|
|
353
|
+
}
|
|
354
|
+
return syntaxApi.isPropertyAssignment(member) ? originTarget({ syntaxApi, node: member.initializer, visited }) : "own-api";
|
|
355
|
+
};
|
|
356
|
+
var heldMembersNamed = (request) => {
|
|
357
|
+
const { syntaxApi, holder, member } = request;
|
|
358
|
+
return declarationsNamed({ syntaxApi, node: request.node, name: holder }).flatMap((declaration) => {
|
|
359
|
+
if (!syntaxApi.isVariableDeclaration(declaration) || !syntaxApi.isIdentifier(declaration.name)) return [];
|
|
360
|
+
const { initializer } = declaration;
|
|
361
|
+
if (initializer === void 0 || !syntaxApi.isObjectLiteralExpression(initializer)) return [];
|
|
362
|
+
return initializer.properties.filter((property) => property.name !== void 0 && syntaxApi.isIdentifier(property.name) && property.name.text === member);
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
var heldValueTarget = (request) => {
|
|
366
|
+
const { syntaxApi, node, visited } = request;
|
|
367
|
+
if (!syntaxApi.isPropertyAccessExpression(node) || !syntaxApi.isIdentifier(node.expression)) return void 0;
|
|
368
|
+
const members = heldMembersNamed({ syntaxApi, node, holder: node.expression.text, member: node.name.text });
|
|
369
|
+
if (members.length === 0) return void 0;
|
|
370
|
+
const fromLibrary = members.some((member) => memberTarget({ syntaxApi, node, member, visited }) === "built-in-or-library");
|
|
371
|
+
return fromLibrary ? "built-in-or-library" : "own-api";
|
|
372
|
+
};
|
|
373
|
+
var originTarget = (request) => {
|
|
374
|
+
const { syntaxApi, node, visited } = request;
|
|
375
|
+
const loadedModule = loadedModuleOf({ syntaxApi, node });
|
|
376
|
+
if (loadedModule !== void 0) return moduleTarget({ specifier: loadedModule });
|
|
377
|
+
const held = heldValueTarget(request);
|
|
378
|
+
if (held !== void 0) return held;
|
|
379
|
+
if (syntaxApi.isIdentifier(node)) return nameTarget({ syntaxApi, node, name: node.text, visited });
|
|
380
|
+
if (syntaxApi.isStringLiteralLike(node) || syntaxApi.isArrayLiteralExpression(node) || syntaxApi.isTemplateExpression(node)) {
|
|
381
|
+
return "built-in-or-library";
|
|
382
|
+
}
|
|
383
|
+
const isChain = syntaxApi.isPropertyAccessExpression(node) || syntaxApi.isElementAccessExpression(node) || syntaxApi.isCallExpression(node) || syntaxApi.isParenthesizedExpression(node) || syntaxApi.isNonNullExpression(node) || syntaxApi.isAwaitExpression(node) || syntaxApi.isAsExpression(node) || syntaxApi.isSatisfiesExpression(node);
|
|
384
|
+
return isChain ? originTarget({ syntaxApi, node: node.expression, visited }) : "own-api";
|
|
385
|
+
};
|
|
386
|
+
var packageBindingsOf = (request) => request.node.getSourceFile().statements.flatMap((statement) => {
|
|
387
|
+
const { syntaxApi } = request;
|
|
388
|
+
if (!syntaxApi.isImportDeclaration(statement) || !syntaxApi.isStringLiteral(statement.moduleSpecifier)) return [];
|
|
389
|
+
if (statement.moduleSpecifier.text.startsWith(".") || statement.importClause === void 0) return [];
|
|
390
|
+
const { name, namedBindings } = statement.importClause;
|
|
391
|
+
const named = namedBindings === void 0 ? [] : syntaxApi.isNamespaceImport(namedBindings) ? [namedBindings.name.text] : namedBindings.elements.map((element) => element.name.text);
|
|
392
|
+
return name === void 0 ? named : [name.text, ...named];
|
|
393
|
+
});
|
|
394
|
+
var argumentsTarget = (request) => {
|
|
395
|
+
const { syntaxApi, call, name } = request;
|
|
396
|
+
if (call.arguments.some((argument) => syntaxApi.isSpreadElement(argument))) return "built-in-or-library";
|
|
397
|
+
const mostArguments = MOST_ARGUMENTS.get(name);
|
|
398
|
+
if (mostArguments !== void 0 && call.arguments.length > mostArguments) return "own-api";
|
|
399
|
+
const objectNoBuiltInTakes = call.arguments.some((argument, position) => syntaxApi.isObjectLiteralExpression(argument) && objectFitsBuiltIn({ name, position }) === "never-fits");
|
|
400
|
+
return objectNoBuiltInTakes ? "own-api" : "built-in-or-library";
|
|
401
|
+
};
|
|
402
|
+
var callTargetOf = (request) => {
|
|
403
|
+
const { syntaxApi, call, method } = request;
|
|
404
|
+
if (originTarget({ syntaxApi, node: method.expression, visited: [] }) === "built-in-or-library") return "built-in-or-library";
|
|
405
|
+
return argumentsTarget({ syntaxApi, call, name: method.name.text });
|
|
406
|
+
};
|
|
407
|
+
var listedMethodForm = (request) => {
|
|
408
|
+
const form = methodForm({ name: request.method.name.text });
|
|
409
|
+
if (form === void 0) return void 0;
|
|
410
|
+
return callTargetOf(request) === "own-api" ? void 0 : form;
|
|
411
|
+
};
|
|
412
|
+
var callForm = (request) => {
|
|
413
|
+
const { syntaxApi, node } = request;
|
|
414
|
+
if (!syntaxApi.isCallExpression(node)) return void 0;
|
|
415
|
+
const calledForm = syntaxApi.isPropertyAccessExpression(node.expression) ? listedMethodForm({ syntaxApi, call: node, method: node.expression }) ?? namespaceForm({ syntaxApi, node: node.expression.expression, name: node.expression.name.text }) : void 0;
|
|
416
|
+
return calledForm ?? (node.questionDotToken === void 0 ? void 0 : OPTIONAL_CALL);
|
|
417
|
+
};
|
|
418
|
+
var optionalChainForm = (request) => {
|
|
419
|
+
const { syntaxApi, node } = request;
|
|
420
|
+
const isOptionalAccess = (syntaxApi.isPropertyAccessExpression(node) || syntaxApi.isElementAccessExpression(node)) && node.questionDotToken !== void 0;
|
|
421
|
+
if (!isOptionalAccess) return void 0;
|
|
422
|
+
const mockRecord = mockRecordReading({ syntaxApi, node: node.expression });
|
|
423
|
+
if (mockRecord === "calls") return MOCK_CALL_OPTIONAL_CHAIN;
|
|
424
|
+
if (mockRecord === "results") return MOCK_RESULT_OPTIONAL_CHAIN;
|
|
425
|
+
return syntaxApi.isElementAccessExpression(node.expression) ? INDEXED_OPTIONAL_CHAIN : PROPERTY_OPTIONAL_CHAIN;
|
|
426
|
+
};
|
|
427
|
+
var expressionForm = (request) => {
|
|
97
428
|
const { syntaxApi, node } = request;
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var
|
|
429
|
+
if (syntaxApi.isConditionalExpression(node)) return TERNARY;
|
|
430
|
+
if (syntaxApi.isBinaryExpression(node) && SHORT_CIRCUIT_TOKENS({ syntaxApi }).includes(node.operatorToken.kind)) {
|
|
431
|
+
return SHORT_CIRCUIT;
|
|
432
|
+
}
|
|
433
|
+
return callForm(request) ?? optionalChainForm(request);
|
|
434
|
+
};
|
|
435
|
+
var IMPLEMENTATION_TAKERS = ["mockImplementation", "mockImplementationOnce"];
|
|
436
|
+
var takesImplementation = (request) => {
|
|
106
437
|
const { syntaxApi, node } = request;
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
438
|
+
if (!syntaxApi.isCallExpression(node) || !syntaxApi.isPropertyAccessExpression(node.expression)) return "other";
|
|
439
|
+
const callee = node.expression;
|
|
440
|
+
const isViFn = callee.name.text === "fn" && syntaxApi.isIdentifier(callee.expression) && callee.expression.text === "vi";
|
|
441
|
+
return isViFn || IMPLEMENTATION_TAKERS.includes(callee.name.text) ? "takes" : "other";
|
|
442
|
+
};
|
|
443
|
+
var enclosingFunctionOf = (request) => {
|
|
444
|
+
if (request.syntaxApi.isSourceFile(request.node)) return void 0;
|
|
445
|
+
if (request.syntaxApi.isFunctionLike(request.node)) return request.node;
|
|
446
|
+
return enclosingFunctionOf({ syntaxApi: request.syntaxApi, node: request.node.parent });
|
|
447
|
+
};
|
|
448
|
+
var enclosureOf = (request) => {
|
|
449
|
+
const { syntaxApi } = request;
|
|
450
|
+
const enclosing = enclosingFunctionOf({ syntaxApi, node: request.node.parent });
|
|
451
|
+
if (enclosing === void 0) return "elsewhere";
|
|
452
|
+
const holder = syntaxApi.isPropertyAssignment(enclosing.parent) ? enclosing.parent.parent : enclosing.parent;
|
|
453
|
+
const passedOn = syntaxApi.isObjectLiteralExpression(holder) || takesImplementation({ syntaxApi, node: holder }) === "takes";
|
|
454
|
+
return passedOn ? "passed-on-function" : "elsewhere";
|
|
110
455
|
};
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
return
|
|
456
|
+
var testBodyFormOf = (request) => {
|
|
457
|
+
const form = statementForm(request) ?? expressionForm(request);
|
|
458
|
+
if (form === void 0) return void 0;
|
|
459
|
+
return enclosureOf(request) === "passed-on-function" ? { introducedIn: form.introducedIn, remedy: PASSED_ON_FUNCTION } : form;
|
|
115
460
|
};
|
|
116
461
|
var snippetAt = (request) => {
|
|
117
462
|
const snippet = request.source.slice(request.position, request.position + 80).replace(/\n/g, " ");
|
|
@@ -133,14 +478,14 @@ var check = {
|
|
|
133
478
|
const hits = [];
|
|
134
479
|
return {
|
|
135
480
|
enter: ({ node }) => {
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
const reaching = clauses.filter((clause) => editionReaches({ edition: clause.edition, introducedIn }) === "reached");
|
|
481
|
+
const form = testBodyFormOf({ syntaxApi, node });
|
|
482
|
+
if (form === void 0) return;
|
|
483
|
+
const reaching = clauses.filter((clause) => editionReaches({ edition: clause.edition, introducedIn: form.introducedIn }) === "reached");
|
|
139
484
|
if (reaching.length === 0) return;
|
|
140
485
|
const position = node.getStart(sourceFile);
|
|
141
486
|
const anchor = anchorAt({ position });
|
|
142
487
|
const snippet = snippetAt({ source: sourceFile.text, position });
|
|
143
|
-
hits.push(...reaching.map((clause) => ({ clause: clause.address, anchor, snippet })));
|
|
488
|
+
hits.push(...reaching.map((clause) => ({ clause: clause.address, anchor, snippet, remedy: form.remedy })));
|
|
144
489
|
},
|
|
145
490
|
finish: () => hits
|
|
146
491
|
};
|
|
@@ -153,5 +498,8 @@ var check = {
|
|
|
153
498
|
})
|
|
154
499
|
};
|
|
155
500
|
export {
|
|
156
|
-
|
|
501
|
+
TEST_BODY_REMEDIES,
|
|
502
|
+
TEST_BODY_SECTIONS,
|
|
503
|
+
check,
|
|
504
|
+
testBodyFormOf
|
|
157
505
|
};
|
|
@@ -5,6 +5,8 @@ export type SyntaxNode = typescript.Node;
|
|
|
5
5
|
export type CommentRange = typescript.CommentRange;
|
|
6
6
|
export type Statement = typescript.Statement;
|
|
7
7
|
export type ImportDeclaration = typescript.ImportDeclaration;
|
|
8
|
+
export type CallExpression = typescript.CallExpression;
|
|
9
|
+
export type PropertyAccessExpression = typescript.PropertyAccessExpression;
|
|
8
10
|
export type ExportDeclaration = typescript.ExportDeclaration;
|
|
9
11
|
export type Diagnostic = typescript.Diagnostic;
|
|
10
12
|
export type CompilerOptions = typescript.CompilerOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PieceFailure } from "../../../core/mechanism-port/piece-failure-types.js";
|
|
2
2
|
import type { RunnerClause } from "../../../core/mechanism-port/runner-module-types.js";
|
|
3
|
-
import type { Hit } from "../../../core/mechanism-port/runner-result-types.js";
|
|
3
|
+
import type { Hit, Remedy } from "../../../core/mechanism-port/runner-result-types.js";
|
|
4
4
|
import type { Anchor } from "../../../core/values/anchor.js";
|
|
5
5
|
import type { ClauseAddress } from "../../../core/values/clause-address-types.js";
|
|
6
6
|
import type { RepoPath } from "../../../core/values/repo-path-types.js";
|
|
@@ -10,6 +10,7 @@ export type PieceHit = {
|
|
|
10
10
|
readonly clause: ClauseAddress;
|
|
11
11
|
readonly anchor: Anchor;
|
|
12
12
|
readonly snippet: string;
|
|
13
|
+
readonly remedy?: Remedy;
|
|
13
14
|
};
|
|
14
15
|
export type WalkerFile = {
|
|
15
16
|
readonly file: RepoPath;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
siteRule
|
|
3
|
+
} from "../../../../chunks/chunk-WF3PPYRR.js";
|
|
1
4
|
import {
|
|
2
5
|
defaultNativeRuleSources,
|
|
3
6
|
typescriptEslintRules
|
|
@@ -10,7 +13,7 @@ var LOOP_HEADS = /* @__PURE__ */ new Set(["ForInStatement", "ForOfStatement"]);
|
|
|
10
13
|
var bindingDisposition = (request) => (request.binding.init ?? null) === null && !("typeAnnotation" in request.binding.id && request.binding.id.typeAnnotation) ? "implicit-any" : "typed-or-initialised";
|
|
11
14
|
var governedFile = (request) => TYPESCRIPT_FILE.test(request.filename) && !DECLARATION_FILE.test(request.filename) ? "governed" : "not-governed";
|
|
12
15
|
var loopHeadDisposition = (request) => request.node.parent !== null && LOOP_HEADS.has(request.node.parent.type) ? "loop-head" : "statement";
|
|
13
|
-
var implicitAnyLet = {
|
|
16
|
+
var implicitAnyLet = siteRule({
|
|
14
17
|
meta: {
|
|
15
18
|
type: "problem",
|
|
16
19
|
docs: { description: "Disallow let and var declarations with neither a type nor an initialiser (CD-1)" },
|
|
@@ -19,8 +22,8 @@ var implicitAnyLet = {
|
|
|
19
22
|
implicitAny: "CD-1: give this variable a type annotation or an initialiser so it is not implicitly any."
|
|
20
23
|
}
|
|
21
24
|
},
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
observe: (context) => ({
|
|
26
|
+
variableDeclarations: (node) => {
|
|
24
27
|
if (node.kind === "const" || governedFile({ filename: context.filename }) === "not-governed") {
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
@@ -34,7 +37,7 @@ var implicitAnyLet = {
|
|
|
34
37
|
context.report({ node: implicit.id, messageId: "implicitAny" });
|
|
35
38
|
}
|
|
36
39
|
})
|
|
37
|
-
};
|
|
40
|
+
});
|
|
38
41
|
var createPlugin = (sources) => ({
|
|
39
42
|
meta: { name: "hone-cd1", version: "0.0.0-local" },
|
|
40
43
|
rules: {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
siteRule
|
|
3
|
+
} from "../../../../chunks/chunk-WF3PPYRR.js";
|
|
4
|
+
|
|
1
5
|
// mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.ts
|
|
2
6
|
var NON_ERROR_EXPRESSIONS = /* @__PURE__ */ new Set([
|
|
3
7
|
"Literal",
|
|
@@ -7,11 +11,18 @@ var NON_ERROR_EXPRESSIONS = /* @__PURE__ */ new Set([
|
|
|
7
11
|
"TaggedTemplateExpression"
|
|
8
12
|
]);
|
|
9
13
|
var eitherNonError = (request) => thrownDisposition({ expression: request.first }) === "non-error" || thrownDisposition({ expression: request.second }) === "non-error" ? "non-error" : "possibly-error";
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
var compositeDisposition = (request) => {
|
|
15
|
+
const expression = request.expression;
|
|
16
|
+
if (expression.type === "LogicalExpression") {
|
|
17
|
+
return eitherNonError({ first: expression.left, second: expression.right });
|
|
18
|
+
}
|
|
19
|
+
if (expression.type === "ConditionalExpression") {
|
|
20
|
+
return eitherNonError({ first: expression.consequent, second: expression.alternate });
|
|
21
|
+
}
|
|
22
|
+
if (expression.type === "AssignmentExpression") {
|
|
23
|
+
return thrownDisposition({ expression: expression.right });
|
|
24
|
+
}
|
|
25
|
+
return expression.type === "SequenceExpression" ? thrownDisposition({ expression: expression.expressions.at(-1) }) : "possibly-error";
|
|
15
26
|
};
|
|
16
27
|
var thrownDisposition = (request) => {
|
|
17
28
|
if (request.expression === void 0) {
|
|
@@ -23,10 +34,9 @@ var thrownDisposition = (request) => {
|
|
|
23
34
|
if (request.expression.type === "Identifier") {
|
|
24
35
|
return request.expression.name === "undefined" ? "non-error" : "possibly-error";
|
|
25
36
|
}
|
|
26
|
-
|
|
27
|
-
return composite === void 0 ? "possibly-error" : composite(request.expression);
|
|
37
|
+
return compositeDisposition({ expression: request.expression });
|
|
28
38
|
};
|
|
29
|
-
var throwOnlyError = {
|
|
39
|
+
var throwOnlyError = siteRule({
|
|
30
40
|
meta: {
|
|
31
41
|
type: "problem",
|
|
32
42
|
docs: { description: "Disallow throwing values that cannot be Error objects (CD-10)" },
|
|
@@ -35,15 +45,15 @@ var throwOnlyError = {
|
|
|
35
45
|
throwOnlyError: "CD-10: throw an Error, not a literal, object, template or undefined."
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
observe: (context) => ({
|
|
49
|
+
throws: (node) => {
|
|
40
50
|
if (thrownDisposition({ expression: node.argument }) === "possibly-error") {
|
|
41
51
|
return;
|
|
42
52
|
}
|
|
43
53
|
context.report({ node, messageId: "throwOnlyError" });
|
|
44
54
|
}
|
|
45
55
|
})
|
|
46
|
-
};
|
|
56
|
+
});
|
|
47
57
|
var cd10_eslint_plugin_default = {
|
|
48
58
|
meta: { name: "hone-cd10", version: "0.0.0-local" },
|
|
49
59
|
rules: { "throw-only-error": throwOnlyError }
|