@yearofthedan/warp 0.3.0 → 0.4.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 (45) hide show
  1. package/README.md +20 -22
  2. package/dist/app/check.d.ts +3 -1
  3. package/dist/app/check.js +3 -2
  4. package/dist/app/configLines.d.ts +5 -0
  5. package/dist/app/configLines.js +24 -0
  6. package/dist/app/load.d.ts +2 -2
  7. package/dist/app/load.js +32 -44
  8. package/dist/app/unclassified.js +1 -1
  9. package/dist/builtins/advice.js +9 -9
  10. package/dist/builtins/dependency-direction/dependencyDirection.js +7 -2
  11. package/dist/builtins/module-externals/moduleExternals.js +3 -2
  12. package/dist/builtins/unused-declaration/empty.js +11 -10
  13. package/dist/builtins/unused-declaration/grants.js +39 -11
  14. package/dist/builtins/unused-declaration/surfaces.js +16 -6
  15. package/dist/cli.js +37 -17
  16. package/dist/config/loadConfig.d.ts +8 -2
  17. package/dist/config/loadConfig.js +107 -14
  18. package/dist/git/cache.js +5 -1
  19. package/dist/index.d.ts +0 -1
  20. package/dist/index.js +0 -1
  21. package/dist/model/archetype/data.d.ts +14 -23
  22. package/dist/model/archetype/data.js +1 -1
  23. package/dist/model/archetype/fixes.d.ts +5 -7
  24. package/dist/model/archetype/fixes.js +132 -90
  25. package/dist/model/archetype/language.d.ts +16 -0
  26. package/dist/model/archetype/language.js +432 -0
  27. package/dist/model/archetype/reach.d.ts +8 -3
  28. package/dist/model/archetype/reach.js +122 -56
  29. package/dist/model/archetype/references.d.ts +11 -5
  30. package/dist/model/archetype/references.js +59 -118
  31. package/dist/model/archetype/requirements.d.ts +3 -3
  32. package/dist/model/archetype/requirements.js +75 -58
  33. package/dist/model/archetype/resolve.d.ts +1 -0
  34. package/dist/model/archetype/resolve.js +26 -56
  35. package/dist/model/archetype/rulesets.d.ts +2 -1
  36. package/dist/model/archetype/rulesets.js +74 -43
  37. package/dist/model/archetype/settings.d.ts +1 -0
  38. package/dist/model/archetype/settings.js +5 -0
  39. package/dist/reporters/model.js +4 -3
  40. package/dist/rules/registry.js +2 -2
  41. package/package.json +4 -2
  42. package/dist/model/archetype/builder.d.ts +0 -183
  43. package/dist/model/archetype/builder.js +0 -78
  44. package/dist/model/archetype/draft.d.ts +0 -30
  45. package/dist/model/archetype/draft.js +0 -264
@@ -18,40 +18,58 @@ export const verdicts = (config, model) => {
18
18
  return {
19
19
  reach: (file) => reach(state, file),
20
20
  exposes: (module) => exposes(state, module),
21
- surface: (module, name) => surface(state, module, name),
21
+ surface: (module, name, view = 'production') => surface(state, module, name, view),
22
22
  verdict: (from, to) => verdict(state, from, to),
23
- files: (module, ref) => resolve(state, module, ref),
23
+ files: (module, ref, view = 'production') => resolve(state, module, ref, view),
24
24
  describe: (module, ref) => describe(state, module, ref),
25
25
  };
26
26
  };
27
27
  const exposes = ({ config }, module) => {
28
- if (module.kind === 'dir')
29
- return config.archetypes[module.archetype].exposes;
28
+ if (module.kind === 'dir') {
29
+ const { exposes, testExposes } = config.archetypes[module.archetype];
30
+ return exposes ?? (module.test && !testExposes ? { kind: 'all' } : undefined);
31
+ }
30
32
  const declared = declarationOf(config, module);
31
33
  if (declared?.kind === 'test')
32
34
  return declared.exposes ?? { kind: 'all' };
33
35
  return declared?.kind === 'files' ? declared.exposes : undefined;
34
36
  };
