@yearofthedan/warp 0.4.1 → 0.5.1

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 (169) hide show
  1. package/README.md +6 -10
  2. package/dist/adapters/analysis/chains.d.ts +4 -0
  3. package/dist/adapters/analysis/chains.js +97 -0
  4. package/dist/adapters/analysis/classes.d.ts +3 -0
  5. package/dist/adapters/analysis/classes.js +109 -0
  6. package/dist/{analysis → adapters/analysis}/complexity.d.ts +1 -1
  7. package/dist/adapters/analysis/folders.d.ts +2 -0
  8. package/dist/{app/facts.d.ts → adapters/analysis/freshFacts.d.ts} +1 -2
  9. package/dist/{app/facts.js → adapters/analysis/freshFacts.js} +0 -10
  10. package/dist/{analysis → adapters/analysis}/imports.d.ts +2 -1
  11. package/dist/{analysis → adapters/analysis}/imports.js +60 -23
  12. package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
  13. package/dist/{analysis → adapters/analysis}/members.js +1 -1
  14. package/dist/{analysis → adapters/analysis}/source.d.ts +2 -2
  15. package/dist/{analysis → adapters/analysis}/source.js +2 -2
  16. package/dist/adapters/analysis/specifiers.d.ts +10 -0
  17. package/dist/adapters/analysis/specifiers.js +39 -0
  18. package/dist/adapters/analysis/typescript.d.ts +2 -0
  19. package/dist/{analysis → adapters/analysis}/typescript.js +14 -4
  20. package/dist/{config → adapters/config}/loadConfig.d.ts +2 -7
  21. package/dist/{config → adapters/config}/loadConfig.js +5 -4
  22. package/dist/{git → adapters/git}/cache.d.ts +1 -1
  23. package/dist/adapters/git/factsStore.d.ts +2 -0
  24. package/dist/adapters/git/factsStore.js +10 -0
  25. package/dist/{git → adapters/git}/repository.d.ts +1 -1
  26. package/dist/{config → adapters/git}/toolDigest.js +1 -1
  27. package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
  28. package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
  29. package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
  30. package/dist/app/check.d.ts +5 -6
  31. package/dist/app/check.js +3 -3
  32. package/dist/app/checkModel.d.ts +5 -5
  33. package/dist/app/checkModel.js +7 -8
  34. package/dist/app/configLines.d.ts +1 -1
  35. package/dist/app/diff.d.ts +1 -1
  36. package/dist/app/diff.js +1 -1
  37. package/dist/app/failures.d.ts +6 -0
  38. package/dist/app/failures.js +15 -0
  39. package/dist/app/load.d.ts +11 -5
  40. package/dist/app/load.js +23 -59
  41. package/dist/app/ports.d.ts +13 -3
  42. package/dist/builtins/advice.d.ts +4 -4
  43. package/dist/builtins/advice.js +1 -1
  44. package/dist/builtins/boundaries.d.ts +17 -0
  45. package/dist/builtins/boundaries.js +35 -0
  46. package/dist/builtins/class-cohesion/rule.d.ts +6 -0
  47. package/dist/builtins/class-cohesion/rule.js +34 -0
  48. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
  49. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
  50. package/dist/builtins/components.d.ts +1 -1
  51. package/dist/builtins/dependency-direction/rule.d.ts +2 -0
  52. package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +3 -3
  53. package/dist/builtins/export-consumers/rule.d.ts +6 -0
  54. package/dist/builtins/export-consumers/rule.js +65 -0
  55. package/dist/builtins/export-spread/rule.d.ts +3 -0
  56. package/dist/builtins/export-spread/rule.js +65 -0
  57. package/dist/builtins/export-surface/rule.d.ts +6 -0
  58. package/dist/builtins/export-surface/rule.js +60 -0
  59. package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
  60. package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
  61. package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
  62. package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
  63. package/dist/builtins/index.d.ts +2 -2
  64. package/dist/builtins/index.js +33 -13
  65. package/dist/builtins/loops.d.ts +1 -1
  66. package/dist/builtins/loops.js +1 -1
  67. package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
  68. package/dist/builtins/module-dependencies/rule.d.ts +3 -0
  69. package/dist/builtins/module-dependencies/rule.js +67 -0
  70. package/dist/builtins/module-externals/rule.d.ts +2 -0
  71. package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
  72. package/dist/builtins/module-size/rule.d.ts +6 -0
  73. package/dist/builtins/module-size/rule.js +36 -0
  74. package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
  75. package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
  76. package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
  77. package/dist/builtins/no-double-export/rule.d.ts +2 -0
  78. package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
  79. package/dist/builtins/packages.d.ts +1 -1
  80. package/dist/builtins/place.d.ts +1 -1
  81. package/dist/builtins/shared.d.ts +1 -1
  82. package/dist/builtins/unclassified/rule.d.ts +2 -0
  83. package/dist/builtins/unclassified/rule.js +15 -0
  84. package/dist/builtins/unresolved-import/rule.d.ts +2 -0
  85. package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
  86. package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
  87. package/dist/builtins/unused-declaration/empty.d.ts +1 -1
  88. package/dist/builtins/unused-declaration/empty.js +1 -1
  89. package/dist/builtins/unused-declaration/grants.d.ts +1 -1
  90. package/dist/builtins/unused-declaration/grants.js +42 -10
  91. package/dist/builtins/unused-declaration/rule.d.ts +2 -0
  92. package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
  93. package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
  94. package/dist/builtins/unused-declaration/surfaces.js +1 -1
  95. package/dist/cli.js +34 -54
  96. package/dist/{model → domain/facts}/facts.d.ts +20 -0
  97. package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
  98. package/dist/{model/archetype → domain/fixes}/fixes.js +2 -6
  99. package/dist/domain/language/compile.d.ts +12 -0
  100. package/dist/domain/language/compile.js +58 -0
  101. package/dist/{model/archetype → domain/language}/references.d.ts +6 -7
  102. package/dist/{model/archetype → domain/language}/references.js +41 -26
  103. package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
  104. package/dist/{model/archetype → domain/language}/requirements.js +2 -1
  105. package/dist/domain/language/rulesets.d.ts +11 -0
  106. package/dist/domain/language/rulesets.js +60 -0
  107. package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
  108. package/dist/{model/archetype/language.js → domain/language/structure.js} +33 -12
  109. package/dist/{model/archetype → domain/model}/data.d.ts +9 -6
  110. package/dist/{model/archetype → domain/model}/reach.d.ts +2 -0
  111. package/dist/{model/archetype → domain/model}/reach.js +10 -7
  112. package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
  113. package/dist/{model/archetype → domain/model}/resolve.js +6 -1
  114. package/dist/{model/archetype → domain/model}/settings.d.ts +3 -3
  115. package/dist/domain/model/settings.js +83 -0
  116. package/dist/domain/model/text.d.ts +4 -0
  117. package/dist/domain/model/text.js +13 -0
  118. package/dist/{rules → domain/rules}/registry.d.ts +1 -0
  119. package/dist/{rules → domain/rules}/registry.js +11 -1
  120. package/dist/{rules → domain/rules}/rule.d.ts +11 -4
  121. package/dist/{rules → domain/rules}/rule.js +1 -1
  122. package/dist/index.d.ts +6 -6
  123. package/dist/index.js +2 -2
  124. package/package.json +1 -1
  125. package/dist/analysis/folders.d.ts +0 -2
  126. package/dist/analysis/specifiers.d.ts +0 -2
  127. package/dist/analysis/specifiers.js +0 -6
  128. package/dist/analysis/typescript.d.ts +0 -2
  129. package/dist/app/unclassified.d.ts +0 -5
  130. package/dist/app/unclassified.js +0 -13
  131. package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
  132. package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
  133. package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
  134. package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
  135. package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
  136. package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
  137. package/dist/model/archetype/rulesets.d.ts +0 -5
  138. package/dist/model/archetype/rulesets.js +0 -139
  139. package/dist/model/archetype/settings.js +0 -54
  140. /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
  141. /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
  142. /package/dist/{git → adapters/git}/cache.js +0 -0
  143. /package/dist/{git → adapters/git}/repository.js +0 -0
  144. /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
  145. /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
  146. /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
  147. /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
  148. /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
  149. /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
  150. /package/dist/{reporters → adapters/reporters}/index.js +0 -0
  151. /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
  152. /package/dist/{reporters → adapters/reporters}/json.js +0 -0
  153. /package/dist/{reporters → adapters/reporters}/model.js +0 -0
  154. /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
  155. /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
  156. /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
  157. /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
  158. /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
  159. /package/dist/{reporters → adapters/reporters}/text.js +0 -0
  160. /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
  161. /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
  162. /package/dist/{model → domain/errors}/configError.d.ts +0 -0
  163. /package/dist/{model → domain/errors}/configError.js +0 -0
  164. /package/dist/{model → domain/facts}/facts.js +0 -0
  165. /package/dist/{model/archetype → domain/model}/data.js +0 -0
  166. /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
  167. /package/dist/{model/archetype → domain/model}/shared.js +0 -0
  168. /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
  169. /package/dist/{rules → domain/rules}/diff.js +0 -0
