@hailstails/hone 1.3.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.
Files changed (47) hide show
  1. package/ADOPTING.md +2 -2
  2. package/CHANGELOG.md +22 -0
  3. package/MIGRATING.md +23 -0
  4. package/README.md +27 -6
  5. package/api/audit.d.ts +1 -1
  6. package/api/testing.js +3 -3
  7. package/chunks/chunk-335ITLPO.js +7 -0
  8. package/chunks/{chunk-YSN46EB3.js → chunk-6SM3HKWO.js} +270 -624
  9. package/chunks/{chunk-PL2PNPAR.js → chunk-E6VR3VRV.js} +1 -6
  10. package/chunks/{chunk-H4V72FCW.js → chunk-FEWCJU7H.js} +9 -1
  11. package/chunks/chunk-WF3PPYRR.js +27 -0
  12. package/core/check/tool-command.js +756 -64
  13. package/core/mechanism-port/runner-result-types.d.ts +6 -0
  14. package/docs/adding-a-discipline-or-mechanism.md +3 -3
  15. package/docs/extending.md +1 -0
  16. package/docs/output-contract.md +52 -10
  17. package/mechanisms/audit/CD-27/test-body-logic.js +394 -46
  18. package/mechanisms/audit/runner/runner.js +1 -1
  19. package/mechanisms/audit/runner/typescript-parse.d.ts +2 -0
  20. package/mechanisms/audit/runner/walker-piece.d.ts +2 -1
  21. package/mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js +7 -4
  22. package/mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js +21 -11
  23. package/mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js +15 -5
  24. package/mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js +7 -3
  25. package/mechanisms/eslint/CD-41/README.md +1 -1
  26. package/mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js +100 -28
  27. package/mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js +8 -4
  28. package/mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js +8 -4
  29. package/mechanisms/eslint/runner/README.md +9 -2
  30. package/mechanisms/eslint/runner/runner.js +1404 -1382
  31. package/methods/lenses/di-discipline.md +4 -5
  32. package/methods/lenses/test-discipline.md +1 -1
  33. package/package.json +1 -1
  34. package/rules/CD-1/CHECKS.md +2 -0
  35. package/rules/CD-12/README.md +1 -1
  36. package/rules/CD-15/CHECKS.md +2 -0
  37. package/rules/CD-17/README.md +3 -3
  38. package/rules/CD-2/CHECKS.md +2 -0
  39. package/rules/CD-25/CHECKS.md +2 -2
  40. package/rules/CD-25/README.md +3 -3
  41. package/rules/CD-27/CHECKS.md +382 -6
  42. package/rules/CD-27/README.md +1 -1
  43. package/rules/CD-27/discipline.json +130 -0
  44. package/rules/CD-41/CHECKS.md +10 -0
  45. package/rules/CD-41/README.md +2 -0
  46. package/rules/CD-41/discipline.json +14 -0
  47. package/chunks/chunk-YLZ73C7O.js +0 -0
