@yearofthedan/warp 0.4.0 → 0.5.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 (152) hide show
  1. package/README.md +5 -7
  2. package/dist/{analysis → adapters/analysis}/complexity.d.ts +1 -1
  3. package/dist/adapters/analysis/folders.d.ts +2 -0
  4. package/dist/{app/facts.d.ts → adapters/analysis/freshFacts.d.ts} +1 -2
  5. package/dist/{app/facts.js → adapters/analysis/freshFacts.js} +0 -10
  6. package/dist/{analysis → adapters/analysis}/imports.d.ts +2 -1
  7. package/dist/{analysis → adapters/analysis}/imports.js +52 -18
  8. package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
  9. package/dist/adapters/analysis/specifiers.d.ts +10 -0
  10. package/dist/adapters/analysis/specifiers.js +39 -0
  11. package/dist/adapters/analysis/typescript.d.ts +2 -0
  12. package/dist/{analysis → adapters/analysis}/typescript.js +10 -4
  13. package/dist/adapters/config/loadConfig.d.ts +8 -0
  14. package/dist/{config → adapters/config}/loadConfig.js +44 -21
  15. package/dist/{git → adapters/git}/cache.d.ts +1 -1
  16. package/dist/{git → adapters/git}/cache.js +5 -1
  17. package/dist/adapters/git/factsStore.d.ts +2 -0
  18. package/dist/adapters/git/factsStore.js +10 -0
  19. package/dist/{git → adapters/git}/repository.d.ts +1 -1
  20. package/dist/{config → adapters/git}/toolDigest.js +1 -1
  21. package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
  22. package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
  23. package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
  24. package/dist/app/check.d.ts +5 -6
  25. package/dist/app/check.js +3 -3
  26. package/dist/app/checkModel.d.ts +5 -5
  27. package/dist/app/checkModel.js +4 -5
  28. package/dist/app/configLines.d.ts +1 -1
  29. package/dist/app/diff.d.ts +1 -1
  30. package/dist/app/diff.js +1 -1
  31. package/dist/app/failures.d.ts +6 -0
  32. package/dist/app/failures.js +15 -0
  33. package/dist/app/load.d.ts +11 -5
  34. package/dist/app/load.js +22 -59
  35. package/dist/app/ports.d.ts +13 -3
  36. package/dist/builtins/advice.d.ts +4 -4
  37. package/dist/builtins/advice.js +2 -2
  38. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
  39. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
  40. package/dist/builtins/components.d.ts +1 -1
  41. package/dist/builtins/dependency-direction/rule.d.ts +2 -0
  42. package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +9 -4
  43. package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
  44. package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
  45. package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
  46. package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
  47. package/dist/builtins/index.d.ts +2 -2
  48. package/dist/builtins/index.js +18 -13
  49. package/dist/builtins/loops.d.ts +1 -1
  50. package/dist/builtins/loops.js +1 -1
  51. package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
  52. package/dist/builtins/module-externals/rule.d.ts +2 -0
  53. package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
  54. package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
  55. package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
  56. package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
  57. package/dist/builtins/no-double-export/rule.d.ts +2 -0
  58. package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
  59. package/dist/builtins/packages.d.ts +1 -1
  60. package/dist/builtins/place.d.ts +1 -1
  61. package/dist/builtins/shared.d.ts +1 -1
  62. package/dist/builtins/unclassified/rule.d.ts +2 -0
  63. package/dist/builtins/unclassified/rule.js +15 -0
  64. package/dist/builtins/unresolved-import/rule.d.ts +2 -0
  65. package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
  66. package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
  67. package/dist/builtins/unused-declaration/empty.d.ts +1 -1
  68. package/dist/builtins/unused-declaration/empty.js +1 -1
  69. package/dist/builtins/unused-declaration/grants.d.ts +1 -1
  70. package/dist/builtins/unused-declaration/grants.js +64 -14
  71. package/dist/builtins/unused-declaration/rule.d.ts +2 -0
  72. package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
  73. package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
  74. package/dist/builtins/unused-declaration/surfaces.js +1 -1
  75. package/dist/cli.js +51 -54
  76. package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
  77. package/dist/{model/archetype → domain/fixes}/fixes.js +36 -29
  78. package/dist/domain/language/compile.d.ts +11 -0
  79. package/dist/domain/language/compile.js +58 -0
  80. package/dist/{model/archetype → domain/language}/references.d.ts +3 -6
  81. package/dist/{model/archetype → domain/language}/references.js +16 -21
  82. package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
  83. package/dist/{model/archetype → domain/language}/requirements.js +13 -2
  84. package/dist/domain/language/rulesets.d.ts +10 -0
  85. package/dist/domain/language/rulesets.js +60 -0
  86. package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
  87. package/dist/{model/archetype/language.js → domain/language/structure.js} +50 -17
  88. package/dist/{model/archetype → domain/model}/data.d.ts +10 -6
  89. package/dist/{model/archetype → domain/model}/reach.d.ts +1 -0
  90. package/dist/{model/archetype → domain/model}/reach.js +3 -7
  91. package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
  92. package/dist/{model/archetype → domain/model}/resolve.js +9 -3
  93. package/dist/{model/archetype → domain/model}/settings.d.ts +1 -1
  94. package/dist/domain/model/settings.js +82 -0
  95. package/dist/domain/model/text.d.ts +4 -0
  96. package/dist/domain/model/text.js +13 -0
  97. package/dist/{rules → domain/rules}/registry.d.ts +1 -0
  98. package/dist/{rules → domain/rules}/registry.js +11 -1
  99. package/dist/{rules → domain/rules}/rule.d.ts +10 -4
  100. package/dist/index.d.ts +6 -6
  101. package/dist/index.js +2 -2
  102. package/package.json +2 -1
  103. package/dist/analysis/folders.d.ts +0 -2
  104. package/dist/analysis/specifiers.d.ts +0 -2
  105. package/dist/analysis/specifiers.js +0 -6
  106. package/dist/analysis/typescript.d.ts +0 -2
  107. package/dist/app/unclassified.d.ts +0 -5
  108. package/dist/app/unclassified.js +0 -13
  109. package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
  110. package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
  111. package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
  112. package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
  113. package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
  114. package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
  115. package/dist/config/loadConfig.d.ts +0 -13
  116. package/dist/model/archetype/rulesets.d.ts +0 -5
  117. package/dist/model/archetype/rulesets.js +0 -138
  118. package/dist/model/archetype/settings.js +0 -49
  119. /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
  120. /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
  121. /package/dist/{analysis → adapters/analysis}/members.js +0 -0
  122. /package/dist/{analysis → adapters/analysis}/source.d.ts +0 -0
  123. /package/dist/{analysis → adapters/analysis}/source.js +0 -0
  124. /package/dist/{git → adapters/git}/repository.js +0 -0
  125. /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
  126. /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
  127. /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
  128. /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
  129. /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
  130. /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
  131. /package/dist/{reporters → adapters/reporters}/index.js +0 -0
  132. /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
  133. /package/dist/{reporters → adapters/reporters}/json.js +0 -0
  134. /package/dist/{reporters → adapters/reporters}/model.js +0 -0
  135. /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
  136. /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
  137. /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
  138. /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
  139. /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
  140. /package/dist/{reporters → adapters/reporters}/text.js +0 -0
  141. /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
  142. /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
  143. /package/dist/{model → domain/facts}/facts.d.ts +0 -0
  144. /package/dist/{model → domain/facts}/facts.js +0 -0
  145. /package/dist/{model → domain/model}/configError.d.ts +0 -0
  146. /package/dist/{model → domain/model}/configError.js +0 -0
  147. /package/dist/{model/archetype → domain/model}/data.js +0 -0
  148. /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
  149. /package/dist/{model/archetype → domain/model}/shared.js +0 -0
  150. /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
  151. /package/dist/{rules → domain/rules}/diff.js +0 -0
  152. /package/dist/{rules → domain/rules}/rule.js +0 -0