@@ -0,0 +1,65 @@
1
+ import { ignored, limitOptions, listed, valueUses, within } from '../boundaries.js';
2
+ const id = 'export-spread';
3
+ const defaults = { max: 2, ignore: [] };
4
+ export const exportSpread = {
5
+ id,
6
+ scope: 'project',
7
+ defaults,
8
+ moduleOptions: ['ignore'],
9
+ parseOptions: limitOptions(defaults),
10
+ check: ({ model, project, atModule }) => {
11
+ const uses = valueUses(model, project.files);
12
+ return model.modules.flatMap((module) => {
13
+ const { on, options } = atModule(module);
14
+ if (!on)
15
+ return [];
16
+ const skip = ignored(model, options.ignore);
17
+ return [...spreads(model, module, uses, skip).values()]
18
+ .filter((spread) => spread.children.size > options.max)
19
+ .map((spread) => finding(spread, module, model.moduleOf(spread.file), options.max));
20
+ });
21
+ },
22
+ };
23
+ const outside = (target, module, skip) => !within(target, module) && !skip.some((holder) => within(target, holder));
24
+ const spreads = (model, module, uses, skip) => {
25
+ const found = new Map();
26
+ for (const { file, edge, name } of uses) {
27
+ if (!outside(model.moduleOf(edge.to), module, skip))
28
+ continue;
29
+ const child = module.children.find((candidate) => !candidate.test && within(model.moduleOf(file), candidate));
30
+ if (!child)
31
+ continue;
32
+ const key = `${edge.to}#${name}`;
33
+ const spread = found.get(key) ?? { file: edge.to, name, children: new Map() };
34
+ found.set(key, spread);
35
+ spread.children.set(child, [...(spread.children.get(child) ?? []), { file, line: edge.line }]);
36
+ }
37
+ return found;
38
+ };
39
+ const finding = ({ file, name, children }, module, exporter, max) => {
40
+ const named = [...children.keys()].map((child) => child.id).sort();
41
+ const sites = [...children.values()].map(([first]) => first).toSorted((a, b) => a.file.localeCompare(b.file));
42
+ return {
43
+ rule: id,
44
+ key: `${id}:${module.id}:${file}#${name}`,
45
+ file: sites[0].file,
46
+ line: sites[0].line,
47
+ value: children.size,
48
+ limit: max,
49
+ message: `${children.size} of ${module.id}'s modules use ${name} from ${exporter.id}: ${listed(named)}. ` +
50
+ `Its limit here is ${max}. Give the use to the one module that should own it and let the others go through ` +
51
+ `that module, or name it in ${id}'s ignore on ${module.id} if it is meant to be shared.`,
52
+ sites,
53
+ parts: named,
54
+ details: {
55
+ module: module.id,
56
+ exporter: exporter.id,
57
+ file,
58
+ name,
59
+ children: [...children].map(([child, uses]) => ({
60
+ module: child.id,
61
+ files: [...new Set(uses.map((use) => use.file))],
62
+ })),
63
+ },
64
+ };
65
+ };
@@ -0,0 +1,6 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ declare const defaults: {
3
+ max: number;
4
+ };
5
+ export declare const exportSurface: ProjectRule<typeof defaults>;
6
+ export {};
@@ -0,0 +1,60 @@
1
+ import { wholeNumberOptions } from '../../domain/rules/rule.js';
2
+ import { within } from '../boundaries.js';
3
+ const id = 'export-surface';
4
+ const defaults = { max: 20 };
5
+ export const exportSurface = {
6
+ id,
7
+ scope: 'project',
8
+ defaults,
9
+ parseOptions: wholeNumberOptions(defaults),
10
+ check: ({ model, project, atModule }) => {
11
+ const production = new Set(project.files.map((file) => file.path).filter((path) => !model.isTest(path)));
12
+ const uses = project.files.flatMap(({ path, imports }) => production.has(path)
13
+ ? imports
14
+ .filter((edge) => !edge.reExport && production.has(edge.to))
15
+ .flatMap((edge) => edge.names
16
+ .filter((name) => name !== '*')
17
+ .map((name) => ({ from: path, file: edge.to, name, value: !edge.typeOnly })))
18
+ : []);
19
+ return model.modules.flatMap((module) => {
20
+ const { on, options } = atModule(module);
21
+ if (!on)
22
+ return [];
23
+ const names = surface(module, uses, (file) => model.moduleOf(file));
24
+ return names.length > options.max ? [finding(module, names, options.max)] : [];
25
+ });
26
+ },
27
+ };
28
+ const surface = (module, uses, moduleOf) => {
29
+ const names = new Map();
30
+ for (const { from, file, name, value } of uses) {
31
+ if (!within(moduleOf(file), module) || within(moduleOf(from), module))
32
+ continue;
33
+ const key = `${file}#${name}`;
34
+ const known = names.get(key);
35
+ names.set(key, { file, name, value: value || (known?.value ?? false) });
36
+ }
37
+ return [...names.values()].toSorted((a, b) => a.file.localeCompare(b.file) || a.name.localeCompare(b.name));
38
+ };
39
+ const finding = (module, names, max) => {
40
+ const values = names.filter((name) => name.value).length;
41
+ const byFile = Map.groupBy(names, (name) => name.file);
42
+ const [widest] = [...byFile].toSorted(([, a], [, b]) => b.length - a.length);
43
+ return {
44
+ rule: id,
45
+ key: `${id}:${module.id}`,
46
+ file: widest[0],
47
+ line: 1,
48
+ value: names.length,
49
+ limit: max,
50
+ message: `${module.id} offers ${names.length} names that other modules use (${counted(values, 'value')}, ${counted(names.length - values, 'type')}). ` +
51
+ `Its limit here is ${max}. Split it, or give it a smaller front.`,
52
+ details: {
53
+ module: module.id,
54
+ values,
55
+ types: names.length - values,
56
+ files: [...byFile].map(([file, found]) => ({ file, names: found.map((name) => name.name) })),
57
+ },
58
+ };
59
+ };
60
+ const counted = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
@@ -1,4 +1,4 @@
1
- import { type FileRule } from '../../rules/rule.ts';
1
+ import { type FileRule } from '../../domain/rules/rule.ts';
2
2
  declare const defaults: {
3
3
  maxLines: number;
4
4
  };
