@yearofthedan/warp 0.4.1 → 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 (151) 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/{config → adapters/config}/loadConfig.d.ts +2 -7
  14. package/dist/{config → adapters/config}/loadConfig.js +5 -4
  15. package/dist/{git → adapters/git}/cache.d.ts +1 -1
  16. package/dist/adapters/git/factsStore.d.ts +2 -0
  17. package/dist/adapters/git/factsStore.js +10 -0
  18. package/dist/{git → adapters/git}/repository.d.ts +1 -1
  19. package/dist/{config → adapters/git}/toolDigest.js +1 -1
  20. package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
  21. package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
  22. package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
  23. package/dist/app/check.d.ts +5 -6
  24. package/dist/app/check.js +3 -3
  25. package/dist/app/checkModel.d.ts +5 -5
  26. package/dist/app/checkModel.js +4 -5
  27. package/dist/app/configLines.d.ts +1 -1
  28. package/dist/app/diff.d.ts +1 -1
  29. package/dist/app/diff.js +1 -1
  30. package/dist/app/failures.d.ts +6 -0
  31. package/dist/app/failures.js +15 -0
  32. package/dist/app/load.d.ts +11 -5
  33. package/dist/app/load.js +22 -59
  34. package/dist/app/ports.d.ts +13 -3
  35. package/dist/builtins/advice.d.ts +4 -4
  36. package/dist/builtins/advice.js +1 -1
  37. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
  38. package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
  39. package/dist/builtins/components.d.ts +1 -1
  40. package/dist/builtins/dependency-direction/rule.d.ts +2 -0
  41. package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +3 -3
  42. package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
  43. package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
  44. package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
  45. package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
  46. package/dist/builtins/index.d.ts +2 -2
  47. package/dist/builtins/index.js +18 -13
  48. package/dist/builtins/loops.d.ts +1 -1
  49. package/dist/builtins/loops.js +1 -1
  50. package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
  51. package/dist/builtins/module-externals/rule.d.ts +2 -0
  52. package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
  53. package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
  54. package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
  55. package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
  56. package/dist/builtins/no-double-export/rule.d.ts +2 -0
  57. package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
  58. package/dist/builtins/packages.d.ts +1 -1
  59. package/dist/builtins/place.d.ts +1 -1
  60. package/dist/builtins/shared.d.ts +1 -1
  61. package/dist/builtins/unclassified/rule.d.ts +2 -0
  62. package/dist/builtins/unclassified/rule.js +15 -0
  63. package/dist/builtins/unresolved-import/rule.d.ts +2 -0
  64. package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
  65. package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
  66. package/dist/builtins/unused-declaration/empty.d.ts +1 -1
  67. package/dist/builtins/unused-declaration/empty.js +1 -1
  68. package/dist/builtins/unused-declaration/grants.d.ts +1 -1
  69. package/dist/builtins/unused-declaration/grants.js +42 -10
  70. package/dist/builtins/unused-declaration/rule.d.ts +2 -0
  71. package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
  72. package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
  73. package/dist/builtins/unused-declaration/surfaces.js +1 -1
  74. package/dist/cli.js +34 -54
  75. package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
  76. package/dist/{model/archetype → domain/fixes}/fixes.js +2 -6
  77. package/dist/domain/language/compile.d.ts +11 -0
  78. package/dist/domain/language/compile.js +58 -0
  79. package/dist/{model/archetype → domain/language}/references.d.ts +3 -6
  80. package/dist/{model/archetype → domain/language}/references.js +16 -21
  81. package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
  82. package/dist/{model/archetype → domain/language}/requirements.js +2 -1
  83. package/dist/domain/language/rulesets.d.ts +10 -0
  84. package/dist/domain/language/rulesets.js +60 -0
  85. package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
  86. package/dist/{model/archetype/language.js → domain/language/structure.js} +32 -12
  87. package/dist/{model/archetype → domain/model}/data.d.ts +9 -6
  88. package/dist/{model/archetype → domain/model}/reach.d.ts +1 -0
  89. package/dist/{model/archetype → domain/model}/reach.js +3 -7
  90. package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
  91. package/dist/{model/archetype → domain/model}/resolve.js +6 -1
  92. package/dist/{model/archetype → domain/model}/settings.d.ts +0 -1
  93. package/dist/domain/model/settings.js +82 -0
  94. package/dist/domain/model/text.d.ts +4 -0
  95. package/dist/domain/model/text.js +13 -0
  96. package/dist/{rules → domain/rules}/registry.d.ts +1 -0
  97. package/dist/{rules → domain/rules}/registry.js +10 -0
  98. package/dist/{rules → domain/rules}/rule.d.ts +10 -4
  99. package/dist/index.d.ts +6 -6
  100. package/dist/index.js +2 -2
  101. package/package.json +1 -1
  102. package/dist/analysis/folders.d.ts +0 -2
  103. package/dist/analysis/specifiers.d.ts +0 -2
  104. package/dist/analysis/specifiers.js +0 -6
  105. package/dist/analysis/typescript.d.ts +0 -2
  106. package/dist/app/unclassified.d.ts +0 -5
  107. package/dist/app/unclassified.js +0 -13
  108. package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
  109. package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
  110. package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
  111. package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
  112. package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
  113. package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
  114. package/dist/model/archetype/rulesets.d.ts +0 -5
  115. package/dist/model/archetype/rulesets.js +0 -139
  116. package/dist/model/archetype/settings.js +0 -54
  117. /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
  118. /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
  119. /package/dist/{analysis → adapters/analysis}/members.js +0 -0
  120. /package/dist/{analysis → adapters/analysis}/source.d.ts +0 -0
  121. /package/dist/{analysis → adapters/analysis}/source.js +0 -0
  122. /package/dist/{git → adapters/git}/cache.js +0 -0
  123. /package/dist/{git → adapters/git}/repository.js +0 -0
  124. /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
  125. /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
  126. /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
  127. /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
  128. /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
  129. /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
  130. /package/dist/{reporters → adapters/reporters}/index.js +0 -0
  131. /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
  132. /package/dist/{reporters → adapters/reporters}/json.js +0 -0
  133. /package/dist/{reporters → adapters/reporters}/model.js +0 -0
  134. /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
  135. /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
  136. /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
  137. /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
  138. /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
  139. /package/dist/{reporters → adapters/reporters}/text.js +0 -0
  140. /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
  141. /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
  142. /package/dist/{model → domain/facts}/facts.d.ts +0 -0
  143. /package/dist/{model → domain/facts}/facts.js +0 -0
  144. /package/dist/{model → domain/model}/configError.d.ts +0 -0
  145. /package/dist/{model → domain/model}/configError.js +0 -0
  146. /package/dist/{model/archetype → domain/model}/data.js +0 -0
  147. /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
  148. /package/dist/{model/archetype → domain/model}/shared.js +0 -0
  149. /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
  150. /package/dist/{rules → domain/rules}/diff.js +0 -0
  151. /package/dist/{rules → domain/rules}/rule.js +0 -0