@@ -1,20 +1,31 @@
1
- import { isName, isRecord, list } from './shared.js';
1
+ import { isName, isRecord, list } from '../model/shared.js';
2
2
  export const rootName = 'root';
3
- const moduleKeys = ['description', 'dir', 'files', 'entry', 'archetype', 'dependencies', 'exposes', 'modules', 'test'];
4
- const archetypeKeys = ['description', 'marker', 'requires', 'entry', 'exposes', 'modules', 'test'];
5
- const rootKeys = ['description', 'modules', 'test'];
6
- const testKeys = ['requires', 'dependencies', 'provides', 'exposes', 'modules'];
3
+ const moduleKeys = [
4
+ 'description',
5
+ 'dir',
6
+ 'files',
7
+ 'entry',
8
+ 'archetype',
9
+ 'dependencies',
10
+ 'exposes',
11
+ 'modules',
12
+ 'test',
13
+ 'ruleset',
14
+ ];
15
+ const archetypeKeys = ['description', 'marker', 'requires', 'entry', 'exposes', 'modules', 'test', 'ruleset'];
16
+ const rootKeys = ['description', 'modules', 'test', 'ruleset'];
17
+ const testKeys = ['requires', 'dependencies', 'provides', 'exposes', 'modules', 'ruleset'];
7
18
  const kindOf = new Map([
8
19
  [archetypeKeys, 'an archetype'],
9
20
  [rootKeys, 'the root'],
10
21
  [testKeys, 'a test block'],
11
22
  ]);