@@ -1,5 +1,5 @@
1
1
  import { components } from '../components.js';
2
- import { wholeNumberOptions } from '../../rules/rule.js';
2
+ import { wholeNumberOptions } from '../../domain/rules/rule.js';
3
3
  import { group } from '../shared.js';
4
4
  const defaults = { maxLines: 200 };
5
5
  export const fileCohesion = {
@@ -1,4 +1,4 @@
1
- import { type FileRule } from '../../rules/rule.ts';
1
+ import { type FileRule } from '../../domain/rules/rule.ts';
2
2
  declare const defaults: {
3
3
  maxLines: number;
4
4
  };
@@ -1,5 +1,5 @@
1
1
  import { components } from '../components.js';
2
- import { wholeNumberOptions } from '../../rules/rule.js';
2
+ import { wholeNumberOptions } from '../../domain/rules/rule.js';
3
3
  import { group, withOrdinals } from '../shared.js';
4
4
  const defaults = { maxLines: 40 };
5
5
  export const functionCohesion = {
@@ -1,4 +1,4 @@
1
- import type { Rule } from '../rules/rule.ts';
1
+ import type { Plugin, Rule } from '../domain/rules/rule.ts';
2
2
  export declare const builtinRules: readonly Rule[];
3
3
  export declare const builtinRegistry: ReadonlyMap<string, Rule>;
4
- export declare const unclassifiedDocs = "https://github.com/yearofthedan/warp/blob/main/src/builtins/unclassified/README.md";
4
+ export declare const warp: Plugin;
@@ -1,16 +1,24 @@
1
- import { registry } from '../rules/registry.js';
2
- import { cognitiveComplexity } from './cognitive-complexity/cognitiveComplexity.js';
3
- import { dependencyDirection } from './dependency-direction/dependencyDirection.js';
4
- import { fileCohesion } from './file-cohesion/fileCohesion.js';
5
- import { functionCohesion } from './function-cohesion/functionCohesion.js';
6
- import { moduleCycle } from './module-cycle/moduleCycle.js';
7
- import { moduleExternals } from './module-externals/moduleExternals.js';
8
- import { noCrossModuleReexport } from './no-cross-module-reexport/noCrossModuleReexport.js';
9
- import { noCycle } from './no-cycle/noCycle.js';
10
- import { noDoubleExport } from './no-double-export/noDoubleExport.js';
11
- import { unresolvedImport } from './unresolved-import/unresolvedImport.js';
12
- import { unusedDeclaration } from './unused-declaration/unusedDeclaration.js';
1
+ import { registry } from '../domain/rules/registry.js';
2
+ import { classCohesion } from './class-cohesion/rule.js';
3
+ import { cognitiveComplexity } from './cognitive-complexity/rule.js';
4
+ import { exportConsumers } from './export-consumers/rule.js';
5
+ import { exportSpread } from './export-spread/rule.js';
6
+ import { exportSurface } from './export-surface/rule.js';
7
+ import { dependencyDirection } from './dependency-direction/rule.js';
8
+ import { fileCohesion } from './file-cohesion/rule.js';
9
+ import { functionCohesion } from './function-cohesion/rule.js';
10
+ import { moduleDependencies } from './module-dependencies/rule.js';
11
+ import { moduleSize } from './module-size/rule.js';
12
+ import { moduleCycle } from './module-cycle/rule.js';
13
+ import { moduleExternals } from './module-externals/rule.js';
14
+ import { noCrossModuleReexport } from './no-cross-module-reexport/rule.js';
15
+ import { noCycle } from './no-cycle/rule.js';
16
+ import { noDoubleExport } from './no-double-export/rule.js';
17
+ import { unclassified } from './unclassified/rule.js';
18
+ import { unresolvedImport } from './unresolved-import/rule.js';
19
+ import { unusedDeclaration } from './unused-declaration/rule.js';
13
20
  export const builtinRules = [
21
+ unclassified,
14
22
  unresolvedImport,
15
23
  dependencyDirection,
16
24
  moduleExternals,
@@ -19,9 +27,15 @@ export const builtinRules = [
19
27
  noCycle,
20
28
  moduleCycle,
21
29
  fileCohesion,
30
+ classCohesion,
22
31
  functionCohesion,
23
32
  cognitiveComplexity,
24
33
  unusedDeclaration,
34
+ exportConsumers,
35
+ exportSpread,
36
+ exportSurface,
37
+ moduleDependencies,
38
+ moduleSize,
25
39
  ];
26
40
  const source = 'https://github.com/yearofthedan/warp/blob/main';
27
41
  const documented = (rule) => ({
@@ -29,4 +43,10 @@ const documented = (rule) => ({
29
43
  docs: `${source}/src/builtins/${rule.id}/README.md`,
30
44
  });
31
45
  export const builtinRegistry = registry(builtinRules.map(documented));
32
- export const unclassifiedDocs = `${source}/src/builtins/unclassified/README.md`;
46
+ export const warp = {
47
+ rules: [...builtinRegistry.values()],
48
+ rulesets: {
49
+ recommended: { rules: Object.fromEntries(builtinRules.map((rule) => [rule.id, 'on'])) },
50
+ utility: { rules: { 'export-consumers': 'off', 'export-surface': 'off' } },
51
+ },
52
+ };
@@ -1,4 +1,4 @@
1
- import type { ImportEdge } from '../model/facts.ts';
1
+ import type { ImportEdge } from '../domain/facts/facts.ts';
2
2
  export interface CycleOptions {
3
3
  types: 'count' | 'ignore';
4
4
  }
@@ -1,4 +1,4 @@
1
- import { ConfigError } from '../model/configError.js';
1
+ import { ConfigError } from '../domain/errors/configError.js';
2
2
  export const cycleDefaults = { types: 'count' };
3
3
  export const cycleOptions = (raw, at) => {
4
4
  const unknown = Object.keys(raw).filter((key) => key !== 'types');
@@ -1,3 +1,3 @@
1
- import type { ProjectRule } from '../../rules/rule.ts';
1
+ import type { ProjectRule } from '../../domain/rules/rule.ts';
2
2
  import { type CycleOptions } from '../loops.ts';
3
3
  export declare const moduleCycle: ProjectRule<CycleOptions>;
@@ -0,0 +1,3 @@
1
+ import type { ProjectRule } from '../../domain/rules/rule.ts';
2
+ import { type LimitOptions } from '../boundaries.ts';
3
+ export declare const moduleDependencies: ProjectRule<LimitOptions>;
@@ -0,0 +1,67 @@
1
+ import { crossed, ignored, limitOptions, listed, within } from '../boundaries.js';
2
+ const id = 'module-dependencies';
3
+ const defaults = { max: 4, ignore: [] };
4
+ export const moduleDependencies = {
5
+ id,
6
+ scope: 'project',
7
+ defaults,
8
+ moduleOptions: ['ignore'],
9
+ parseOptions: limitOptions(defaults),
10
+ check: ({ model, project, atModule }) => {
11
+ const imports = productionImports(model, project.files);
12
+ return model.modules.flatMap((module) => {
13
+ const { on, options } = atModule(module);
14
+ if (!on)
15
+ return [];
16
+ const boundaries = crossings(model, module, imports, ignored(model, options.ignore));
17
+ return boundaries.size > options.max ? [finding(module, boundaries, options.max)] : [];
18
+ });
19
+ },
20
+ };
21
+ const crossings = (model, module, imports, skip) => {
22
+ const boundaries = new Map();
23
+ for (const { file, to, line } of imports) {
24
+ const target = model.moduleOf(to);
25
+ if (!within(model.moduleOf(file), module) || within(target, module))
26
+ continue;
27
+ if (skip.some((holder) => within(target, holder)))
28
+ continue;
29
+ const boundary = crossed(module, target);
30
+ boundaries.set(boundary, [...(boundaries.get(boundary) ?? []), { file, line }]);
31
+ }
32
+ return boundaries;
33
+ };
34
+ const productionImports = (model, files) => {
35
+ const production = new Set(files.map((file) => file.path).filter((path) => !model.isTest(path)));
36
+ return files
37
+ .filter(({ path }) => production.has(path))
38
+ .flatMap(({ path, imports }) => imports
39
+ .map((edge) => ({ file: path, to: edge.via ?? edge.to, line: edge.line }))
40
+ .filter(({ to }) => production.has(to)));
41
+ };
42
+ const finding = (module, boundaries, max) => {
43
+ const named = [...boundaries.keys()].map((boundary) => boundary.id).sort();
44
+ const sites = [...boundaries.values()]
45
+ .map(([first]) => first)
46
+ .toSorted((a, b) => a.file.localeCompare(b.file) || a.line - b.line);
47
+ return {
48
+ rule: id,
49
+ key: `${id}:${module.id}`,
50
+ file: sites[0].file,
51
+ line: sites[0].line,
52
+ value: boundaries.size,
53
+ limit: max,
54
+ message: `${module.id} imports across ${boundaries.size} boundaries: ${listed(named)}. Its limit here is ${max}. ` +
55
+ 'Split it along what each part depends on, or reach some of them through one module. A module meant to wire ' +
56
+ `everything together, such as a composition root, turns ${id} off or raises its max.`,
57
+ sites,
58
+ parts: named,
59
+ details: {
60
+ module: module.id,
61
+ boundaries: [...boundaries].map(([boundary, uses]) => ({
62
+ module: boundary.id,
63
+ files: [...new Set(uses.map((use) => use.file))],
64
+ })),
65
+ },
66
+ };
67
+ };
@@ -0,0 +1,2 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const moduleExternals: ProjectRule;
@@ -1,8 +1,8 @@
1
1
  import { listsPackage } from '../packages.js';
2
2
  import { place } from '../place.js';
3
- import { sitesOf } from '../../model/archetype/fixes.js';
4
- import { packageText } from '../../model/archetype/references.js';
5
- import { noOptions } from '../../rules/rule.js';
3
+ import { sitesOf } from '../../domain/fixes/fixes.js';
4
+ import { packageText } from '../../domain/model/text.js';
5
+ import { noOptions } from '../../domain/rules/rule.js';
6
6
  const id = 'module-externals';
7
7
  export const moduleExternals = {
8
8
  id,
@@ -0,0 +1,6 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ declare const defaults: {
3
+ max: number;
4
+ };
5
+ export declare const moduleSize: ProjectRule<typeof defaults>;
6
+ export {};
@@ -0,0 +1,36 @@
1
+ import { wholeNumberOptions } from '../../domain/rules/rule.js';
2
+ const id = 'module-size';
3
+ const defaults = { max: 1000 };
4
+ export const moduleSize = {
5
+ id,
6
+ scope: 'project',
7
+ defaults,
8
+ parseOptions: wholeNumberOptions(defaults),
9
+ check: ({ model, project, atModule }) => {
10
+ return model.modules.flatMap((module) => {
11
+ if (module.test)
12
+ return [];
13
+ const { on, options } = atModule(module);
14
+ if (!on)
15
+ return [];
16
+ const files = project.files
17
+ .filter(({ path }) => model.moduleOf(path) === module)
18
+ .map(({ path, lines }) => ({ file: path, lines }))
19
+ .toSorted((a, b) => b.lines - a.lines || a.file.localeCompare(b.file));
20
+ const total = files.reduce((sum, file) => sum + file.lines, 0);
21
+ return total > options.max ? [finding(module, files, total, options.max)] : [];
22
+ });
23
+ },
24
+ };
25
+ const finding = (module, files, total, max) => ({
26
+ rule: id,
27
+ key: `${id}:${module.id}`,
28
+ file: files[0].file,
29
+ line: 1,
30
+ value: total,
31
+ limit: max,
32
+ message: `${module.id} holds ${total} lines in its own files (limit ${max}): ` +
33
+ `${files.map(({ file, lines }) => `${file} ${lines}`).join(', ')}. ` +
34
+ 'Split it into modules that each hold one responsibility.',
35
+ details: { module: module.id, files },
36
+ });
@@ -0,0 +1,2 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const noCrossModuleReexport: ProjectRule;
@@ -1,5 +1,5 @@
1
1
  import { place } from '../place.js';
2
- import { noOptions } from '../../rules/rule.js';
2
+ import { noOptions } from '../../domain/rules/rule.js';
3
3
  const id = 'no-cross-module-reexport';
4
4
  export const noCrossModuleReexport = {
5
5
  id,
@@ -1,3 +1,3 @@
1
- import type { ProjectRule } from '../../rules/rule.ts';
1
+ import type { ProjectRule } from '../../domain/rules/rule.ts';
2
2
  import { type CycleOptions } from '../loops.ts';
3
3
  export declare const noCycle: ProjectRule<CycleOptions>;
@@ -0,0 +1,2 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const noDoubleExport: ProjectRule;
@@ -1,5 +1,5 @@
1
1
  import { place } from '../place.js';
2
- import { noOptions } from '../../rules/rule.js';
2
+ import { noOptions } from '../../domain/rules/rule.js';
3
3
  const id = 'no-double-export';
4
4
  const exposingBoth = (verdicts, module, from, to) => {
5
5
  for (let at = module; at; at = at.parent)
@@ -1,2 +1,2 @@
1
- import type { ExternalImport } from '../model/facts.ts';
1
+ import type { ExternalImport } from '../domain/facts/facts.ts';
2
2
  export declare const listsPackage: (pattern: string, external: Pick<ExternalImport, 'package' | 'specifier'>) => boolean;
@@ -1,2 +1,2 @@
1
- import type { Model, ModuleView } from '../model/archetype/resolve.ts';
1
+ import type { Model, ModuleView } from '../domain/model/resolve.ts';
2
2
  export declare const place: (model: Model, file: string, module?: ModuleView) => string;
@@ -1,4 +1,4 @@
1
- import type { Member } from '../model/facts.ts';
1
+ import type { Member } from '../domain/facts/facts.ts';
2
2
  export interface Group {
3
3
  names: string[];
4
4
  lines: [number, number];
@@ -0,0 +1,2 @@
1
+ import type { ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const unclassified: ProjectRule;
@@ -0,0 +1,15 @@
1
+ export const unclassified = {
2
+ id: 'unclassified',
3
+ scope: 'project',
4
+ check: ({ model, atModule }) => model.modules.flatMap((module) => atModule(module).on
5
+ ? module.looseFiles.map((file) => ({
6
+ rule: 'unclassified',
7
+ key: `unclassified:${file}`,
8
+ file,
9
+ line: 1,
10
+ value: 1,
11
+ message: `${file} is in no module of ${module.parent ? `${module.id} (${module.archetype})` : 'the root'}, so nothing says what it may import. ` +
12
+ `Add a files module to ${module.archetype} that matches it, or move it into a module's folder.`,
13
+ }))
14
+ : []),
15
+ };
@@ -0,0 +1,2 @@
1
+ import { type FileRule } from '../../domain/rules/rule.ts';
2
+ export declare const unresolvedImport: FileRule;
@@ -1,4 +1,4 @@
1
- import { noOptions } from '../../rules/rule.js';
1
+ import { noOptions } from '../../domain/rules/rule.js';
2
2
  const id = 'unresolved-import';
3
3
  export const unresolvedImport = {
4
4
  id,
@@ -1,6 +1,6 @@
1
- import type { ConfigData } from '../../model/archetype/data.ts';
2
- import type { ModuleView } from '../../model/archetype/resolve.ts';
3
- import type { Finding, ProjectContext } from '../../rules/rule.ts';
1
+ import type { ConfigData } from '../../domain/model/data.ts';
2
+ import type { ModuleView } from '../../domain/model/resolve.ts';
3
+ import type { Finding, ProjectContext } from '../../domain/rules/rule.ts';
4
4
  export declare const id = "unused-declaration";
5
5
  export type Layer = 'production' | 'test';
6
6
  export type UnusedDeclaration = {
@@ -1,3 +1,3 @@
1
- import type { Finding } from '../../rules/rule.ts';
1
+ import type { Finding } from '../../domain/rules/rule.ts';
2
2
  import { type Context } from './declarations.ts';
3
3
  export declare const emptyModules: (context: Context) => Finding[];
@@ -1,4 +1,4 @@
1
- import { isTestData } from '../../model/archetype/data.js';
1
+ import { isTestData } from '../../domain/model/data.js';
2
2
  import { childrenNamed, instancesOf, named, unused } from './declarations.js';
3
3
  export const emptyModules = (context) => Object.values(context.config.archetypes).flatMap((archetype) => {
4
4
  const instances = instancesOf(context, archetype.name);
@@ -1,3 +1,3 @@
1
- import type { Finding } from '../../rules/rule.ts';
1
+ import type { Finding } from '../../domain/rules/rule.ts';
2
2
  import { type Context } from './declarations.ts';
3
3
  export declare const unusedGrants: (context: Context) => Finding[];
@@ -1,19 +1,51 @@
1
- import { isTestData, } from '../../model/archetype/data.js';
2
- import { show } from '../../model/archetype/references.js';
1
+ import { isTestData, } from '../../domain/model/data.js';
2
+ import { show } from '../../domain/model/text.js';
3
3
  import { listsPackage } from '../packages.js';
4
- import { childrenNamed, instancesOf, named, unused } from './declarations.js';
4
+ import { childrenNamed, instancesOf, named, unused, within } from './declarations.js';
5
5
  export const unusedGrants = (context) => {
6
6
  const used = usedRefs(context);
7
7
  return declared(context, used)
8
8
  .filter(({ ref, holders }) => !used.has(ref) && holders.some((holder) => context.atModule(holder).on))
9
- .map(({ ref, declaredIn, layer, holders, ending, kit }) => {
9
+ .map(({ ref, declaredIn, layer, holders, ending, kit, inner }) => {
10
10
  const using = show(ref);
11
11
  const modules = holders.map((holder) => holder.id);
12
12
  const names = holders.map(named).join(', ');
13
13
  const files = kit ? `the tests of ${names}` : names;
14
- return unused(context.config, `${declaredIn}->${using}`, `${declaredIn} names ${using}, but nothing in ${files} imports through it. ${ending}`, { kind: 'grant', declaredIn, layer, using, modules });
14
+ const users = inner ? innerUsers(context, holders, ref, layer) : [];
15
+ const owner = declaredIn.slice(0, -'.dependencies'.length);
16
+ const sites = users.map((name) => `${owner}.${name}.dependencies`);
17
+ const message = users.length === 0
18
+ ? `${declaredIn} names ${using}, but nothing in ${files} imports through it. ${ending}`
19
+ : `${declaredIn} names ${using}, but only its modules ${users.join(', ')} import through it. ` +
20
+ `A module's dependencies are its own: name it in ${sites.join(' and ')}, and remove it here.`;
21
+ return unused(context.config, `${declaredIn}->${using}`, message, {
22
+ kind: 'grant',
23
+ declaredIn,
24
+ layer,
25
+ using,
26
+ modules,
27
+ });
15
28
  });
16
29
  };
30
+ const innerUsers = (context, holders, ref, layer) => {
31
+ const users = new Set();
32
+ for (const holder of holders) {
33
+ const grant = context.verdicts.grants(holder, layer).find((candidate) => candidate.declared === ref);
34
+ for (const file of context.project.files) {
35
+ const module = context.model.moduleOf(file.path);
36
+ if (grant && module && module !== holder && within(module, holder) && importsThrough(grant, file)) {
37
+ users.add(childOf(holder, module).name ?? module.id);
38
+ }
39
+ }
40
+ }
41
+ return [...users].sort();
42
+ };
43
+ const childOf = (holder, module) => {
44
+ let at = module;
45
+ while (at.parent !== holder)
46
+ at = at.parent;
47
+ return at;
48
+ };
17
49
  const declared = (context, used) => Object.values(context.config.archetypes).flatMap((archetype) => {
18
50
  const instances = instancesOf(context, archetype.name);
19
51
  const unusedInputs = new Set(archetype.requires.filter((name) => !bindingsOf(context.config, archetype, name).some((ref) => used.has(ref))));
@@ -36,6 +68,7 @@ const declared = (context, used) => Object.values(context.config.archetypes).fla
36
68
  layer,
37
69
  holders,
38
70
  ending: 'Remove it.',
71
+ inner: true,
39
72
  }));
40
73
  });
41
74
  const kit = (archetype.testUsing ?? []).map((ref) => ({
@@ -57,9 +90,8 @@ const usedRefs = ({ project, verdicts }) => {
57
90
  const used = new Set();
58
91
  for (const file of project.files) {
59
92
  const reach = verdicts.reach(file.path) ?? [];
60
- const targets = file.imports.map((edge) => edge.via ?? edge.to);
61
93
  for (const grant of reach) {
62
- if (!grant.declared || !permits(grant, targets, file.externals))
94
+ if (!grant.declared || !importsThrough(grant, file))
63
95
  continue;
64
96
  used.add(grant.declared);
65
97
  for (const bound of grant.via ?? [])
@@ -68,6 +100,6 @@ const usedRefs = ({ project, verdicts }) => {
68
100
  }
69
101
  return used;
70
102
  };
71
- const permits = (grant, targets, externals) => grant.package === undefined
72
- ? targets.some((to) => grant.files.has(to))
73
- : externals.some((external) => listsPackage(grant.package, external));
103
+ const importsThrough = (grant, file) => grant.package === undefined
104
+ ? file.imports.some((edge) => grant.files.has(edge.via ?? edge.to))
105
+ : file.externals.some((external) => listsPackage(grant.package, external));
@@ -0,0 +1,2 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const unusedDeclaration: ProjectRule;
@@ -1,4 +1,4 @@
1
- import { noOptions } from '../../rules/rule.js';
1
+ import { noOptions } from '../../domain/rules/rule.js';
2
2
  import { holding, id } from './declarations.js';
3
3
  import { emptyModules } from './empty.js';
4
4
  import { unusedGrants } from './grants.js';
@@ -1,3 +1,3 @@
1
- import type { Finding } from '../../rules/rule.ts';
1
+ import type { Finding } from '../../domain/rules/rule.ts';
2
2
  import { type Context } from './declarations.ts';
3
3
  export declare const unusedSurfaces: (context: Context) => Finding[];
@@ -1,4 +1,4 @@
1
- import { isTestData } from '../../model/archetype/data.js';
1
+ import { isTestData } from '../../domain/model/data.js';
2
2
  import { childrenNamed, instancesOf, named, unused, within } from './declarations.js';
3
3
  export const unusedSurfaces = (context) => {
4
4
  const edges = context.project.files.flatMap((file) => file.imports.map((edge) => ({ from: file.path, to: edge.via ?? edge.to })));