35
- const surface = (state, module, name) => {
36
- const key = `${module.id}\0${name ?? ''}`;
37
+ const testExposes = ({ config }, module) => (module.kind === 'dir' && config.archetypes[module.archetype].testExposes) || {};
38
+ const surface = (state, module, name, view) => {
39
+ const key = `${module.id}\0${name ?? ''}\0${view}`;
37
40
  let files = state.surfaces.get(key);
38
41
  if (!files) {
39
- files = exposed(state, module, name);
42
+ files = view === 'test' ? testSurface(state, module, name) : exposed(state, module, name);
40
43
  state.surfaces.set(key, files);
41
44
  }
42
45
  return files;
43
46
  };
47
+ const testSurface = (state, module, name) => {
48
+ const declared = testExposes(state, module);
49
+ const refs = name === undefined ? Object.values(declared).flat() : (declared[name] ?? []);
50
+ const production = name === undefined || !(name in declared) || isSurface(state, module, name);
51
+ return union([
52
+ production ? surface(state, module, name, 'production') : none,
53
+ ...refs.map((ref) => resolve(state, module, ref, 'test')),
54
+ ]);
55
+ };
56
+ const isSurface = (state, module, name) => {
57
+ const declared = exposes(state, module);
58
+ return declared?.kind === 'surfaces' && name in declared.surfaces;
59
+ };
44
60
  const exposed = (state, module, name) => {
45
61
  const declared = exposes(state, module);
46
62
  if (declared === undefined)
47
63
  return none;
48
64
  if (declared.kind === 'surfaces') {
49
65
  const refs = name === undefined ? Object.values(declared.surfaces).flat() : (declared.surfaces[name] ?? []);
50
- return union(refs.map((ref) => resolve(state, module, ref)));
66
+ return union(refs.map((ref) => resolve(state, module, ref, 'production')));
51
67
  }
52
68
  const all = union([
53
69
  new Set(module.files),
54
- ...module.children.filter((child) => child.kind !== 'test').map((child) => surface(state, child)),
70
+ ...module.children
71
+ .filter((child) => module.test || !child.test)
72
+ .map((child) => surface(state, child, undefined, 'production')),
55
73
  ]);
56
74
  if (declared.kind === 'all')
57
75
  return all;
@@ -59,46 +77,69 @@ const exposed = (state, module, name) => {
59
77
  const inside = (file) => (module.dir === '' ? file : file.slice(module.dir.length + 1));
60
78
  return new Set([...all].filter((file) => patterns.some((pattern) => globRegex(pattern).test(inside(file)))));
61
79
  };
62
- const provider = (state, module, name) => {
63
- for (const at of ancestors(module)) {
64
- const ref = state.config.archetypes[at.archetype].provides[name];
65
- if (ref)
66
- return { at, ref };
67
- }
68
- return undefined;
80
+ export const instanceOf = (state, holder) => {
81
+ let at = holder;
82
+ while (state.config.archetypes[at.archetype].inline && at.parent)
83
+ at = at.parent;
84
+ return at;
69
85
  };
70
- const resolve = (state, module, ref) => {
86
+ const bindingOf = (state, holder, name, view) => {
87
+ const instance = instanceOf(state, holder);
88
+ const declared = declarationOf(state.config, instance);
89
+ return (view === 'test' ? declared?.testInputs?.[name] : undefined) ?? declared?.inputs?.[name];
90
+ };
91
+ const concrete = (state, holder, ref, view) => {
92
+ if (ref.kind === 'module') {
93
+ let at = holder;
94
+ for (let up = ref.up ?? 0; up > 0 && at; up -= 1)
95
+ at = at.parent;
96
+ return at && { holder: at, ref: { ...ref, up: 0 }, via: [] };
97
+ }
71
98
  if (ref.kind === 'package')
72
- return none;
73
- if (ref.kind === 'required')
74
- return resolveRequired(state, module, ref.name, ref.surface);
75
- return union(module.children.filter((child) => child.name === ref.module).map((child) => surface(state, child, ref.surface)));
99
+ return { holder, ref, via: [] };
100
+ const bound = bindingOf(state, holder, ref.name, view);
101
+ const instance = instanceOf(state, holder);
102
+ if (!bound || !instance.parent)
103
+ return undefined;
104
+ const surface = ref.surface ?? (bound.kind === 'package' ? undefined : bound.surface);
105
+ const found = concrete(state, instance.parent, bound.kind === 'package' ? bound : { ...bound, surface }, view);
106
+ return found && { ...found, via: [bound, ...found.via] };
76
107
  };
77
- const resolveRequired = (state, module, name, surface) => {
78
- const found = provider(state, module, name);
79
- return resolve(state, found.at, { ...found.ref, surface });
108
+ const resolve = (state, module, ref, view) => {
109
+ const found = concrete(state, module, ref, view);
110
+ if (!found || found.ref.kind !== 'module')
111
+ return none;
112
+ const { holder, ref: target } = found;
113
+ return union(holder.children
114
+ .filter((child) => child.name === target.module)
115
+ .map((child) => surface(state, child, target.surface, view)));
80
116
  };
81
- const describe = (state, module, ref) => {
82
- if (ref.kind === 'module')
83
- return `m.${show(ref)}`;
84
- if (ref.kind === 'package')
117
+ const describe = (state, module, ref, view = 'production') => {
118
+ if (ref.kind !== 'required')
85
119
  return show(ref);
86
- return `${show(ref)} (from ${provider(state, module, ref.name).at.id})`;
87
- };
88
- const grants = (state, holder, owner, refs) => refs.map((ref) => ({
89
- owner,
90
- ref: describe(state, holder, ref),
91
- files: resolve(state, holder, ref),
92
- ...(ref.kind === 'package' ? { package: ref.pattern } : {}),
93
- declared: ref,
94
- }));
120
+ const instance = instanceOf(state, module);
121
+ const found = concrete(state, module, ref, view);
122
+ const bound = found ? ` = ${show(found.ref)} in ${found.holder.id}` : '';
123
+ return `${show(ref)} (input of ${instance.id}${bound})`;
124
+ };
125
+ const grants = (state, holder, owner, refs, view) => refs.map((ref) => {
126
+ const found = concrete(state, holder, ref, view);
127
+ return {
128
+ owner,
129
+ ref: describe(state, holder, ref, view),
130
+ files: resolve(state, holder, ref, view),
131
+ ...(found?.ref.kind === 'package' ? { package: found.ref.pattern } : {}),
132
+ declared: ref,
133
+ ...(found && found.via.length > 0 ? { via: found.via } : {}),
134
+ };
135
+ });
95
136
  const reach = (state, file) => {
96
137
  const module = state.model.moduleOf(file);
97
138
  if (!module || module.looseFiles.includes(file))
98
139
  return undefined;
99
140
  let found = state.reaches.get(module.id);
100
141
  if (!found) {
101
- found = module.kind === 'test' ? testReach(state, module) : productionReach(state, module);
142
+ found = module.test ? testReach(state, module) : productionReach(state, module);
102
143
  state.reaches.set(module.id, found);
103
144
  }
104
145
  return found;
@@ -106,37 +147,61 @@ const reach = (state, file) => {
106
147
  const productionReach = (state, module) => [
107
148
  { owner: `own module ${module.id}`, files: new Set(module.files) },
108
149
  ...module.children
109
- .filter((child) => child.kind !== 'test')
110
- .map((child) => ({ owner: module.id, ref: child.id, files: surface(state, child) })),
111
- ...using(state, module),
112
- ...(module.kind === 'files' ? using(state, module.parent) : []),
150
+ .filter((child) => !child.test)
151
+ .map((child) => ({ owner: module.id, ref: child.id, files: surface(state, child, undefined, 'production') })),
152
+ ...using(state, module, 'production'),
153
+ ];
154
+ const testReach = (state, module) => [
155
+ { owner: `own module ${module.id}`, files: new Set(module.files) },
156
+ ...module.children.map((child) => ({
157
+ owner: module.id,
158
+ ref: child.id,
159
+ files: surface(state, child, undefined, 'test'),
160
+ })),
161
+ ...inherited(state, module),
113
162
  ];
114
- const testReach = (state, module) => {
163
+ const inherited = (state, module) => {
115
164
  const holder = module.parent;
165
+ if (holder.test)
166
+ return [...using(state, module, 'test'), ...inherited(state, holder)];
167
+ const declared = declarationOf(state.config, module);
168
+ if (declared?.kind === 'test' && declared.of !== undefined)
169
+ return filesTests(state, module, declared.of);
116
170
  const own = holder.children.filter((child) => child.kind === 'files');
171
+ const inside = new Set(subtree(module).flatMap((at) => at.files));
117
172
  return [
118
- { owner: `own module ${module.id}`, files: new Set(module.files) },
119
173
  {
120
174
  owner: module.id,
121
175
  ref: holder.id,
122
176
  files: union([new Set(holder.files), ...own.map((child) => new Set(child.files))]),
123
177
  },
124
178
  ...holder.children
125
- .filter((child) => child.kind === 'dir')
126
- .map((child) => ({ owner: holder.id, ref: child.id, files: surface(state, child) })),
127
- ...using(state, holder),
128
- ...own.flatMap((child) => using(state, child)),
129
- ...using(state, module),
179
+ .filter((child) => child.kind === 'dir' && !child.test)
180
+ .map((child) => ({ owner: holder.id, ref: child.id, files: surface(state, child, undefined, 'test') })),
181
+ ...using(state, holder, 'test'),
182
+ ...own.flatMap((child) => using(state, child, 'test')),
183
+ ...using(state, module, 'test'),
184
+ ...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
185
+ ].map((grant) => ({ ...grant, files: new Set([...grant.files].filter((file) => !inside.has(file))) }));
186
+ };
187
+ const filesTests = (state, module, of) => {
188
+ const holder = module.parent;
189
+ const tested = holder.children.filter((child) => child.kind === 'files' && child.name === of);
190
+ return [
191
+ { owner: module.id, ref: `${holder.id}:${of}`, files: union(tested.map((child) => new Set(child.files))) },
192
+ ...tested.flatMap((child) => using(state, child, 'test')),
193
+ ...using(state, module, 'test'),
130
194
  ...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
131
195
  ];
132
196
  };
133
- const testKit = (state, at) => grants(state, at, `${at.archetype}.testUsing`, state.config.archetypes[at.archetype].testUsing ?? []);
134
- const using = (state, module) => {
197
+ const subtree = (module) => [module, ...module.children.flatMap(subtree)];
198
+ const testKit = (state, at) => grants(state, at, `${at.archetype}.test.provides`, state.config.archetypes[at.archetype].testUsing ?? [], 'test');
199
+ const using = (state, module, view) => {
135
200
  const declared = declarationOf(state.config, module);
136
201
  if (!declared)
137
202
  return [];
138
203
  const owner = module.kind === 'dir' ? `${module.parent.archetype}.${declared.name}` : declared.name;
139
- return grants(state, module.parent, owner, declared.using);
204
+ return grants(state, module.parent, owner, declared.using, view);
140
205
  };
141
206
  const verdict = (state, from, to) => {
142
207
  const granted = reach(state, from);
@@ -148,16 +213,17 @@ const verdict = (state, from, to) => {
148
213
  const grant = granted.find((candidate) => candidate.files.has(to));
149
214
  if (grant)
150
215
  return { allowed: true, grant };
151
- return { allowed: false, ...refusal(state, state.model.moduleOf(from), target, from, to) };
216
+ const view = state.model.isTest(from) ? 'test' : 'production';
217
+ return { allowed: false, ...refusal(state, state.model.moduleOf(from), target, to, view) };
152
218
  };
153
- const refusal = (state, source, target, from, to) => {
219
+ const refusal = (state, source, target, to, view) => {
154
220
  const above = new Set(ancestors(source));
155
221
  if (above.has(target))
156
222
  return { reason: 'above' };
157
223
  if (target.kind !== 'dir' && target.parent !== source.parent && above.has(target.parent))
158
224
  return { reason: 'above' };
159
225
  for (let at = target; !above.has(at) && at !== source; at = at.parent)
160
- if (!surface(state, at).has(to))
226
+ if (!surface(state, at, undefined, view).has(to))
161
227
  return { reason: 'private', hiddenBy: at };
162
- return { reason: 'not-in-using' };
228
+ return { reason: 'not-in-dependencies' };
163
229
  };
@@ -1,13 +1,19 @@
1
- import type { ExposesData, RefData, RuleSettingsData } from './data.ts';
2
- import type { Draft, DraftExposes } from './draft.ts';
1
+ import { type ArchetypeData, type ExposesData, type RefData, type RuleSettingsData } from './data.ts';
2
+ import type { PendingRef } from './language.ts';
3
3
  import { type Fail } from './shared.ts';
4
4
  export interface Check {
5
5
  fail: Fail;
6
6
  ruleIds?: ReadonlySet<string> | undefined;
7
7
  options: Readonly<Record<string, (raw: Record<string, unknown>, at: string) => unknown>>;
8
- exposesOf: (archetype: string) => DraftExposes | undefined;
9
8
  }
9
+ export declare const packageText: (pattern: string) => string;
10
10
  export declare const show: (ref: RefData) => string;
11
- export declare const resolveDraft: (check: Check, { data: archetype, modules, exposes, provides, testUsing }: Draft) => void;
11
+ export declare const checkReferences: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;
12
+ interface Surfaces {
13
+ exposes: ExposesData | undefined;
14
+ testExposes: readonly string[];
15
+ }
16
+ export declare const exposedProblem: (subject: string, { exposes, testExposes }: Surfaces, surface: string | undefined, tests: boolean) => string | undefined;
17
+ export declare const exposesText: (exposes: ExposesData | undefined) => string;
12
18
  export declare const toRules: (check: Check, value: unknown, where: string) => RuleSettingsData | undefined;
13
- export declare const exposesText: (exposes: DraftExposes | ExposesData | undefined) => string;
19
+ export {};
@@ -1,65 +1,67 @@
1
1
  import { ConfigError } from '../configError.js';
2
- import { recordedAs } from './builder.js';
3
- import { isName, isRecord, list } from './shared.js';
2
+ import { isTestData } from './data.js';
3
+ import { isRecord, list } from './shared.js';
4
+ export const packageText = (pattern) => pattern.startsWith('node:') || pattern.startsWith('virtual:') ? pattern : `npm:${pattern}`;
4
5
  export const show = (ref) => ref.kind === 'package'
5
- ? `pkg('${ref.pattern}')`
6
- : `${ref.kind === 'required' ? `required.${ref.name}` : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
7
- export const resolveDraft = (check, { data: archetype, modules, exposes, provides, testUsing }) => {
8
- const every = ['module', 'required', 'package'];
9
- for (const [index, module] of modules.entries()) {
10
- const scope = {
11
- archetype,
12
- visible: index,
13
- kinds: every,
14
- refused: '',
15
- tests: module.data.kind === 'test',
16
- module: module.data.name,
17
- };
18
- const where = `${archetype.name}.${module.data.name}`;
19
- module.data.using.push(...module.using.map((value) => toRef(check, value, `${where} uses`, scope)));
20
- }
21
- const own = {
22
- archetype,
23
- visible: archetype.modules.length,
24
- kinds: ['module'],
25
- refused: 'exposes and provides name the archetype’s own modules',
26
- tests: true,
27
- };
28
- if (exposes)
29
- archetype.exposes = exposesData(check, archetype.name, exposes, own);
30
- for (const [name, value] of Object.entries(provides)) {
31
- const scope = { ...own, whole: true, tests: false };
32
- archetype.provides[name] = toRef(check, value, `${archetype.name} provides ${name} as`, scope);
33
- }
34
- const kit = { ...own, kinds: every, refused: '' };
35
- if (testUsing.length > 0)
36
- archetype.testUsing = testUsing.map((value) => toRef(check, value, `${archetype.name} testUsing`, kit));
37
- };
38
- const exposesData = (check, name, exposes, scope) => exposes.kind !== 'surfaces'
39
- ? exposes
40
- : {
41
- kind: 'surfaces',
42
- surfaces: Object.fromEntries(Object.entries(exposes.surfaces).map(([surface, refs]) => [
43
- surface,
44
- refs.map((value) => toRef(check, value, `${name} exposes ${surface} as`, scope)),
45
- ])),
46
- };
47
- const toRef = (check, value, where, scope) => {
48
- const ref = recordedAs(value, 'ref');
49
- if (!ref)
50
- check.fail(`${where} something other than a reference: use s.module, required.name or pkg('name')`);
51
- else {
52
- const problem = refProblem(check, ref, scope);
6
+ ? packageText(ref.pattern)
7
+ : `${ref.kind === 'module' && ref.top ? 'top.' : ''}${ref.kind === 'required' ? ref.name : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
8
+ export const checkReferences = (archetypes, pending, fail) => {
9
+ for (const entry of pending) {
10
+ const problem = refProblem(archetypes, entry);
53
11
  if (problem)
54
- check.fail(`${where} ${show(ref)}; ${problem}`);
12
+ fail(`${entry.where}: '${show(entry.ref)}': ${problem}`);
55
13
  }
56
- return { ...ref };
14
+ };
15
+ const refProblem = (archetypes, { ref, archetype, tests, surface }) => {
16
+ if (ref.kind !== 'module')
17
+ return undefined;
18
+ const module = archetypes[archetype]?.modules.find((candidate) => candidate.name === ref.module);
19
+ if (!module)
20
+ return undefined;
21
+ if (isTestData(module) && !tests)
22
+ return surface
23
+ ? `${ref.module} is a test module, and exposes is production code: name it in test.exposes`
24
+ : `${ref.module} is a test module, which only test code may name`;
25
+ if (module.kind === 'test')
26
+ return exposedProblem(ref.module, { exposes: module.exposes ?? { kind: 'all' }, testExposes: [] }, ref.surface, true);
27
+ if (module.kind === 'files')
28
+ return exposedProblem(ref.module, { exposes: module.exposes, testExposes: [] }, ref.surface, tests);
29
+ const inside = archetypes[module.archetype];
30
+ if (!inside)
31
+ return undefined;
32
+ const exposes = module.test && !inside.testExposes ? (inside.exposes ?? { kind: 'all' }) : inside.exposes;
33
+ const subject = inside.inline ? ref.module : `${ref.module} (${module.archetype})`;
34
+ return exposedProblem(subject, { exposes, testExposes: Object.keys(inside.testExposes ?? {}) }, ref.surface, tests);
35
+ };
36
+ export const exposedProblem = (subject, { exposes, testExposes }, surface, tests) => {
37
+ if (surface !== undefined && testExposes.includes(surface))
38
+ return tests ? undefined : `${surface} is a test surface of ${subject}, which only test code may name`;
39
+ if (exposes === undefined && (!tests || testExposes.length === 0))
40
+ return `${subject} exposes nothing: give it exposes, or drop the reference`;
41
+ if (surface === undefined)
42
+ return undefined;
43
+ const surfaces = exposes?.kind === 'surfaces' ? Object.keys(exposes.surfaces) : [];
44
+ if (surfaces.includes(surface))
45
+ return undefined;
46
+ const named = [...surfaces, ...(tests ? testExposes : [])];
47
+ if (exposes?.kind === 'surfaces' || named.length > 0)
48
+ return `${subject} exposes ${list(named, 'nothing')}`;
49
+ return `${subject} exposes ${exposesText(exposes)}, not named surfaces`;
50
+ };
51
+ export const exposesText = (exposes) => {
52
+ if (exposes === undefined)
53
+ return 'nothing';
54
+ if (exposes.kind === 'all')
55
+ return 'all its files';
56
+ if (exposes.kind === 'files')
57
+ return `{ files: [${exposes.patterns.join(', ')}] }`;
58
+ return Object.keys(exposes.surfaces).join(', ');
57
59
  };
58
60
  export const toRules = (check, value, where) => {
59
61
  if (value === undefined || value === 'off')
60
62
  return value;
61
63
  if (!isRecord(value)) {
62
- check.fail(`${where}: expected 'off' or rule settings by id`);
64
+ check.fail(`${where}: expected off or rule settings by id`);
63
65
  return undefined;
64
66
  }
65
67
  return Object.fromEntries(Object.entries(value).map(([id, setting]) => [id, toSetting(check, id, setting, where)]));
@@ -67,12 +69,14 @@ export const toRules = (check, value, where) => {
67
69
  const toSetting = (check, id, setting, where) => {
68
70
  if (id !== '*' && check.ruleIds && !check.ruleIds.has(id))
69
71
  check.fail(`${where}: no rule called ${id}`);
72
+ else if (setting === 'on' || setting === 'off')
73
+ return setting === 'on';
70
74
  else if (typeof setting === 'boolean')
71
75
  return setting;
72
- else if (id !== '*' && isRecord(setting) && !recordedAs(setting, 'ref'))
76
+ else if (id !== '*' && isRecord(setting))
73
77
  return checkOptions(check, id, setting, where);
74
78
  else
75
- check.fail(`${where}.${id}: expected true, false${id === '*' ? '' : ' or options'}`);
79
+ check.fail(`${where}.${id}: expected on, off${id === '*' ? '' : ' or options'}`);
76
80
  return undefined;
77
81
  };
78
82
  const checkOptions = (check, id, options, where) => {
@@ -86,66 +90,3 @@ const checkOptions = (check, id, options, where) => {
86
90
  }
87
91
  return { ...options };
88
92
  };
89
- const refProblem = (check, ref, scope) => {
90
- if (!scope.kinds.includes(ref.kind))
91
- return scope.refused;
92
- if (ref.kind === 'package')
93
- return isName(ref.pattern) ? undefined : 'a package pattern is a non-empty string';
94
- if (ref.kind === 'required')
95
- return requiredProblem(check, ref.name, ref.surface, scope.archetype);
96
- return moduleProblem(check, ref.module, ref.surface, scope);
97
- };
98
- const requiredProblem = (check, name, surface, archetype) => {
99
- const requirement = archetype.requires[name];
100
- if (!requirement)
101
- return `${archetype.name} requires ${list(Object.keys(archetype.requires), 'nothing')}`;
102
- if (requirement.kind !== 'archetype')
103
- return surface === undefined ? undefined : `required.${name} is ${requirement.kind}(), which has no surfaces`;
104
- return exposedProblem(`required.${name}`, requirement.archetype, check.exposesOf(requirement.archetype), surface);
105
- };
106
- const moduleProblem = (check, name, surface, scope) => {
107
- const index = scope.archetype.modules.findIndex((module) => module.name === name);
108
- if (index < 0 || index >= scope.visible)
109
- return visibilityProblem(name, index, scope);
110
- if (surface !== undefined && scope.whole)
111
- return 'name the whole module, without a surface';
112
- const module = scope.archetype.modules[index];
113
- if (module.kind === 'test')
114
- return scope.tests
115
- ? exposedProblem(name, undefined, module.exposes ?? { kind: 'all' }, surface)
116
- : `${name} is a test module, which only test modules and testUsing may name`;
117
- if (module.kind === 'files')
118
- return exposedProblem(name, undefined, module.exposes, surface);
119
- return exposedProblem(name, archetypeText(scope.archetype, module), check.exposesOf(module.archetype), surface);
120
- };
121
- const archetypeText = (holder, module) => module.archetype === holder.name || module.archetype.startsWith(`${holder.name}.`) ? undefined : module.archetype;
122
- const exposedProblem = (name, archetype, exposes, surface) => {
123
- const subject = archetype === undefined ? name : `${name} (${archetype})`;
124
- if (exposes === undefined)
125
- return `${subject} exposes nothing: give ${archetype ?? name} exposes, or drop the reference`;
126
- if (surface === undefined)
127
- return undefined;
128
- if (exposes.kind !== 'surfaces')
129
- return `${subject} exposes ${exposesText(exposes)}, not named surfaces`;
130
- const surfaces = Object.keys(exposes.surfaces);
131
- return surfaces.includes(surface) ? undefined : `${subject} exposes ${list(surfaces, 'nothing')}`;
132
- };
133
- export const exposesText = (exposes) => {
134
- if (exposes === undefined)
135
- return 'nothing';
136
- if (exposes.kind === 'all')
137
- return 'all its files';
138
- if (exposes.kind === 'files')
139
- return `files(${exposes.patterns.map((pattern) => `'${pattern}'`).join(', ')})`;
140
- return list(Object.keys(exposes.surfaces), 'nothing');
141
- };
142
- const visibilityProblem = (name, index, { archetype, visible, module }) => {
143
- const above = list(archetype.modules.slice(0, visible).map((candidate) => candidate.name), 'no modules');
144
- if (module === undefined)
145
- return `${archetype.name} has modules ${above}`;
146
- if (index < 0)
147
- return `${module} sees ${above}`;
148
- if (index === visible)
149
- return `a module reaches its own files already; ${module} sees ${above}`;
150
- return `${name} is declared below ${module}, which sees ${above}`;
151
- };
@@ -1,5 +1,5 @@
1
1
  import type { ArchetypeData } from './data.ts';
2
- import type { Draft } from './draft.ts';
2
+ import type { PendingRef } from './language.ts';
3
3
  import type { Fail } from './shared.ts';
4
- export declare const checkUnused: (drafts: readonly Draft[], fail: Fail) => void;
5
- export declare const checkRequirements: (archetypes: Record<string, ArchetypeData>, root: string, fail: Fail) => string[];
4
+ export declare const markTests: (archetypes: Record<string, ArchetypeData>, fail: Fail) => void;
5
+ export declare const checkInputs: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;