12
- const testModuleKeys = ['description', 'dir', 'files', 'archetype', 'dependencies', 'exposes', 'modules'];
13
- export const parseStructure = (root, archetypes, fail) => {
23
+ const testModuleKeys = ['description', 'dir', 'files', 'archetype', 'dependencies', 'exposes', 'modules', 'ruleset'];
24
+ export const parseStructure = (root, archetypes, fail, ruleset) => {
14
25
  const defs = archetypes === undefined ? {} : isRecord(archetypes) ? archetypes : {};
15
26
  if (archetypes !== undefined && !isRecord(archetypes))
16
27
  fail('archetypes: expected archetypes by name');
17
- const state = { defs, archetypes: {}, pending: [], fail };
28
+ const state = { defs, archetypes: {}, pending: [], fail, ruleset };
18
29
  if (Object.hasOwn(defs, rootName))
19
30
  fail(`archetypes.${rootName}: root is the repository; name the archetype otherwise`);
20
31
  for (const [name, def] of Object.entries(defs)) {
@@ -63,6 +74,7 @@ const archetype = (state, name, def, options) => {
63
74
  const data = options.parent ? inlineData(state, name, where, test) : namedData(state, name, def, test);
64
75
  if (options.test)
65
76
  data.test = true;
77
+ Object.assign(data, rulesetsAt(state, where, def.ruleset, test.ruleset));
66
78
  const scope = {
67
79
  archetype: name,
68
80
  names: new Set([...Object.keys(modules), ...Object.keys(testModules), ...filesTestNames(modules)]),
@@ -98,6 +110,11 @@ const inlineData = (state, name, where, test) => {
98
110
  state.fail(`${where}.test.requires: only an archetype requires; its modules see what it requires`);
99
111
  return { name, inline: true, requires: [], modules: [] };
100
112
  };
113
+ const rulesetsAt = (state, where, ruleset, testRuleset) => {
114
+ const own = state.ruleset(ruleset, `${where}.ruleset`);
115
+ const tests = state.ruleset(testRuleset, `${where}.test.ruleset`);
116
+ return { ...(own ? { ruleset: own } : {}), ...(tests ? { testRuleset: tests } : {}) };
117
+ };
101
118
  const testBlock = (state, where, value) => {
102
119
  if (value === undefined)
103
120
  return {};
@@ -143,7 +160,7 @@ const productionModule = (state, scope, name, raw) => {
143
160
  const where = `${scope.archetype}.${name}`;
144
161
  const def = record(state, where, raw);
145
162
  if (nameProblem(name))
146
- state.fail(`${scope.archetype}: a module's name has no dots, not '${name}'`);
163
+ state.fail(`${where}: a module's name has no dots, not '${name}'`);
147
164
  checkKeys(state, where, def, moduleKeys);
148
165
  const inner = { ...scope, own: name };
149
166
  if (def.archetype !== undefined)
@@ -162,7 +179,7 @@ const testModule = (state, scope, name, raw) => {
162
179
  const where = `${scope.archetype}.${name}`;
163
180
  const def = record(state, where, raw);
164
181
  if (nameProblem(name))
165
- state.fail(`${scope.archetype}: a module's name has no dots, not '${name}'`);
182
+ state.fail(`${where}: a module's name has no dots, not '${name}'`);
166
183
  checkKeys(state, where, def, testModuleKeys);
167
184
  const inner = { ...scope, own: name };
168
185
  if (def.archetype !== undefined)
@@ -185,6 +202,7 @@ const testFiles = (state, scope, name, def, of) => {
185
202
  ...(of === undefined ? {} : { of }),
186
203
  using: references(state, scope, `${where}.dependencies`, def.dependencies, true),
187
204
  ...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
205
+ ...rulesetsAt(state, where, def.ruleset, undefined),
188
206
  ...description(state, where, def.description),
189
207
  };
190
208
  };
@@ -213,7 +231,7 @@ const instance = (state, scope, name, def, test) => {
213
231
  state.fail(`${where}.${key}: ${named} defines what is inside; declare ${key} there`);
214
232
  const own = bindings(state, scope, `${where}.dependencies`, def.dependencies, test);
215
233
  const testBlock = isRecord(def.test) ? def.test : {};
216
- for (const key of Object.keys(testBlock).filter((key) => key !== 'dependencies'))
234
+ for (const key of Object.keys(testBlock).filter((key) => key !== 'dependencies' && key !== 'ruleset'))
217
235
  state.fail(`${where}.test.${key}: ${named} defines its test code; declare ${key} there`);
218
236
  const tests = bindings(state, scope, `${where}.test.dependencies`, testBlock.dependencies, true);
219
237
  return {
@@ -225,6 +243,7 @@ const instance = (state, scope, name, def, test) => {
225
243
  using: Object.values(own),
226
244
  ...(Object.keys(own).length > 0 ? { inputs: own } : {}),
227
245
  ...(Object.keys(tests).length > 0 ? { testInputs: tests } : {}),
246
+ ...rulesetsAt(state, where, def.ruleset, testBlock.ruleset),
228
247
  ...description(state, where, def.description),
229
248
  };
230
249
  };
@@ -249,17 +268,18 @@ const filesModule = (state, scope, name, def) => {
249
268
  for (const key of ['modules', 'entry'].filter((key) => def[key] !== undefined))
250
269
  state.fail(`${where}.${key}: a files module has no modules; use dir for a folder of them`);
251
270
  const exposed = exposes(state, scope, `${where}.exposes`, def.exposes, undefined, false, false);
271
+ const test = isRecord(def.test) ? def.test : {};
252
272
  const module = {
253
273
  kind: 'files',
254
274
  name,
255
275
  patterns: patterns(state, `${where}.files`, def.files),
256
276
  using: references(state, scope, `${where}.dependencies`, def.dependencies, false),
257
277
  ...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
278
+ ...rulesetsAt(state, where, def.ruleset, test.ruleset),
258
279
  ...description(state, where, def.description),
259
280
  };
260
- const test = isRecord(def.test) ? def.test : {};
261
- for (const key of Object.keys(test).filter((key) => key !== 'modules'))
262
- state.fail(`${where}.test.${key}: a files module's test block holds its test modules only`);
281
+ for (const key of Object.keys(test).filter((key) => key !== 'modules' && key !== 'ruleset'))
282
+ state.fail(`${where}.test.${key}: a files module's test block holds its test modules and ruleset only`);
263
283
  const tests = test.modules === undefined ? {} : record(state, `${where}.test.modules`, test.modules);
264
284
  const lifted = Object.entries(tests).map(([inner, raw]) => {
265
285
  const testDef = record(state, `${where}.test.modules.${inner}`, raw);
@@ -322,7 +342,10 @@ const resolveName = (state, scope, entry, tests, where) => {
322
342
  const parts = top ? rest : [head, ...rest];
323
343
  if (parts.length === 0 || parts.length > 2 || !parts.every(isName))
324
344
  return fail(state, where, entry, 'a name is a module, a module and one of its surfaces, or an input');
325
- const [module, surface] = parts;
345
+ const whole = parts.join('.');
346
+ const [module, surface] = searchedFrom(scope, top).some((level) => level.names.has(whole))
347
+ ? [whole, undefined]
348
+ : parts;
326
349
  const name = { module, ...(surface === undefined ? {} : { surface }), top, tests, where, entry };
327
350
  const named = moduleRef(state, scope, name);
328
351
  if (named !== undefined)
@@ -343,7 +366,7 @@ const moduleRef = (state, scope, name) => {
343
366
  const found = searchedFrom(scope, name.top).find((level) => level.names.has(name.module));
344
367
  if (!found)
345
368
  return undefined;
346
- if (found === scope && name.module === scope.own && !name.top) {
369
+ if (found === scope && name.module === scope.own) {
347
370
  fail(state, name.where, name.entry, `a module reaches its own files already`);
348
371
  return null;
349
372
  }
@@ -353,6 +376,7 @@ const moduleRef = (state, scope, name) => {
353
376
  module: name.module,
354
377
  ...(name.surface === undefined ? {} : { surface: name.surface }),
355
378
  ...(up > 0 ? { up } : {}),
379
+ ...(name.top ? { top: true } : {}),
356
380
  };
357
381
  state.pending.push({ ref, where: name.where, archetype: found.archetype, tests: name.tests });
358
382
  return ref;
@@ -374,7 +398,16 @@ const outOfScope = (state, scope, { module, top, tests, where, entry }) => {
374
398
  const names = searchedFrom(scope, top).flatMap((level) => [...level.names].filter((name) => level !== scope || name !== scope.own));
375
399
  const inScope = [...new Set([...names, ...inputs])];
376
400
  const testInput = !tests && scope.testInputs.has(module) ? `; ${module} is a test input, which only test code may name` : '';
377
- return fail(state, where, entry, `no module or input called ${module} here${testInput}; in scope: ${list(inScope.sort(), 'nothing')}`);
401
+ const named = scope.archetype.split('.')[0];
402
+ const hints = testInput !== ''
403
+ ? []
404
+ : named !== rootName && !top
405
+ ? [`a module outside ${named} comes in through ${named}.requires`]
406
+ : entry === module && /^[\w-]+$/.test(module) && where.endsWith('dependencies')
407
+ ? [`a package is npm:${module}`]
408
+ : [];
409
+ return fail(state, where, entry, `no module or input called ${module} here${testInput}; in scope: ${list(inScope.sort(), 'nothing')}` +
410
+ hints.map((hint) => `. ${hint[0].toUpperCase()}${hint.slice(1)}`).join(''));
378
411
  };
379
412
  const fail = (state, where, entry, problem) => {
380
413
  state.fail(`${where}: '${entry}': ${problem}`);
@@ -3,6 +3,7 @@ export interface ModuleRefData {
3
3
  module: string;
4
4
  surface?: string;
5
5
  up?: number;
6
+ top?: true;
6
7
  }
7
8
  export interface RequiredRefData {
8
9
  kind: 'required';
@@ -14,7 +15,8 @@ export interface PackageRefData {
14
15
  pattern: string;
15
16
  }
16
17
  export type RefData = ModuleRefData | RequiredRefData | PackageRefData;
17
- export type RuleSettingsData = 'off' | Record<string, boolean | Record<string, unknown>>;
18
+ export type RuleSettingsData = Record<string, boolean | Record<string, unknown>>;
19
+ export type RulesetData = readonly RuleSettingsData[];
18
20
  export type ExposesData = {
19
21
  kind: 'all';
20
22
  } | {
@@ -33,7 +35,8 @@ export interface FilesModuleData {
33
35
  exposes?: Exclude<ExposesData, {
34
36
  kind: 'surfaces';
35
37
  }>;
36
- rules?: RuleSettingsData;
38
+ ruleset?: RulesetData;
39
+ testRuleset?: RulesetData;
37
40
  description?: string;
38
41
  }
39
42
  export interface DirModuleData {
@@ -45,7 +48,8 @@ export interface DirModuleData {
45
48
  using: RefData[];
46
49
  inputs?: Record<string, RefData>;
47
50
  testInputs?: Record<string, RefData>;
48
- rules?: RuleSettingsData;
51
+ ruleset?: RulesetData;
52
+ testRuleset?: RulesetData;
49
53
  description?: string;
50
54
  }
51
55
  export interface TestModuleData {
@@ -57,7 +61,7 @@ export interface TestModuleData {
57
61
  exposes?: Exclude<ExposesData, {
58
62
  kind: 'surfaces';
59
63
  }>;
60
- rules?: RuleSettingsData;
64
+ ruleset?: RulesetData;
61
65
  description?: string;
62
66
  }
63
67
  export type ModuleData = FilesModuleData | DirModuleData | TestModuleData;
@@ -77,12 +81,12 @@ export interface ArchetypeData {
77
81
  exposes?: ExposesData;
78
82
  testExposes?: Record<string, RefData[]>;
79
83
  testUsing?: RefData[];
80
- rules?: RuleSettingsData;
84
+ ruleset?: RulesetData;
85
+ testRuleset?: RulesetData;
81
86
  }
82
87
  export interface ConfigData {
83
88
  file: string;
84
89
  root: string;
85
90
  archetypes: Record<string, ArchetypeData>;
86
91
  tsconfig: string[];
87
- rules?: RuleSettingsData;
88
92
  }
@@ -28,6 +28,7 @@ export type Verdict = {
28
28
  } & Refusal);
29
29
  export interface Verdicts {
30
30
  reach(file: string): readonly Grant[] | undefined;
31
+ grants(module: ModuleView, view?: View): readonly Grant[];
31
32
  exposes(module: ModuleView): ExposesData | undefined;
32
33
  surface(module: ModuleView, name?: string, view?: View): ReadonlySet<string>;
33
34
  verdict(from: string, to: string): Verdict | undefined;
@@ -1,5 +1,5 @@
1
- import { show } from './references.js';
2
- import { declarationOf, fillPattern, globRegex } from './resolve.js';
1
+ import { show } from './text.js';
2
+ import { ancestors, declarationOf, fillPattern, globRegex, subtree } from './resolve.js';
3
3
  export const grantText = ({ owner, ref }) => (ref === undefined ? owner : `${owner} uses ${ref}`);
4
4
  const none = new Set();
5
5
  const union = (sets) => {
@@ -9,14 +9,11 @@ const union = (sets) => {
9
9
  all.add(file);
10
10
  return all;
11
11
  };
12
- const ancestors = function* (module) {
13
- for (let at = module.parent; at; at = at.parent)
14
- yield at;
15
- };
16
12
  export const verdicts = (config, model) => {
17
13
  const state = { config, model, surfaces: new Map(), reaches: new Map() };
18
14
  return {
19
15
  reach: (file) => reach(state, file),
16
+ grants: (module, view = 'production') => using(state, module, view),
20
17
  exposes: (module) => exposes(state, module),
21
18
  surface: (module, name, view = 'production') => surface(state, module, name, view),
22
19
  verdict: (from, to) => verdict(state, from, to),
@@ -194,7 +191,6 @@ const filesTests = (state, module, of) => {
194
191
  ...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
195
192
  ];
196
193
  };
197
- const subtree = (module) => [module, ...module.children.flatMap(subtree)];
198
194
  const testKit = (state, at) => grants(state, at, `${at.archetype}.test.provides`, state.config.archetypes[at.archetype].testUsing ?? [], 'test');
199
195
  const using = (state, module, view) => {
200
196
  const declared = declarationOf(state.config, module);
@@ -28,3 +28,5 @@ export declare const fillPattern: (pattern: string, captures: Record<string, str
28
28
  export declare const resolveModel: (config: ConfigData, folders: Folders, files: readonly string[]) => Model;
29
29
  export declare const specificity: (pattern: string) => number;
30
30
  export declare const globRegex: (pattern: string) => RegExp;
31
+ export declare const ancestors: (module: ModuleView) => Generator<ModuleView>;
32
+ export declare const subtree: (module: ModuleView) => ModuleView[];
@@ -1,4 +1,4 @@
1
- import { ConfigError } from '../configError.js';
1
+ import { ConfigError } from './configError.js';
2
2
  export const declarationOf = (config, module) => module.parent && config.archetypes[module.parent.archetype].modules.find((data) => data.name === module.name);
3
3
  export const rootId = '(root)';
4
4
  const placeholders = /\{(\w+)\}/g;
@@ -174,7 +174,8 @@ const claimsIn = (resolution, module, archetype) => {
174
174
  const claimsOf = (resolution, module, declared) => {
175
175
  const child = resolution.config.archetypes[declared.archetype];
176
176
  return declared.paths.flatMap((path) => matchFolders(resolution.folders, module.dir, path).flatMap((match) => {
177
- const captures = identify(resolution, child, match.dir, match.captures, module, { declared, path });
177
+ const inherited = child.inline ? { ...module.captures, ...match.captures } : match.captures;
178
+ const captures = identify(resolution, child, match.dir, inherited, module, { declared, path });
178
179
  return captures ? [{ module: declared, path, archetype: child, ...match, captures }] : [];
179
180
  }));
180
181
  };
@@ -249,7 +250,7 @@ const filesModule = (resolution, module, archetype, candidates, file) => {
249
250
  for (const pattern of declared.patterns) {
250
251
  const filled = fill(pattern, module.captures);
251
252
  if ('missing' in filled) {
252
- resolution.errors.add(`${module.id}: ${archetype.name}.${declared.name} '${pattern}' names {${filled.missing}}, which ${module.id} doesn't capture`);
253
+ resolution.errors.add(`${archetype.name}.${declared.name}.files: '${pattern}' names {${filled.missing}}, which ${module.id} doesn't capture`);
253
254
  }
254
255
  else if (globRegex(filled.filled).test(path))
255
256
  matches.push({ module: declared.name, pattern, score: specificity(filled.filled) });
@@ -300,3 +301,8 @@ export const globRegex = (pattern) => {
300
301
  globCache.set(pattern, regex);
301
302
  return regex;
302
303
  };
304
+ export const ancestors = function* (module) {
305
+ for (let at = module.parent; at; at = at.parent)
306
+ yield at;
307
+ };
308
+ export const subtree = (module) => [module, ...module.children.flatMap(subtree)];
@@ -7,7 +7,6 @@ export interface RuleAt {
7
7
  export interface Settings {
8
8
  atFile(file: string, id: string, defaults?: object): RuleAt;
9
9
  atModule(module: ModuleView, id: string, defaults?: object): RuleAt;
10
- decidedAt(module: ModuleView, id: string): boolean | undefined;
11
10
  }
12
11
  export declare const settings: (config: ConfigData, model: Model) => Settings;
13
12
  export type ResolvedRules = Record<string, false | Record<string, unknown>>;
@@ -19,3 +18,4 @@ export declare const rulesOf: (config: ConfigData, model: Model, rules: readonly
19
18
  id: string;
20
19
  defaults?: object;
21
20
  }[]) => RulesOf;
21
+ export declare const anyRuleOn: (config: ConfigData) => boolean;
@@ -0,0 +1,82 @@
1
+ import { declarationOf } from './resolve.js';
2
+ import { isRecord } from './shared.js';
3
+ const archetypeOf = (config, module) => module.archetype === undefined ? undefined : config.archetypes[module.archetype];
4
+ const own = (config, module) => [
5
+ archetypeOf(config, module)?.ruleset,
6
+ declarationOf(config, module)?.ruleset,
7
+ ];
8
+ const ownTests = (config, module) => [
9
+ archetypeOf(config, module)?.testRuleset,
10
+ declarationOf(config, module)?.testRuleset,
11
+ ];
12
+ const production = (config, module) => [
13
+ ...(module.parent ? production(config, module.parent) : []),
14
+ ...own(config, module),
15
+ ];
16
+ const tests = (config, module) => [
17
+ ...(module.parent ? tests(config, module.parent) : []),
18
+ ...ownTests(config, module),
19
+ ];
20
+ const filesModuleOf = (config, holder, test) => {
21
+ const of = declarationOf(config, test)?.of;
22
+ return of === undefined ? undefined : archetypeOf(config, holder).modules.find((module) => module.name === of);
23
+ };
24
+ const layersOf = (config, module) => {
25
+ if (!module.test)
26
+ return production(config, module);
27
+ const chain = [];
28
+ let holder = module;
29
+ for (; holder.test && holder.parent; holder = holder.parent)
30
+ chain.unshift(holder);
31
+ const files = filesModuleOf(config, holder, chain[0]);
32
+ return [
33
+ ...production(config, holder),
34
+ files?.ruleset,
35
+ ...tests(config, holder),
36
+ files?.testRuleset,
37
+ ...chain.flatMap((test) => own(config, test)),
38
+ ];
39
+ };
40
+ const ruleAt = (layers, id, defaults = {}) => {
41
+ const at = { on: false, options: { ...defaults } };
42
+ for (const layer of layers) {
43
+ const setting = Object.hasOwn(layer, id) ? layer[id] : layer['*'];
44
+ if (setting === undefined)
45
+ continue;
46
+ at.on = setting !== false;
47
+ if (isRecord(setting))
48
+ Object.assign(at.options, setting);
49
+ }
50
+ return at;
51
+ };
52
+ export const settings = (config, model) => {
53
+ const cache = new Map();
54
+ const at = (module) => {
55
+ if (!module)
56
+ return [];
57
+ let found = cache.get(module);
58
+ if (!found)
59
+ cache.set(module, (found = layersOf(config, module).flatMap((ruleset) => ruleset ?? [])));
60
+ return found;
61
+ };
62
+ return {
63
+ atFile: (file, id, defaults) => ruleAt(at(model.moduleOf(file)), id, defaults),
64
+ atModule: (module, id, defaults) => ruleAt(at(module), id, defaults),
65
+ };
66
+ };
67
+ export const rulesOf = (config, model, rules) => {
68
+ const settled = settings(config, model);
69
+ return {
70
+ defaults: Object.fromEntries(rules.map(({ id, defaults }) => [id, { ...defaults }])),
71
+ module: (module) => Object.fromEntries(rules.map(({ id, defaults }) => {
72
+ const { on, options } = settled.atModule(module, id, defaults);
73
+ return [id, on ? options : false];
74
+ })),
75
+ };
76
+ };
77
+ const turnsOn = (ruleset) => ruleset !== undefined && ruleset.some((layer) => Object.values(layer).some((setting) => setting !== false));
78
+ const rulesetsOf = (place) => [
79
+ place.ruleset,
80
+ 'testRuleset' in place ? place.testRuleset : undefined,
81
+ ];
82
+ export const anyRuleOn = (config) => Object.values(config.archetypes).some((archetype) => [archetype, ...archetype.modules].flatMap(rulesetsOf).some(turnsOn));
@@ -0,0 +1,4 @@
1
+ import type { ExposesData, RefData } from './data.ts';
2
+ export declare const packageText: (pattern: string) => string;
3
+ export declare const show: (ref: RefData) => string;
4
+ export declare const exposesText: (exposes: ExposesData | undefined) => string;
@@ -0,0 +1,13 @@
1
+ export const packageText = (pattern) => pattern.startsWith('node:') || pattern.startsWith('virtual:') ? pattern : `npm:${pattern}`;
2
+ export const show = (ref) => ref.kind === 'package'
3
+ ? packageText(ref.pattern)
4
+ : `${ref.kind === 'module' && ref.top ? 'top.' : ''}${ref.kind === 'required' ? ref.name : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
5
+ export const exposesText = (exposes) => {
6
+ if (exposes === undefined)
7
+ return 'nothing';
8
+ if (exposes.kind === 'all')
9
+ return 'all its files';
10
+ if (exposes.kind === 'files')
11
+ return `{ files: [${exposes.patterns.join(', ')}] }`;
12
+ return Object.keys(exposes.surfaces).join(', ');
13
+ };
@@ -2,4 +2,5 @@ import type { Rule } from './rule.ts';
2
2
  export declare const registry: <R extends {
3
3
  id: string;
4
4
  }>(rules: readonly R[]) => ReadonlyMap<string, R>;
5
+ export declare const pluginRulesets: (plugins: Record<string, unknown>) => Record<string, unknown>;
5
6
  export declare const pluginRules: (plugins: Record<string, unknown>) => Rule[];
@@ -9,10 +9,20 @@ export const registry = (rules) => {
9
9
  return byId;
10
10
  };
11
11
  const name = /^[a-z][a-z0-9-]*$/;
12
- export const pluginRules = (plugins) => Object.entries(plugins).flatMap(([namespace, plugin]) => namespaced(namespace, plugin, `config.plugins.${namespace}`));
12
+ export const pluginRulesets = (plugins) => Object.fromEntries(Object.entries(plugins).flatMap(([namespace, plugin]) => {
13
+ const rulesets = plugin.rulesets;
14
+ if (rulesets === undefined)
15
+ return [];
16
+ if (typeof rulesets !== 'object' || rulesets === null || Array.isArray(rulesets))
17
+ throw new ConfigError(`plugins.${namespace}: expected rulesets by name, { recommended: { rules: {...} } }`);
18
+ return Object.entries(rulesets).map(([ruleset, definition]) => [`${namespace}:${ruleset}`, definition]);
19
+ }));
20
+ export const pluginRules = (plugins) => Object.entries(plugins).flatMap(([namespace, plugin]) => namespaced(namespace, plugin, `plugins.${namespace}`));
13
21
  const namespaced = (namespace, plugin, at) => {
14
22
  if (!name.test(namespace))
15
23
  throw new ConfigError(`${at}: a namespace is lowercase letters, digits and dashes`);
24
+ if (namespace === 'warp')
25
+ throw new ConfigError(`${at}: warp is the namespace of warp's own rulesets; name it otherwise`);
16
26
  const rules = typeof plugin === 'object' && plugin !== null ? plugin.rules : undefined;
17
27
  if (!Array.isArray(rules))
18
28
  throw new ConfigError(`${at}: expected a plugin, { rules: Rule[] }, as the default export of its file`);
@@ -1,7 +1,7 @@
1
- import type { ConfigData } from '../model/archetype/data.ts';
2
- import type { Verdicts } from '../model/archetype/reach.ts';
3
- import type { Model, ModuleView } from '../model/archetype/resolve.ts';
4
- import type { FileFacts, Project } from '../model/facts.ts';
1
+ import type { ConfigData } from '../model/data.ts';
2
+ import type { Verdicts } from '../model/reach.ts';
3
+ import type { Model, ModuleView } from '../model/resolve.ts';
4
+ import type { FileFacts, Project } from '../facts/facts.ts';
5
5
  export interface Site {
6
6
  file: string;
7
7
  line: number;
@@ -51,8 +51,14 @@ export interface ProjectRule<Options extends object = object> extends RuleBase<O
51
51
  check: (context: ProjectContext<Options>) => Finding[];
52
52
  }
53
53
  export type Rule = FileRule<any> | ProjectRule<any>;
54
+ export type RuleSetting = 'on' | 'off' | boolean | Record<string, unknown>;
55
+ export interface RulesetDefinition {
56
+ extends?: readonly string[];
57
+ rules?: Readonly<Record<string, RuleSetting>>;
58
+ }
54
59
  export interface Plugin {
55
60
  rules: readonly Rule[];
61
+ rulesets?: Readonly<Record<string, RulesetDefinition>>;
56
62
  }
57
63
  export declare const noOptions: (raw: Record<string, unknown>, at: string) => Partial<object>;
58
64
  export declare const wholeNumberOptions: <Options extends Record<string, number>>(defaults: Options) => (raw: Record<string, unknown>, at: string) => Partial<Options>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { loadConfigData, type LoadedConfigData } from './app/load.ts';
2
- export type * from './model/archetype/data.ts';
3
- export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './model/facts.ts';
4
- export type { Model, ModuleView } from './model/archetype/resolve.ts';
5
- export type { Grant, Refusal, Verdict, Verdicts } from './model/archetype/reach.ts';
6
- export { ConfigError } from './model/configError.ts';
7
- export { type Finding, type FileContext, type FileRule, type Plugin, type ProjectContext, type ProjectRule, type Rule, type Setting, wholeNumberOptions, } from './rules/rule.ts';
2
+ export type * from './domain/model/data.ts';
3
+ export type { Complexity, FunctionFacts, ImportEdge, FileFacts, Member, MemberGraph, MemberKind, } from './domain/facts/facts.ts';
4
+ export type { Model, ModuleView } from './domain/model/resolve.ts';
5
+ export type { Grant, Refusal, Verdict, Verdicts } from './domain/model/reach.ts';
6
+ export { ConfigError } from './domain/model/configError.ts';
7
+ export { type Finding, type FileContext, type FileRule, type Plugin, type RuleSetting, type RulesetDefinition, type ProjectContext, type ProjectRule, type Rule, type Setting, wholeNumberOptions, } from './domain/rules/rule.ts';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { loadConfigData } from './app/load.js';
2
- export { ConfigError } from './model/configError.js';
3
- export { wholeNumberOptions, } from './rules/rule.js';
2
+ export { ConfigError } from './domain/model/configError.js';
3
+ export { wholeNumberOptions, } from './domain/rules/rule.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yearofthedan/warp",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Architectural fitness checks for TypeScript codebases",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,6 +36,7 @@
36
36
  "@stryker-mutator/core": "10.1.1",
37
37
  "@stryker-mutator/vitest-runner": "10.1.1",
38
38
  "@types/node": "26.6.6",
39
+ "c8": "10.1.3",
39
40
  "secretlint": "14.0.1",
40
41
  "vite-plus": "catalog:"
41
42
  },
@@ -1,2 +0,0 @@
1
- import type { Folders } from '../model/archetype/resolve.ts';
2
- export declare const diskFolders: (root: string) => Folders;
@@ -1,2 +0,0 @@
1
- import type { SourceFile } from 'typescript/ast';
2
- export declare const moduleSpecifiers: (sourceFile: SourceFile) => string[];
@@ -1,6 +0,0 @@
1
- import { isExportDeclaration, isImportDeclaration, isStringLiteralLikeNode } from 'typescript/ast/is';
2
- export const moduleSpecifiers = (sourceFile) => sourceFile.statements.flatMap((statement) => (isImportDeclaration(statement) || isExportDeclaration(statement)) &&
3
- statement.moduleSpecifier &&
4
- isStringLiteralLikeNode(statement.moduleSpecifier)
5
- ? [statement.moduleSpecifier.text]
6
- : []);
@@ -1,2 +0,0 @@
1
- import type { Analyzer } from '../app/ports.ts';
2
- export declare const typescriptAnalyzer: Analyzer;
@@ -1,5 +0,0 @@
1
- import type { Finding } from '../rules/rule.ts';
2
- import type { Model } from '../model/archetype/resolve.ts';
3
- import type { Settings } from '../model/archetype/settings.ts';
4
- export declare const unclassified = "unclassified";
5
- export declare const unclassifiedFindings: (model: Model, settled: Settings, docs: string | undefined) => Finding[];
@@ -1,13 +0,0 @@
1
- export const unclassified = 'unclassified';
2
- export const unclassifiedFindings = (model, settled, docs) => model.modules.flatMap((module) => (settled.decidedAt(module, unclassified) ?? module.parent === undefined)
3
- ? module.looseFiles.map((file) => ({
4
- rule: unclassified,
5
- key: `${unclassified}:${file}`,
6
- file,
7
- line: 1,
8
- value: 1,
9
- message: `${file} is in no module of ${module.id} (${module.archetype}), so nothing says what it may import. ` +
10
- `Add a files module to ${module.archetype} that matches it, or move it into a module's folder.`,
11
- ...(docs ? { docs } : {}),
12
- }))
13
- : []);
@@ -1,2 +0,0 @@
1
- import { type ProjectRule } from '../../rules/rule.ts';
2
- export declare const dependencyDirection: ProjectRule;
@@ -1,2 +0,0 @@
1
- import { type ProjectRule } from '../../rules/rule.ts';
2
- export declare const moduleExternals: ProjectRule;
@@ -1,2 +0,0 @@
1
- import { type ProjectRule } from '../../rules/rule.ts';
2
- export declare const noCrossModuleReexport: ProjectRule;
@@ -1,2 +0,0 @@
1
- import { type ProjectRule } from '../../rules/rule.ts';
2
- export declare const noDoubleExport: ProjectRule;
@@ -1,2 +0,0 @@
1
- import { type FileRule } from '../../rules/rule.ts';
2
- export declare const unresolvedImport: FileRule;
@@ -1,2 +0,0 @@
1
- import { type ProjectRule } from '../../rules/rule.ts';
2
- export declare const unusedDeclaration: ProjectRule;
@@ -1,13 +0,0 @@
1
- export declare const configName = "warp.yaml";
2
- export declare const findConfig: (dir: string) => string;
3
- export interface LoadedConfig {
4
- raw: unknown;
5
- plugins: Record<string, unknown>;
6
- lines: ReadonlyMap<string, number>;
7
- digest: string;
8
- }
9
- export declare const parseConfig: (text: string, file: string) => {
10
- raw: unknown;
11
- lines: Map<string, number>;
12
- };
13
- export declare const loadConfig: (file: string) => Promise<LoadedConfig>;
@@ -1,5 +0,0 @@
1
- import { type ConfigData, type RuleSettingsData } from './data.ts';
2
- import { type Fail } from './shared.ts';
3
- export type ParseRules = (value: unknown, at: string) => RuleSettingsData | undefined;
4
- export declare const withRuleset: (config: ConfigData, rulesets: unknown, name: string | undefined, parse: ParseRules, fail: Fail) => ConfigData;
5
- export declare const recommended = "warp:recommended";