@yearofthedan/warp 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -25
- package/dist/analysis/imports.d.ts +3 -1
- package/dist/analysis/imports.js +5 -1
- package/dist/analysis/typescript.js +2 -1
- package/dist/app/check.d.ts +3 -1
- package/dist/app/check.js +5 -3
- package/dist/app/checkModel.js +1 -1
- package/dist/app/configLines.d.ts +5 -0
- package/dist/app/configLines.js +24 -0
- package/dist/app/load.d.ts +2 -2
- package/dist/app/load.js +31 -43
- package/dist/builtins/advice.d.ts +8 -0
- package/dist/builtins/advice.js +42 -0
- package/dist/builtins/dependency-direction/dependencyDirection.js +33 -16
- package/dist/builtins/index.js +2 -0
- package/dist/builtins/module-externals/moduleExternals.js +11 -9
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.js +16 -5
- package/dist/builtins/place.js +5 -3
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +2 -0
- package/dist/builtins/unresolved-import/unresolvedImport.js +15 -0
- package/dist/builtins/unused-declaration/declarations.js +1 -1
- package/dist/builtins/unused-declaration/empty.js +19 -11
- package/dist/builtins/unused-declaration/grants.js +22 -15
- package/dist/builtins/unused-declaration/surfaces.js +24 -22
- package/dist/cli.js +14 -11
- package/dist/config/loadConfig.d.ts +7 -1
- package/dist/config/loadConfig.js +83 -12
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/model/archetype/data.d.ts +25 -29
- package/dist/model/archetype/data.js +1 -1
- package/dist/model/archetype/fixes.d.ts +35 -0
- package/dist/model/archetype/fixes.js +265 -0
- package/dist/model/archetype/language.d.ts +16 -0
- package/dist/model/archetype/language.js +419 -0
- package/dist/model/archetype/reach.d.ts +8 -3
- package/dist/model/archetype/reach.js +142 -122
- package/dist/model/archetype/references.d.ts +11 -5
- package/dist/model/archetype/references.js +58 -132
- package/dist/model/archetype/requirements.d.ts +3 -3
- package/dist/model/archetype/requirements.js +65 -61
- package/dist/model/archetype/resolve.d.ts +3 -3
- package/dist/model/archetype/resolve.js +64 -77
- package/dist/model/archetype/rulesets.d.ts +2 -1
- package/dist/model/archetype/rulesets.js +72 -49
- package/dist/model/archetype/settings.js +4 -19
- package/dist/model/facts.d.ts +6 -0
- package/dist/reporters/model.js +9 -9
- package/dist/rules/registry.js +1 -1
- package/package.json +3 -2
- package/dist/model/archetype/builder.d.ts +0 -183
- package/dist/model/archetype/builder.js +0 -85
- package/dist/model/archetype/draft.d.ts +0 -37
- package/dist/model/archetype/draft.js +0 -275
|
@@ -18,192 +18,212 @@ 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
|
-
|
|
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);
|
|
33
|
+
if (declared?.kind === 'test')
|
|
34
|
+
return declared.exposes ?? { kind: 'all' };
|
|
31
35
|
return declared?.kind === 'files' ? declared.exposes : undefined;
|
|
32
36
|
};
|
|
33
|
-
const
|
|
34
|
-
|
|
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}`;
|
|
35
40
|
let files = state.surfaces.get(key);
|
|
36
41
|
if (!files) {
|
|
37
|
-
files = exposed(state, module, name);
|
|
42
|
+
files = view === 'test' ? testSurface(state, module, name) : exposed(state, module, name);
|
|
38
43
|
state.surfaces.set(key, files);
|
|
39
44
|
}
|
|
40
45
|
return files;
|
|
41
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
|
+
};
|
|
42
60
|
const exposed = (state, module, name) => {
|
|
43
61
|
const declared = exposes(state, module);
|
|
44
62
|
if (declared === undefined)
|
|
45
63
|
return none;
|
|
46
64
|
if (declared.kind === 'surfaces') {
|
|
47
65
|
const refs = name === undefined ? Object.values(declared.surfaces).flat() : (declared.surfaces[name] ?? []);
|
|
48
|
-
return union(refs.map((ref) => resolve(state, module, ref)));
|
|
66
|
+
return union(refs.map((ref) => resolve(state, module, ref, 'production')));
|
|
49
67
|
}
|
|
50
|
-
const all = union([
|
|
68
|
+
const all = union([
|
|
69
|
+
new Set(module.files),
|
|
70
|
+
...module.children
|
|
71
|
+
.filter((child) => module.test || !child.test)
|
|
72
|
+
.map((child) => surface(state, child, undefined, 'production')),
|
|
73
|
+
]);
|
|
51
74
|
if (declared.kind === 'all')
|
|
52
75
|
return all;
|
|
53
76
|
const patterns = declared.patterns.flatMap((pattern) => fillPattern(pattern, module.captures) ?? []);
|
|
54
77
|
const inside = (file) => (module.dir === '' ? file : file.slice(module.dir.length + 1));
|
|
55
78
|
return new Set([...all].filter((file) => patterns.some((pattern) => globRegex(pattern).test(inside(file)))));
|
|
56
79
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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;
|
|
85
|
+
};
|
|
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: [] };
|
|
62
97
|
}
|
|
63
|
-
return undefined;
|
|
64
|
-
};
|
|
65
|
-
const resolve = (state, module, ref) => {
|
|
66
98
|
if (ref.kind === 'package')
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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] };
|
|
71
107
|
};
|
|
72
|
-
const
|
|
73
|
-
const found =
|
|
74
|
-
|
|
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)));
|
|
75
116
|
};
|
|
76
|
-
const describe = (state, module, ref) => {
|
|
77
|
-
if (ref.kind
|
|
78
|
-
return `m.${show(ref)}`;
|
|
79
|
-
if (ref.kind === 'package')
|
|
117
|
+
const describe = (state, module, ref, view = 'production') => {
|
|
118
|
+
if (ref.kind !== 'required')
|
|
80
119
|
return show(ref);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
});
|
|
90
136
|
const reach = (state, file) => {
|
|
91
137
|
const module = state.model.moduleOf(file);
|
|
92
138
|
if (!module || module.looseFiles.includes(file))
|
|
93
139
|
return undefined;
|
|
94
|
-
if (state.model.isTest(file))
|
|
95
|
-
return testReach(state, module);
|
|
96
140
|
let found = state.reaches.get(module.id);
|
|
97
141
|
if (!found) {
|
|
98
|
-
|
|
99
|
-
{ owner: `own module ${module.id}`, files: new Set(module.files) },
|
|
100
|
-
...module.children
|
|
101
|
-
.filter((child) => !child.test)
|
|
102
|
-
.map((child) => ({ owner: module.id, ref: child.id, files: surface(state, child) })),
|
|
103
|
-
...using(state, module),
|
|
104
|
-
];
|
|
105
|
-
if (module.kind === 'files')
|
|
106
|
-
granted.push(...using(state, module.parent));
|
|
107
|
-
found = granted;
|
|
142
|
+
found = module.test ? testReach(state, module) : productionReach(state, module);
|
|
108
143
|
state.reaches.set(module.id, found);
|
|
109
144
|
}
|
|
110
145
|
return found;
|
|
111
146
|
};
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
147
|
+
const productionReach = (state, module) => [
|
|
148
|
+
{ owner: `own module ${module.id}`, files: new Set(module.files) },
|
|
149
|
+
...module.children
|
|
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),
|
|
162
|
+
];
|
|
163
|
+
const inherited = (state, module) => {
|
|
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);
|
|
170
|
+
const own = holder.children.filter((child) => child.kind === 'files');
|
|
171
|
+
const inside = new Set(subtree(module).flatMap((at) => at.files));
|
|
125
172
|
return [
|
|
126
173
|
{
|
|
127
|
-
owner:
|
|
128
|
-
|
|
174
|
+
owner: module.id,
|
|
175
|
+
ref: holder.id,
|
|
176
|
+
files: union([new Set(holder.files), ...own.map((child) => new Set(child.files))]),
|
|
129
177
|
},
|
|
130
|
-
...
|
|
131
|
-
.filter((child) => child.kind === 'dir')
|
|
132
|
-
.map((child) => ({ owner:
|
|
133
|
-
...
|
|
134
|
-
...own.
|
|
135
|
-
...
|
|
136
|
-
...[...ancestors(
|
|
137
|
-
];
|
|
138
|
-
};
|
|
139
|
-
const filesTests = (state,
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const declared = declarationOf(state.config, owner);
|
|
143
|
-
const tests = declared?.kind === 'files' ? declared.tests : undefined;
|
|
144
|
-
return [
|
|
145
|
-
{ owner: by, files: new Set([...owner.files, ...owner.tests]) },
|
|
146
|
-
...using(state, owner),
|
|
147
|
-
...using(state, folder),
|
|
148
|
-
...(tests ? grants(state, folder, by, tests.using) : []),
|
|
149
|
-
...[folder, ...ancestors(folder)].flatMap((above) => layer(state, above, by)),
|
|
150
|
-
];
|
|
151
|
-
};
|
|
152
|
-
const layerOf = ({ config }, module) => module.archetype === undefined ? undefined : config.archetypes[module.archetype].tests;
|
|
153
|
-
const layerUsing = (state, holder, at, by) => grants(state, holder, by, layerOf(state, at)?.using ?? []);
|
|
154
|
-
const layer = (state, above, by) => {
|
|
155
|
-
const tests = above.children.filter((child) => child.test).map((child) => new Set(child.files));
|
|
178
|
+
...holder.children
|
|
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);
|
|
156
190
|
return [
|
|
157
|
-
|
|
158
|
-
...
|
|
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'),
|
|
194
|
+
...[holder, ...ancestors(holder)].flatMap((at) => testKit(state, at)),
|
|
159
195
|
];
|
|
160
196
|
};
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return none;
|
|
165
|
-
const testModules = module.children.filter((child) => child.test);
|
|
166
|
-
if (exposes.kind !== 'surfaces')
|
|
167
|
-
return union([
|
|
168
|
-
...testModules.map((child) => new Set(child.files)),
|
|
169
|
-
...module.children.filter((child) => child.kind === 'dir').map((child) => testSurface(state, child)),
|
|
170
|
-
]);
|
|
171
|
-
const named = new Set(Object.values(exposes.surfaces)
|
|
172
|
-
.flat()
|
|
173
|
-
.flatMap((ref) => (ref.kind === 'module' ? [`tests.${ref.module}`] : [])));
|
|
174
|
-
return union(testModules.filter((child) => named.has(child.name)).map((child) => new Set(child.files)));
|
|
175
|
-
};
|
|
176
|
-
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) => {
|
|
177
200
|
const declared = declarationOf(state.config, module);
|
|
178
201
|
if (!declared)
|
|
179
202
|
return [];
|
|
180
|
-
const owner = module.kind === '
|
|
181
|
-
return grants(state, module.parent, owner, declared.using);
|
|
203
|
+
const owner = module.kind === 'dir' ? `${module.parent.archetype}.${declared.name}` : declared.name;
|
|
204
|
+
return grants(state, module.parent, owner, declared.using, view);
|
|
182
205
|
};
|
|
183
206
|
const verdict = (state, from, to) => {
|
|
184
207
|
const granted = reach(state, from);
|
|
185
208
|
const target = state.model.moduleOf(to);
|
|
186
209
|
if (!granted || !target)
|
|
187
210
|
return undefined;
|
|
211
|
+
if (state.model.isTest(to) && !state.model.isTest(from))
|
|
212
|
+
return { allowed: false, reason: 'test' };
|
|
188
213
|
const grant = granted.find((candidate) => candidate.files.has(to));
|
|
189
214
|
if (grant)
|
|
190
215
|
return { allowed: true, grant };
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
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) };
|
|
194
218
|
};
|
|
195
|
-
const refusal = (state, source, target,
|
|
219
|
+
const refusal = (state, source, target, to, view) => {
|
|
196
220
|
const above = new Set(ancestors(source));
|
|
197
221
|
if (above.has(target))
|
|
198
222
|
return { reason: 'above' };
|
|
199
|
-
if (target.kind
|
|
223
|
+
if (target.kind !== 'dir' && target.parent !== source.parent && above.has(target.parent))
|
|
200
224
|
return { reason: 'above' };
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (let at = start; !above.has(at) && at !== source; at = at.parent) {
|
|
204
|
-
const open = tested ? union([surface(state, at), testSurface(state, at)]) : surface(state, at);
|
|
205
|
-
if (!open.has(to))
|
|
225
|
+
for (let at = target; !above.has(at) && at !== source; at = at.parent)
|
|
226
|
+
if (!surface(state, at, undefined, view).has(to))
|
|
206
227
|
return { reason: 'private', hiddenBy: at };
|
|
207
|
-
}
|
|
208
|
-
return { reason: 'not-in-using' };
|
|
228
|
+
return { reason: 'not-in-dependencies' };
|
|
209
229
|
};
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
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
|
|
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
|
|
19
|
+
export {};
|
|
@@ -1,84 +1,67 @@
|
|
|
1
1
|
import { ConfigError } from '../configError.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
?
|
|
6
|
-
: `${ref.kind === 'required' ?
|
|
7
|
-
export const
|
|
8
|
-
for (const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
kinds: ['module', 'required', 'package'],
|
|
13
|
-
refused: '',
|
|
14
|
-
module: module.data.name,
|
|
15
|
-
};
|
|
16
|
-
const where = `${archetype.name}.${module.data.name}`;
|
|
17
|
-
module.data.using.push(...module.using.map((value) => toRef(check, value, `${where} uses`, scope)));
|
|
18
|
-
if (module.tests && module.data.kind === 'files')
|
|
19
|
-
module.data.tests = testLayer(check, `${where}.tests`, archetype, module.tests, 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
|
-
};
|
|
27
|
-
if (exposes)
|
|
28
|
-
archetype.exposes = exposesData(check, archetype.name, exposes, own);
|
|
29
|
-
for (const [name, value] of Object.entries(provides)) {
|
|
30
|
-
const scope = { ...own, whole: true };
|
|
31
|
-
archetype.provides[name] = toRef(check, value, `${archetype.name} provides ${name} as`, scope);
|
|
6
|
+
? packageText(ref.pattern)
|
|
7
|
+
: `${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);
|
|
11
|
+
if (problem)
|
|
12
|
+
fail(`${entry.where}: '${show(entry.ref)}': ${problem}`);
|
|
32
13
|
}
|
|
33
|
-
if (tests)
|
|
34
|
-
archetype.tests = testLayer(check, `${archetype.name}.tests`, archetype, tests, {
|
|
35
|
-
...own,
|
|
36
|
-
kinds: ['module', 'required', 'package'],
|
|
37
|
-
refused: '',
|
|
38
|
-
module: 'tests',
|
|
39
|
-
});
|
|
40
14
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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);
|
|
56
35
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(', ');
|
|
76
59
|
};
|
|
77
60
|
export const toRules = (check, value, where) => {
|
|
78
61
|
if (value === undefined || value === 'off')
|
|
79
62
|
return value;
|
|
80
63
|
if (!isRecord(value)) {
|
|
81
|
-
check.fail(`${where}: expected
|
|
64
|
+
check.fail(`${where}: expected off or rule settings by id`);
|
|
82
65
|
return undefined;
|
|
83
66
|
}
|
|
84
67
|
return Object.fromEntries(Object.entries(value).map(([id, setting]) => [id, toSetting(check, id, setting, where)]));
|
|
@@ -86,12 +69,14 @@ export const toRules = (check, value, where) => {
|
|
|
86
69
|
const toSetting = (check, id, setting, where) => {
|
|
87
70
|
if (id !== '*' && check.ruleIds && !check.ruleIds.has(id))
|
|
88
71
|
check.fail(`${where}: no rule called ${id}`);
|
|
72
|
+
else if (setting === 'on' || setting === 'off')
|
|
73
|
+
return setting === 'on';
|
|
89
74
|
else if (typeof setting === 'boolean')
|
|
90
75
|
return setting;
|
|
91
|
-
else if (id !== '*' && isRecord(setting)
|
|
76
|
+
else if (id !== '*' && isRecord(setting))
|
|
92
77
|
return checkOptions(check, id, setting, where);
|
|
93
78
|
else
|
|
94
|
-
check.fail(`${where}.${id}: expected
|
|
79
|
+
check.fail(`${where}.${id}: expected on, off${id === '*' ? '' : ' or options'}`);
|
|
95
80
|
return undefined;
|
|
96
81
|
};
|
|
97
82
|
const checkOptions = (check, id, options, where) => {
|
|
@@ -105,62 +90,3 @@ const checkOptions = (check, id, options, where) => {
|
|
|
105
90
|
}
|
|
106
91
|
return { ...options };
|
|
107
92
|
};
|
|
108
|
-
const refProblem = (check, ref, scope) => {
|
|
109
|
-
if (!scope.kinds.includes(ref.kind))
|
|
110
|
-
return scope.refused;
|
|
111
|
-
if (ref.kind === 'package')
|
|
112
|
-
return isName(ref.pattern) ? undefined : 'a package pattern is a non-empty string';
|
|
113
|
-
if (ref.kind === 'required')
|
|
114
|
-
return requiredProblem(check, ref.name, ref.surface, scope.archetype);
|
|
115
|
-
return moduleProblem(check, ref.module, ref.surface, scope);
|
|
116
|
-
};
|
|
117
|
-
const requiredProblem = (check, name, surface, archetype) => {
|
|
118
|
-
const requirement = archetype.requires[name];
|
|
119
|
-
if (!requirement)
|
|
120
|
-
return `${archetype.name} requires ${list(Object.keys(archetype.requires), 'nothing')}`;
|
|
121
|
-
if (requirement.kind !== 'archetype')
|
|
122
|
-
return surface === undefined ? undefined : `required.${name} is ${requirement.kind}(), which has no surfaces`;
|
|
123
|
-
return exposedProblem(`required.${name}`, requirement.archetype, check.exposesOf(requirement.archetype), surface);
|
|
124
|
-
};
|
|
125
|
-
const moduleProblem = (check, name, surface, scope) => {
|
|
126
|
-
const index = scope.archetype.modules.findIndex((module) => module.name === name);
|
|
127
|
-
if (index < 0 || index >= scope.visible)
|
|
128
|
-
return visibilityProblem(name, index, scope);
|
|
129
|
-
if (surface !== undefined && scope.whole)
|
|
130
|
-
return 'name the whole module, without a surface';
|
|
131
|
-
const module = scope.archetype.modules[index];
|
|
132
|
-
if (module.kind === 'files')
|
|
133
|
-
return exposedProblem(name, undefined, module.exposes, surface);
|
|
134
|
-
return exposedProblem(name, archetypeText(scope.archetype, module), check.exposesOf(module.archetype), surface);
|
|
135
|
-
};
|
|
136
|
-
const archetypeText = (holder, module) => module.archetype === holder.name || module.archetype.startsWith(`${holder.name}.`) ? undefined : module.archetype;
|
|
137
|
-
const exposedProblem = (name, archetype, exposes, surface) => {
|
|
138
|
-
const subject = archetype === undefined ? name : `${name} (${archetype})`;
|
|
139
|
-
if (exposes === undefined)
|
|
140
|
-
return `${subject} exposes nothing: give ${archetype ?? name} exposes, or drop the reference`;
|
|
141
|
-
if (surface === undefined)
|
|
142
|
-
return undefined;
|
|
143
|
-
if (exposes.kind !== 'surfaces')
|
|
144
|
-
return `${subject} exposes ${exposesText(exposes)}, not named surfaces`;
|
|
145
|
-
const surfaces = Object.keys(exposes.surfaces);
|
|
146
|
-
return surfaces.includes(surface) ? undefined : `${subject} exposes ${list(surfaces, 'nothing')}`;
|
|
147
|
-
};
|
|
148
|
-
export const exposesText = (exposes) => {
|
|
149
|
-
if (exposes === undefined)
|
|
150
|
-
return 'nothing';
|
|
151
|
-
if (exposes.kind === 'all')
|
|
152
|
-
return 'all its files';
|
|
153
|
-
if (exposes.kind === 'files')
|
|
154
|
-
return `files(${exposes.patterns.map((pattern) => `'${pattern}'`).join(', ')})`;
|
|
155
|
-
return list(Object.keys(exposes.surfaces), 'nothing');
|
|
156
|
-
};
|
|
157
|
-
const visibilityProblem = (name, index, { archetype, visible, module }) => {
|
|
158
|
-
const above = list(archetype.modules.slice(0, visible).map((candidate) => candidate.name), 'no modules');
|
|
159
|
-
if (module === undefined)
|
|
160
|
-
return `${archetype.name} has modules ${above}`;
|
|
161
|
-
if (index < 0)
|
|
162
|
-
return `${module} sees ${above}`;
|
|
163
|
-
if (index === visible)
|
|
164
|
-
return `a module reaches its own files already; ${module} sees ${above}`;
|
|
165
|
-
return `${name} is declared below ${module}, which sees ${above}`;
|
|
166
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArchetypeData } from './data.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PendingRef } from './language.ts';
|
|
3
3
|
import type { Fail } from './shared.ts';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
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;
|