@@ -1,3 +1,6 @@
1
+ import {
2
+ siteRule
3
+ } from "../../../../chunks/chunk-WF3PPYRR.js";
1
4
  import {
2
5
  defaultNativeRuleSources,
3
6
  typescriptEslintRules
@@ -39,7 +42,15 @@ var reportAtClassKeyword = ({
39
42
  }
40
43
  context.report({ loc: keyword.loc, messageId: "noClass" });
41
44
  };
42
- var noClassAuthoring = {
45
+ var classKindOf = ({ node }) => {
46
+ switch (node.type) {
47
+ case "ClassDeclaration":
48
+ return "declaration";
49
+ case "ClassExpression":
50
+ return "expression";
51
+ }
52
+ };
53
+ var noClassAuthoring = siteRule({
43
54
  meta: {
44
55
  type: "problem",
45
56
  docs: { description: "Disallow authored runtime classes (CD-14)" },
@@ -48,7 +59,7 @@ var noClassAuthoring = {
48
59
  noClass: "CD-14: use functions and closure-backed factories instead of authoring a class."
49
60
  }
50
61
  },
51
- create(context) {
62
+ observe: (context) => {
52
63
  const reportClass = ({
53
64
  node,
54
65
  kind
@@ -63,11 +74,10 @@ var noClassAuthoring = {
63
74
  reportAtClassKeyword({ context, node });
64
75
  };
65
76
  return {
66
- ClassDeclaration: (node) => reportClass({ node, kind: "declaration" }),
67
- ClassExpression: (node) => reportClass({ node, kind: "expression" })
77
+ classes: (node) => reportClass({ node, kind: classKindOf({ node }) })
68
78
  };
69
79
  }
70
- };
80
+ });
71
81
  var eslintPlugin = (plugin) => plugin;
72
82
  var createPlugin = (sources) => eslintPlugin({
73
83
  meta: { name: "hone", version: "0.0.0-local" },
@@ -1,3 +1,7 @@
1
+ import {
2
+ siteRule
3
+ } from "../../../../chunks/chunk-WF3PPYRR.js";
4
+
1
5
  // mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.ts
2
6
  var TEST_ROOTS = /* @__PURE__ */ new Set(["describe", "it", "test", "suite"]);
3
7
  var FOCUSED = {
@@ -44,15 +48,15 @@ var modifiedLink = (request) => {
44
48
  const testFunction = links.findIndex((link) => request.modifier.roots.has(link.name));
45
49
  return testFunction === -1 ? void 0 : links.slice(testFunction + 1).find((link) => request.modifier.members.has(link.name));
46
50
  };
47
- var modifierRule = (request) => ({
51
+ var modifierRule = (request) => siteRule({
48
52
  meta: {
49
53
  type: "problem",
50
54
  docs: { description: request.description },
51
55
  schema: [],
52
56
  messages: { modifiedTest: request.message }
53
57
  },
54
- create: (context) => ({
55
- CallExpression: (node) => {
58
+ observe: (context) => ({
59
+ calls: (node) => {
56
60
  const loc = modifiedLink({ callee: node.callee, modifier: request.modifier })?.node.loc;
57
61
  if (loc === void 0 || loc === null) {
58
62
  return;
@@ -3,7 +3,7 @@
3
3
  This piece enforces CD-41's `cognitive-complexity` and `function-length` clauses through ESLint, in the plugin `cd41/cd41.eslint-plugin.ts` under the namespace `hone-cd41`.
4
4
 
5
5
  - `cognitive-complexity` reports a function whose cognitive complexity is above 15, at the function's name.
6
- - `function-length` reports a function whose body spans more than 50 lines, at the function.
6
+ - `function-length` reports a function whose body spans more than 50 lines, at the function. A test suite's body, the function a `describe` or `suite` call runs, is not measured; the functions inside it are. [CHECKS.md](../../../rules/CD-41/CHECKS.md) lists the suite forms.
7
7
 
8
8
  `piece.json` names each clause, the namespace, the plugin module and the rule. It is the only file core reads to find the rules.
9
9
 
@@ -1,11 +1,11 @@
1
+ import {
2
+ functionSiteOf,
3
+ siteRule
4
+ } from "../../../../chunks/chunk-WF3PPYRR.js";
5
+
1
6
  // mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.ts
2
7
  var MAX_COGNITIVE_COMPLEXITY = 15;
3
8
  var MAX_FUNCTION_LINES = 50;
4
- var FUNCTION_TYPES = /* @__PURE__ */ new Set([
5
- "FunctionDeclaration",
6
- "FunctionExpression",
7
- "ArrowFunctionExpression"
8
- ]);
9
9
  var LOOP_TYPES = /* @__PURE__ */ new Set([
10
10
  "ForStatement",
11
11
  "ForInStatement",
@@ -17,6 +17,24 @@ var LOOP_BODY_KEYS = /* @__PURE__ */ new Set(["body"]);
17
17
  var ACCESSOR_KINDS = /* @__PURE__ */ new Set(["get", "set"]);
18
18
  var MEMBER_TYPES = /* @__PURE__ */ new Set(["MethodDefinition", "Property", "TSAbstractMethodDefinition"]);
19
19
  var BRACES = /* @__PURE__ */ new Set(["{", "}"]);
20
+ var SUITE_ROOTS = /* @__PURE__ */ new Set(["describe", "suite", "fdescribe", "xdescribe", "fsuite", "xsuite"]);
21
+ var SUITE_MODIFIERS = /* @__PURE__ */ new Set([
22
+ "each",
23
+ "for",
24
+ "only",
25
+ "skip",
26
+ "todo",
27
+ "concurrent",
28
+ "sequential",
29
+ "shuffle",
30
+ "skipIf",
31
+ "runIf"
32
+ ]);
33
+ var PLAYWRIGHT_SUITE = {
34
+ root: "test",
35
+ member: "describe",
36
+ modifiers: /* @__PURE__ */ new Set(["only", "skip", "fixme", "serial", "parallel"])
37
+ };
20
38
  var LINE_BREAK = /\r\n|[\r\n]/gu;
21
39
  var EMPTY = { own: 0, nested: [] };
22
40
  var isNode = (candidate) => typeof candidate === "object" && candidate !== null && "type" in candidate && typeof candidate.type === "string";
@@ -83,10 +101,21 @@ var walkedIf = (request) => withOwn({
83
101
  }),
84
102
  increment: 1 + request.nesting
85
103
  });
86
- var NESTING_STRUCTURES = {
87
- SwitchStatement: /* @__PURE__ */ new Set(["cases"]),
88
- ConditionalExpression: /* @__PURE__ */ new Set(["consequent", "alternate"]),
89
- CatchClause: /* @__PURE__ */ new Set(["body"])
104
+ var SWITCH_NESTED_KEYS = /* @__PURE__ */ new Set(["cases"]);
105
+ var CONDITIONAL_NESTED_KEYS = /* @__PURE__ */ new Set(["consequent", "alternate"]);
106
+ var CATCH_NESTED_KEYS = /* @__PURE__ */ new Set(["body"]);
107
+ var nestedKeysOf = (request) => {
108
+ const node = request.node;
109
+ if (LOOP_TYPES.has(node.type)) {
110
+ return LOOP_BODY_KEYS;
111
+ }
112
+ if (node.type === "SwitchStatement") {
113
+ return SWITCH_NESTED_KEYS;
114
+ }
115
+ if (node.type === "ConditionalExpression") {
116
+ return CONDITIONAL_NESTED_KEYS;
117
+ }
118
+ return node.type === "CatchClause" ? CATCH_NESTED_KEYS : void 0;
90
119
  };
91
120
  var structureIncrement = (request) => {
92
121
  const node = request.node;
@@ -106,7 +135,7 @@ var walkedTry = (request) => {
106
135
  };
107
136
  var walked = (request) => {
108
137
  const node = request.node;
109
- if (FUNCTION_TYPES.has(node.type)) {
138
+ if (functionSiteOf({ node }) !== void 0) {
110
139
  const nested = scoredFunction({ node, nesting: request.nesting + 1, sourceCode: request.sourceCode });
111
140
  return { own: 0, nested: [{ node, score: nested.own }, ...nested.nested] };
112
141
  }
@@ -116,7 +145,7 @@ var walked = (request) => {
116
145
  if (node.type === "TryStatement") {
117
146
  return walkedTry(request);
118
147
  }
119
- const nestedKeys = LOOP_TYPES.has(node.type) ? LOOP_BODY_KEYS : NESTING_STRUCTURES[node.type];
148
+ const nestedKeys = nestedKeysOf({ node });
120
149
  if (nestedKeys !== void 0) {
121
150
  return withOwn({ score: walkedChildren({ ...request, nestedKeys }), increment: 1 + request.nesting });
122
151
  }
@@ -145,12 +174,63 @@ var accessorDisposition = (request) => {
145
174
  const parent = request.node.parent;
146
175
  return parent !== null && MEMBER_TYPES.has(parent.type) && "kind" in parent && ACCESSOR_KINDS.has(String(parent.kind)) ? "accessor" : "callable";
147
176
  };
177
+ var memberNameOf = (request) => {
178
+ const property = request.member.property;
179
+ if (property.type === "Identifier" && !request.member.computed) {
180
+ return property.name;
181
+ }
182
+ return property.type === "Literal" && typeof property.value === "string" ? property.value : void 0;
183
+ };
184
+ var calleeChainOf = (request) => {
185
+ const callee = request.callee;
186
+ if (callee.type === "Identifier") {
187
+ return { root: callee.name, members: request.members };
188
+ }
189
+ if (callee.type === "CallExpression") {
190
+ return calleeChainOf({ callee: callee.callee, members: request.members });
191
+ }
192
+ if (callee.type === "TaggedTemplateExpression") {
193
+ return calleeChainOf({ callee: callee.tag, members: request.members });
194
+ }
195
+ if (callee.type !== "MemberExpression") {
196
+ return void 0;
197
+ }
198
+ const name = memberNameOf({ member: callee });
199
+ return name === void 0 ? void 0 : calleeChainOf({ callee: callee.object, members: [name, ...request.members] });
200
+ };
201
+ var modifiedSuiteRole = (request) => request.members.every((member) => request.modifiers.has(member)) ? "suite-body" : "callable";
202
+ var chainRole = (request) => {
203
+ const chain = request.chain;
204
+ if (chain === void 0) {
205
+ return "callable";
206
+ }
207
+ if (SUITE_ROOTS.has(chain.root)) {
208
+ return modifiedSuiteRole({ members: chain.members, modifiers: SUITE_MODIFIERS });
209
+ }
210
+ const [first, ...rest] = chain.members;
211
+ return chain.root === PLAYWRIGHT_SUITE.root && first === PLAYWRIGHT_SUITE.member ? modifiedSuiteRole({ members: rest, modifiers: PLAYWRIGHT_SUITE.modifiers }) : "callable";
212
+ };
213
+ var callbackRole = (request) => {
214
+ const call = request.node.parent;
215
+ if (call?.type !== "CallExpression" || call.callee === request.node) {
216
+ return "callable";
217
+ }
218
+ const curried = call.parent?.type === "CallExpression" && call.parent.callee === call;
219
+ return curried ? "callable" : chainRole({ chain: calleeChainOf({ callee: call.callee, members: [] }) });
220
+ };
148
221
  var functionLineCount = (request) => request.sourceCode.getTokens(request.body).filter((token) => !(token.type === "Punctuator" && BRACES.has(token.value))).reduce((lines, token) => {
149
222
  const previous = request.sourceCode.getTokenBefore(token);
150
223
  const triviaStart = previous === null ? token.range[0] : previous.range[1];
151
224
  return lines + (request.sourceCode.text.slice(triviaStart, token.range[0]).match(LINE_BREAK)?.length ?? 0);
152
225
  }, 0);
153
- var cognitiveComplexity = {
226
+ var enclosure = (request) => {
227
+ const parent = request.node.parent;
228
+ if (parent === null) {
229
+ return "outermost";
230
+ }
231
+ return functionSiteOf({ node: parent }) === void 0 ? enclosure({ node: parent }) : "enclosed";
232
+ };
233
+ var cognitiveComplexity = siteRule({
154
234
  meta: {
155
235
  type: "suggestion",
156
236
  docs: { description: "Limit each function's cognitive complexity to 15 (CD-41)" },
@@ -159,7 +239,7 @@ var cognitiveComplexity = {
159
239
  cognitiveComplexity: "CD-41: this function's cognitive complexity is {{score}}, above the limit of {{max}}; move the branching into helpers it composes."
160
240
  }
161
241
  },
162
- create: (context) => {
242
+ observe: (context) => {
163
243
  const reportScored = (scored) => {
164
244
  const loc = functionNameLoc({ node: scored.node, sourceCode: context.sourceCode });
165
245
  if (loc === void 0) {
@@ -172,21 +252,17 @@ var cognitiveComplexity = {
172
252
  });
173
253
  };
174
254
  const scoreOutermost = (node) => {
175
- if (context.sourceCode.getAncestors(node).some((ancestor) => FUNCTION_TYPES.has(ancestor.type))) {
255
+ if (enclosure({ node }) === "enclosed") {
176
256
  return;
177
257
  }
178
258
  const scored = scoredFunction({ node, nesting: 0, sourceCode: context.sourceCode });
179
259
  [{ node, score: scored.own }, ...scored.nested].filter((entry) => entry.score > MAX_COGNITIVE_COMPLEXITY).forEach(reportScored);
180
260
  };
181
- return {
182
- FunctionDeclaration: scoreOutermost,
183
- FunctionExpression: scoreOutermost,
184
- ArrowFunctionExpression: scoreOutermost
185
- };
261
+ return { functions: scoreOutermost };
186
262
  }
187
- };
263
+ });
188
264
  var reportLongFunction = (request) => {
189
- if (accessorDisposition({ node: request.node }) === "accessor" || !("body" in request.node) || !isNode(request.node.body)) {
265
+ if (accessorDisposition({ node: request.node }) === "accessor" || callbackRole({ node: request.node }) === "suite-body" || !("body" in request.node) || !isNode(request.node.body)) {
190
266
  return;
191
267
  }
192
268
  const lines = functionLineCount({ body: request.node.body, sourceCode: request.context.sourceCode });
@@ -199,7 +275,7 @@ var reportLongFunction = (request) => {
199
275
  data: { lines: String(lines), max: String(MAX_FUNCTION_LINES) }
200
276
  });
201
277
  };
202
- var functionLength = {
278
+ var functionLength = siteRule({
203
279
  meta: {
204
280
  type: "suggestion",
205
281
  docs: { description: "Limit each function body to 50 lines (CD-41)" },
@@ -208,12 +284,8 @@ var functionLength = {
208
284
  functionLength: "CD-41: this function body has {{lines}} lines, above the limit of {{max}}; split it into helpers."
209
285
  }
210
286
  },
211
- create: (context) => ({
212
- FunctionDeclaration: (node) => reportLongFunction({ context, node }),
213
- FunctionExpression: (node) => reportLongFunction({ context, node }),
214
- ArrowFunctionExpression: (node) => reportLongFunction({ context, node })
215
- })
216
- };
287
+ observe: (context) => ({ functions: (node) => reportLongFunction({ context, node }) })
288
+ });
217
289
  var cd41_eslint_plugin_default = {
218
290
  meta: { name: "hone-cd41", version: "0.0.0-local" },
219
291
  rules: {
@@ -1,3 +1,7 @@
1
+ import {
2
+ siteRule
3
+ } from "../../../../chunks/chunk-WF3PPYRR.js";
4
+
1
5
  // mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.ts
2
6
  var bothBranchesExit = (request) => {
3
7
  if (request.alternate === null || request.alternate === void 0) {
@@ -40,7 +44,7 @@ var reportedElses = (request) => {
40
44
  }
41
45
  return request.alternate.type === "IfStatement" ? [request.alternate, ...reportedElses({ consequent: request.alternate.consequent, alternate: request.alternate.alternate })] : [request.alternate];
42
46
  };
43
- var uselessElse = {
47
+ var uselessElse = siteRule({
44
48
  meta: {
45
49
  type: "suggestion",
46
50
  docs: { description: "Disallow else after a branch that always exits (CD-42)" },
@@ -49,8 +53,8 @@ var uselessElse = {
49
53
  uselessElse: "CD-42: the branch above always exits, so drop this else and return the happy path last."
50
54
  }
51
55
  },
52
- create: (context) => ({
53
- IfStatement: (node) => {
56
+ observe: (context) => ({
57
+ ifs: (node) => {
54
58
  if (chainPosition({ node }) === "else-if") {
55
59
  return;
56
60
  }
@@ -63,7 +67,7 @@ var uselessElse = {
63
67
  });
64
68
  }
65
69
  })
66
- };
70
+ });
67
71
  var cd42_eslint_plugin_default = {
68
72
  meta: { name: "hone-cd42", version: "0.0.0-local" },
69
73
  rules: { "useless-else": uselessElse }
@@ -1,3 +1,7 @@
1
+ import {
2
+ siteRule
3
+ } from "../../../../chunks/chunk-WF3PPYRR.js";
4
+
1
5
  // mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.ts
2
6
  var NAME_CASE = /^(?:[a-z0-9]+(?:-[a-z0-9]+)*|[A-Z](?:[A-Za-z0-9]*[a-z][A-Za-z0-9]*|[0-9]*))$/u;
3
7
  var ROUTE_SEGMENT = /^(?:\[{1,2}(?:\.\.\.)?[A-Za-z0-9_-]+\]{1,2}|\([A-Za-z0-9_-]+\))/u;
@@ -22,7 +26,7 @@ var filenameDisposition = (request) => {
22
26
  const route = ROUTE_SEGMENT.exec(name);
23
27
  return route === null ? plainDisposition({ name }) : routeDisposition({ name, route: route[0] });
24
28
  };
25
- var filenameCase = {
29
+ var filenameCase = siteRule({
26
30
  meta: {
27
31
  type: "suggestion",
28
32
  docs: { description: "Require kebab-case or PascalCase file names (CD-7)" },
@@ -31,8 +35,8 @@ var filenameCase = {
31
35
  filenameCase: "CD-7: name this file in kebab-case or PascalCase."
32
36
  }
33
37
  },
34
- create: (context) => ({
35
- Program: () => {
38
+ observe: (context) => ({
39
+ file: () => {
36
40
  const basename = context.filename.split(PATH_SEPARATOR).at(-1) ?? "";
37
41
  if (filenameDisposition({ basename }) === "conventional") {
38
42
  return;
@@ -40,7 +44,7 @@ var filenameCase = {
40
44
  context.report({ loc: { line: 1, column: 0 }, messageId: "filenameCase" });
41
45
  }
42
46
  })
43
- };
47
+ });
44
48
  var cd7_eslint_plugin_default = {
45
49
  meta: { name: "hone-cd7", version: "0.0.0-local" },
46
50
  rules: { "filename-case": filenameCase }
@@ -1,6 +1,6 @@
1
1
  # ESLint runner
2
2
 
3
- The ESLint runner is Hone's embedded mechanism: each selected clause runs as an ESLint rule inside the team's own ESLint setup. Its `exceptionPath` is `embedded`. Core hands it the selected clauses, the files to check, the repository's tracked paths and the exception records for this mechanism. The runner lints the files with its own configuration to find hits, reports every native channel in the team's setup that weakens a selected rule, and writes and checks the projection `disciplines.eslint.mjs`, one slice per config root, that carries the records into the team's own run. Its `projectedKinds` is `["config-override", "inline-disable"]`, so a record can cover only those kinds, and an `inline-disable` only by a file record on its clause and file.
3
+ The ESLint runner is Hone's embedded mechanism: each selected clause runs as an ESLint rule inside the team's own ESLint setup. Its `exceptionPath` is `embedded`. Core hands it the selected clauses, the files to check, the repository's tracked paths and the exception records for this mechanism. The runner lints the files with its own configuration to find hits, reports every native channel in the team's setup that weakens a selected rule, and writes and checks the projection `disciplines.eslint.mjs`, one slice per config root, that carries the records into the team's own run. Its `projectedKinds` is `["config-override", "inline-disable"]`, so a record can cover only those kinds, and an `inline-disable` only by a file record on its clause and file. It reports no `config-override` on a clause and file that one of the records it is given projects off, since that is the projection's own off-switch.
4
4
 
5
5
  The native channels, the exception kind each maps to, and how the projection is adopted and checked are in [the guide](../../../docs/adding-a-discipline-or-mechanism.md#embedded-mechanisms).
6
6
 
@@ -23,6 +23,13 @@ The config roots are the repository root, every folder holding a tracked `eslint
23
23
  - `governing-config.ts` decides, when a nested `eslint.config.*` fails to load, whether the team's own ESLint would ever enter its folder. It asks the config governing that folder, then each config above it up to the repository root, whether it ignores that folder and then the file. `governingConfigIgnores` answers one such question, for a file or a folder, telling a real ignore from a path no `files` block matches; `cachedGoverningIgnores` asks each config about each path once, only when first needed.
24
24
  - `inline-config-parser.ts` is the wrapping factory for `@eslint/plugin-kit`, the only file that imports it.
25
25
  - `native-rules.ts` re-exports the ESLint core rules (`eslintCoreRules`) and the typescript-eslint rules (`typescriptEslintRules`) that pieces reuse. It is the only file that imports them, and it imports `eslint/use-at-your-own-risk` and `@typescript-eslint/eslint-plugin` statically, resolved upward from the install like the toolchain.
26
+ - `rule-sites.ts` is the one boundary between Hone's pieces and ESLint's rule contract.
27
+ - `siteRule` builds a rule from its `meta` and an `observe` function. `observe` names the sites the rule looks at: `file`, `functions`, `classes`, `calls`, `throws`, `ifs` and `variableDeclarations`.
28
+ - The module maps each site onto the ESLint listener keys it stands for, such as `FunctionDeclaration`, `FunctionExpression` and `ArrowFunctionExpression` for `functions`, in one literal `Rule.RuleListener`, so ESLint's own types check each handler.
29
+ - `functionSiteOf` narrows a node to a `FunctionSite`, or gives `undefined`, for the function types `functions` covers.
30
+ - Its reason to change is ESLint's rule-registration contract: how a rule names the nodes it listens to. On `main` that contract was written in seven plugin files; here it is written once.
31
+ - Four of the seven sites, `calls`, `throws`, `ifs` and `variableDeclarations`, are one node type each. They earn their place only as the price of that single registration point.
32
+ - A new node type for `functions` is added here alone, since every plugin reaches the function types through `FunctionSite` and `functionSiteOf`. A new node type for `classes` is added here and in the class-authoring plugin, which tells a declaration from an expression with a `switch` over `ClassSite` that the compiler holds exhaustive.
26
33
  - `projection.ts` renders a projection's text, and writes and compares one projection file.
27
34
  - `projection-slices.ts` finds the config roots for a lookup, names each root's slice, picks and re-paths each slice's records, finds the package root governing a file, and finds tracked slices outside every root.
28
35
  - `sliced-projection.ts` renders each root's slice, reports stale package slices, and plans then writes, removes or leaves slices for `project`.
@@ -47,4 +54,4 @@ Both take the rules to read from as `NativeRuleSources`. A piece that wraps nati
47
54
 
48
55
  The namespace `reservedNamespace` names (currently `hone-core`) is reserved. Two selected clauses may not share a rule id, or a namespace with different plugin modules. A bad setting, a module that fails to load or does not match its schema, or a missing rule makes the run fail as `piece-invalid`.
49
56
 
50
- The rule imports only types from `eslint` and gets everything else from ESLint's rule context. The guide (`docs/adding-a-discipline-or-mechanism.md`) walks through a shipped piece as the example.
57
+ The rule imports only types from `eslint` and gets everything else from ESLint's rule context. A shipped piece writes each of its own rules with `siteRule` from `rule-sites.ts`, asking for the sites it looks at rather than ESLint's listener keys. Each handler receives the official ESTree node, which the rule reads and narrows on `type` as it needs. The guide (`docs/adding-a-discipline-or-mechanism.md`) walks through a shipped piece as the example.