package/dist/app/load.js CHANGED
@@ -1,64 +1,27 @@
1
- import { pluginRules, registry } from '../rules/registry.js';
2
- import { ConfigError } from '../model/configError.js';
3
- import { noOptions } from '../rules/rule.js';
4
- import { parseStructure } from '../model/archetype/language.js';
5
- import { checkReferences, toRules } from '../model/archetype/references.js';
6
- import { checkInputs, markTests } from '../model/archetype/requirements.js';
7
- import { unclassified } from './unclassified.js';
8
- import { withRuleset } from '../model/archetype/rulesets.js';
9
- import { defined, isName, isRecord } from '../model/archetype/shared.js';
10
- const keys = ['root', 'archetypes', 'rulesets', 'plugins', 'tsconfig'];
11
- export const loadConfigData = (raw, { builtins, ruleset, file = 'warp.yaml', plugins = {} } = {}) => {
12
- const errors = [];
13
- const fail = (message) => {
14
- if (!errors.includes(message))
15
- errors.push(message);
16
- };
17
- const failed = () => {
18
- if (errors.length > 0)
19
- throw new ConfigError(errors.join('\n'));
20
- };
21
- if (!isRecord(raw))
22
- throw new ConfigError(`${file}: expected a mapping, root: { modules: ... }`);
23
- const unknownKeys = Object.keys(raw).filter((key) => !keys.includes(key));
24
- for (const key of unknownKeys)
25
- fail(`${key}: unknown key; a config takes ${keys.join(', ')}`);
26
- checkPlugins(raw.plugins, plugins, fail);
27
- const rules = [...registry([...(builtins ?? []), ...pluginRules(plugins)]).values()];
28
- const structure = parseStructure(raw.root, raw.archetypes, fail);
29
- failed();
30
- checkReferences(structure.archetypes, structure.pending, fail);
31
- markTests(structure.archetypes, fail);
32
- checkInputs(structure.archetypes, structure.pending, fail);
33
- const check = {
34
- fail,
35
- ruleIds: builtins && new Set([...rules.map((rule) => rule.id), unclassified]),
1
+ import { compileConfig } from '../domain/language/compile.js';
2
+ import { ConfigError } from '../domain/model/configError.js';
3
+ import { pluginRules, pluginRulesets, registry } from '../domain/rules/registry.js';
4
+ import { noOptions } from '../domain/rules/rule.js';
5
+ import { placeProblems } from './configLines.js';
6
+ export const loadConfigData = (raw, { builtins, file, plugins = {} } = {}) => {
7
+ const rules = [...registry([...(builtins?.rules ?? []), ...pluginRules(plugins)]).values()];
8
+ const config = compileConfig(raw, {
9
+ ...(file === undefined ? {} : { file }),
10
+ plugins: Object.keys(plugins),
11
+ rulesets: pluginRulesets(builtins ? { ...plugins, warp: builtins } : plugins),
12
+ ruleIds: builtins && new Set(rules.map((rule) => rule.id)),
36
13
  options: Object.fromEntries(rules.map((rule) => [rule.id, rule.parseOptions ?? noOptions])),
37
- };
38
- const data = {
39
- file,
40
- root: structure.root,
41
- archetypes: Object.fromEntries(Object.entries(structure.archetypes).map(([name, archetype]) => [name, archetypeData(archetype)])),
42
- tsconfig: tsconfigs(raw.tsconfig, fail),
43
- };
44
- const config = withRuleset(data, raw.rulesets, ruleset, (value, at) => toRules(check, value, at), fail);
45
- failed();
14
+ });
46
15
  return { config, rules };
47
16
  };
48
- const archetypeData = (archetype) => defined({ ...archetype, modules: archetype.modules.map(defined) });
49
- const checkPlugins = (declared, loaded, fail) => {
50
- if (declared === undefined)
51
- return;
52
- if (!isRecord(declared) || !Object.values(declared).every(isName)) {
53
- fail('plugins: expected plugin paths by namespace, { wt: ./rules/wt.ts }');
54
- return;
17
+ export const loadConfig = async (source, options = {}) => {
18
+ const { raw, plugins, lines, digest } = await source.read();
19
+ try {
20
+ return { ...loadConfigData(raw, { ...options, plugins, file: source.file }), lines, digest };
21
+ }
22
+ catch (error) {
23
+ if (error instanceof ConfigError)
24
+ throw new ConfigError(placeProblems(lines, source.file, error.message));
25
+ throw error;
55
26
  }
56
- for (const namespace of Object.keys(declared).filter((namespace) => !Object.hasOwn(loaded, namespace)))
57
- fail(`plugins.${namespace}: not loaded; warp loads each plugin from its path before reading the config`);
58
- };
59
- const tsconfigs = (value, fail) => {
60
- const paths = [value ?? 'tsconfig.json'].flat();
61
- if (paths.length === 0 || !paths.every(isName))
62
- fail('tsconfig: expected a path or a list of paths');
63
- return paths;
64
27
  };
@@ -1,6 +1,6 @@
1
- import type { Folders } from '../model/archetype/resolve.ts';
2
- import type { FileFacts, Project } from '../model/facts.ts';
3
- import type { Finding } from '../rules/rule.ts';
1
+ import type { Folders } from '../domain/model/resolve.ts';
2
+ import type { FileFacts, Project } from '../domain/facts/facts.ts';
3
+ import type { Finding } from '../domain/rules/rule.ts';
4
4
  export interface Analyzer {
5
5
  analyze(root: string, tsconfig: readonly string[], facts?: FactsStore): Project;
6
6
  }
@@ -39,3 +39,13 @@ export interface CachedFile {
39
39
  specifiers?: string[];
40
40
  facts?: FileFacts;
41
41
  }
42
+ export interface ConfigSource {
43
+ file: string;
44
+ read(): Promise<ConfigText>;
45
+ }
46
+ export interface ConfigText {
47
+ raw: unknown;
48
+ plugins: Record<string, unknown>;
49
+ lines: ReadonlyMap<string, number>;
50
+ digest: string;
51
+ }
@@ -1,7 +1,7 @@
1
- import type { RefData } from '../model/archetype/data.ts';
2
- import type { Fix } from '../model/archetype/fixes.ts';
3
- import type { Verdicts } from '../model/archetype/reach.ts';
4
- import type { Model } from '../model/archetype/resolve.ts';
1
+ import type { RefData } from '../domain/model/data.ts';
2
+ import type { Fix } from '../domain/fixes/fixes.ts';
3
+ import type { Verdicts } from '../domain/model/reach.ts';
4
+ import type { Model } from '../domain/model/resolve.ts';
5
5
  export declare const refText: (ref: RefData) => string;
6
6
  export declare const sentence: (parts: readonly string[]) => string;
7
7
  export declare const reachSize: (verdicts: Verdicts, file: string) => number;
@@ -1,4 +1,4 @@
1
- import { show } from '../model/archetype/references.js';
1
+ import { show } from '../domain/model/text.js';
2
2
  export const refText = (ref) => show(ref);
3
3
  export const sentence = (parts) => parts.length < 2 ? (parts[0] ?? '') : `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}`;
4
4
  export const reachSize = (verdicts, file) => new Set((verdicts.reach(file) ?? []).flatMap((grant) => (grant.ref === undefined ? [] : [grant.ref]))).size;
@@ -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
  max: number;
4
4
  };
@@ -1,4 +1,4 @@
1
- import { wholeNumberOptions } from '../../rules/rule.js';
1
+ import { wholeNumberOptions } from '../../domain/rules/rule.js';
2
2
  import { withOrdinals } from '../shared.js';
3
3
  const defaults = { max: 15 };
4
4
  export const cognitiveComplexity = {
@@ -1,2 +1,2 @@
1
- import type { Member, MemberGraph, MemberKind } from '../model/facts.ts';
1
+ import type { Member, MemberGraph, MemberKind } from '../domain/facts/facts.ts';
2
2
  export declare const components: (graph: MemberGraph, counted: readonly MemberKind[]) => Member[][];
@@ -0,0 +1,2 @@
1
+ import { type ProjectRule } from '../../domain/rules/rule.ts';
2
+ export declare const dependencyDirection: ProjectRule;
@@ -1,9 +1,9 @@
1
- import { exposesText } from '../../model/archetype/references.js';
1
+ import { exposesText } from '../../domain/model/text.js';
2
2
  import { fixSteps, reachSize, sentence } from '../advice.js';
3
3
  import { place } from '../place.js';
4
4
  import { title } from '../shared.js';
5
- import { fixesFor } from '../../model/archetype/fixes.js';
6
- import { noOptions } from '../../rules/rule.js';
5
+ import { fixesFor } from '../../domain/fixes/fixes.js';
6
+ import { noOptions } from '../../domain/rules/rule.js';
7
7
  const id = 'dependency-direction';
8
8
  export const dependencyDirection = {
9
9
  id,
@@ -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,18 @@
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 { cognitiveComplexity } from './cognitive-complexity/rule.js';
3
+ import { dependencyDirection } from './dependency-direction/rule.js';
4
+ import { fileCohesion } from './file-cohesion/rule.js';
5
+ import { functionCohesion } from './function-cohesion/rule.js';
6
+ import { moduleCycle } from './module-cycle/rule.js';
7
+ import { moduleExternals } from './module-externals/rule.js';
8
+ import { noCrossModuleReexport } from './no-cross-module-reexport/rule.js';
9
+ import { noCycle } from './no-cycle/rule.js';
10
+ import { noDoubleExport } from './no-double-export/rule.js';
11
+ import { unclassified } from './unclassified/rule.js';
12
+ import { unresolvedImport } from './unresolved-import/rule.js';
13
+ import { unusedDeclaration } from './unused-declaration/rule.js';
13
14
  export const builtinRules = [
15
+ unclassified,
14
16
  unresolvedImport,
15
17
  dependencyDirection,
16
18
  moduleExternals,
@@ -29,4 +31,7 @@ const documented = (rule) => ({
29
31
  docs: `${source}/src/builtins/${rule.id}/README.md`,
30
32
  });
31
33
  export const builtinRegistry = registry(builtinRules.map(documented));
32
- export const unclassifiedDocs = `${source}/src/builtins/unclassified/README.md`;
34
+ export const warp = {
35
+ rules: [...builtinRegistry.values()],
36
+ rulesets: { recommended: { rules: Object.fromEntries(builtinRules.map((rule) => [rule.id, 'on'])) } },
37
+ };
@@ -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/model/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,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,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 })));