@yearofthedan/warp 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -10
- package/dist/adapters/analysis/chains.d.ts +4 -0
- package/dist/adapters/analysis/chains.js +97 -0
- package/dist/adapters/analysis/classes.d.ts +3 -0
- package/dist/adapters/analysis/classes.js +109 -0
- package/dist/{analysis → adapters/analysis}/complexity.d.ts +1 -1
- package/dist/adapters/analysis/folders.d.ts +2 -0
- package/dist/{app/facts.d.ts → adapters/analysis/freshFacts.d.ts} +1 -2
- package/dist/{app/facts.js → adapters/analysis/freshFacts.js} +0 -10
- package/dist/{analysis → adapters/analysis}/imports.d.ts +2 -1
- package/dist/{analysis → adapters/analysis}/imports.js +60 -23
- package/dist/{analysis → adapters/analysis}/members.d.ts +1 -1
- package/dist/{analysis → adapters/analysis}/members.js +1 -1
- package/dist/{analysis → adapters/analysis}/source.d.ts +2 -2
- package/dist/{analysis → adapters/analysis}/source.js +2 -2
- package/dist/adapters/analysis/specifiers.d.ts +10 -0
- package/dist/adapters/analysis/specifiers.js +39 -0
- package/dist/adapters/analysis/typescript.d.ts +2 -0
- package/dist/{analysis → adapters/analysis}/typescript.js +14 -4
- package/dist/{config → adapters/config}/loadConfig.d.ts +2 -7
- package/dist/{config → adapters/config}/loadConfig.js +5 -4
- package/dist/{git → adapters/git}/cache.d.ts +1 -1
- package/dist/adapters/git/factsStore.d.ts +2 -0
- package/dist/adapters/git/factsStore.js +10 -0
- package/dist/{git → adapters/git}/repository.d.ts +1 -1
- package/dist/{config → adapters/git}/toolDigest.js +1 -1
- package/dist/{reporters → adapters/reporters}/model.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/reporter.d.ts +2 -2
- package/dist/{reporters → adapters/reporters}/text.d.ts +2 -2
- package/dist/app/check.d.ts +5 -6
- package/dist/app/check.js +3 -3
- package/dist/app/checkModel.d.ts +5 -5
- package/dist/app/checkModel.js +7 -8
- package/dist/app/configLines.d.ts +1 -1
- package/dist/app/diff.d.ts +1 -1
- package/dist/app/diff.js +1 -1
- package/dist/app/failures.d.ts +6 -0
- package/dist/app/failures.js +15 -0
- package/dist/app/load.d.ts +11 -5
- package/dist/app/load.js +23 -59
- package/dist/app/ports.d.ts +13 -3
- package/dist/builtins/advice.d.ts +4 -4
- package/dist/builtins/advice.js +1 -1
- package/dist/builtins/boundaries.d.ts +17 -0
- package/dist/builtins/boundaries.js +35 -0
- package/dist/builtins/class-cohesion/rule.d.ts +6 -0
- package/dist/builtins/class-cohesion/rule.js +34 -0
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/cognitive-complexity/{cognitiveComplexity.js → rule.js} +1 -1
- package/dist/builtins/components.d.ts +1 -1
- package/dist/builtins/dependency-direction/rule.d.ts +2 -0
- package/dist/builtins/dependency-direction/{dependencyDirection.js → rule.js} +3 -3
- package/dist/builtins/export-consumers/rule.d.ts +6 -0
- package/dist/builtins/export-consumers/rule.js +65 -0
- package/dist/builtins/export-spread/rule.d.ts +3 -0
- package/dist/builtins/export-spread/rule.js +65 -0
- package/dist/builtins/export-surface/rule.d.ts +6 -0
- package/dist/builtins/export-surface/rule.js +60 -0
- package/dist/builtins/file-cohesion/{fileCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/file-cohesion/{fileCohesion.js → rule.js} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/function-cohesion/{functionCohesion.js → rule.js} +1 -1
- package/dist/builtins/index.d.ts +2 -2
- package/dist/builtins/index.js +33 -13
- package/dist/builtins/loops.d.ts +1 -1
- package/dist/builtins/loops.js +1 -1
- package/dist/builtins/module-cycle/{moduleCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/module-dependencies/rule.d.ts +3 -0
- package/dist/builtins/module-dependencies/rule.js +67 -0
- package/dist/builtins/module-externals/rule.d.ts +2 -0
- package/dist/builtins/module-externals/{moduleExternals.js → rule.js} +3 -3
- package/dist/builtins/module-size/rule.d.ts +6 -0
- package/dist/builtins/module-size/rule.js +36 -0
- package/dist/builtins/no-cross-module-reexport/rule.d.ts +2 -0
- package/dist/builtins/no-cross-module-reexport/{noCrossModuleReexport.js → rule.js} +1 -1
- package/dist/builtins/no-cycle/{noCycle.d.ts → rule.d.ts} +1 -1
- package/dist/builtins/no-double-export/rule.d.ts +2 -0
- package/dist/builtins/no-double-export/{noDoubleExport.js → rule.js} +1 -1
- package/dist/builtins/packages.d.ts +1 -1
- package/dist/builtins/place.d.ts +1 -1
- package/dist/builtins/shared.d.ts +1 -1
- package/dist/builtins/unclassified/rule.d.ts +2 -0
- package/dist/builtins/unclassified/rule.js +15 -0
- package/dist/builtins/unresolved-import/rule.d.ts +2 -0
- package/dist/builtins/unresolved-import/{unresolvedImport.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/declarations.d.ts +3 -3
- package/dist/builtins/unused-declaration/empty.d.ts +1 -1
- package/dist/builtins/unused-declaration/empty.js +1 -1
- package/dist/builtins/unused-declaration/grants.d.ts +1 -1
- package/dist/builtins/unused-declaration/grants.js +42 -10
- package/dist/builtins/unused-declaration/rule.d.ts +2 -0
- package/dist/builtins/unused-declaration/{unusedDeclaration.js → rule.js} +1 -1
- package/dist/builtins/unused-declaration/surfaces.d.ts +1 -1
- package/dist/builtins/unused-declaration/surfaces.js +1 -1
- package/dist/cli.js +34 -54
- package/dist/{model → domain/facts}/facts.d.ts +20 -0
- package/dist/{model/archetype → domain/fixes}/fixes.d.ts +2 -2
- package/dist/{model/archetype → domain/fixes}/fixes.js +2 -6
- package/dist/domain/language/compile.d.ts +12 -0
- package/dist/domain/language/compile.js +58 -0
- package/dist/{model/archetype → domain/language}/references.d.ts +6 -7
- package/dist/{model/archetype → domain/language}/references.js +41 -26
- package/dist/{model/archetype → domain/language}/requirements.d.ts +3 -3
- package/dist/{model/archetype → domain/language}/requirements.js +2 -1
- package/dist/domain/language/rulesets.d.ts +11 -0
- package/dist/domain/language/rulesets.js +60 -0
- package/dist/{model/archetype/language.d.ts → domain/language/structure.d.ts} +4 -3
- package/dist/{model/archetype/language.js → domain/language/structure.js} +33 -12
- package/dist/{model/archetype → domain/model}/data.d.ts +9 -6
- package/dist/{model/archetype → domain/model}/reach.d.ts +2 -0
- package/dist/{model/archetype → domain/model}/reach.js +10 -7
- package/dist/{model/archetype → domain/model}/resolve.d.ts +2 -0
- package/dist/{model/archetype → domain/model}/resolve.js +6 -1
- package/dist/{model/archetype → domain/model}/settings.d.ts +3 -3
- package/dist/domain/model/settings.js +83 -0
- package/dist/domain/model/text.d.ts +4 -0
- package/dist/domain/model/text.js +13 -0
- package/dist/{rules → domain/rules}/registry.d.ts +1 -0
- package/dist/{rules → domain/rules}/registry.js +11 -1
- package/dist/{rules → domain/rules}/rule.d.ts +11 -4
- package/dist/{rules → domain/rules}/rule.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/analysis/folders.d.ts +0 -2
- package/dist/analysis/specifiers.d.ts +0 -2
- package/dist/analysis/specifiers.js +0 -6
- package/dist/analysis/typescript.d.ts +0 -2
- package/dist/app/unclassified.d.ts +0 -5
- package/dist/app/unclassified.js +0 -13
- package/dist/builtins/dependency-direction/dependencyDirection.d.ts +0 -2
- package/dist/builtins/module-externals/moduleExternals.d.ts +0 -2
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +0 -2
- package/dist/builtins/no-double-export/noDoubleExport.d.ts +0 -2
- package/dist/builtins/unresolved-import/unresolvedImport.d.ts +0 -2
- package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +0 -2
- package/dist/model/archetype/rulesets.d.ts +0 -5
- package/dist/model/archetype/rulesets.js +0 -139
- package/dist/model/archetype/settings.js +0 -54
- /package/dist/{analysis → adapters/analysis}/complexity.js +0 -0
- /package/dist/{analysis → adapters/analysis}/folders.js +0 -0
- /package/dist/{git → adapters/git}/cache.js +0 -0
- /package/dist/{git → adapters/git}/repository.js +0 -0
- /package/dist/{config → adapters/git}/toolDigest.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/agent.js +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/claudeHook.js +0 -0
- /package/dist/{reporters → adapters/reporters}/index.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/index.js +0 -0
- /package/dist/{reporters → adapters/reporters}/json.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/json.js +0 -0
- /package/dist/{reporters → adapters/reporters}/model.js +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/omp.js +0 -0
- /package/dist/{reporters → adapters/reporters}/reporter.js +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.d.ts +0 -0
- /package/dist/{reporters → adapters/reporters}/sarif.js +0 -0
- /package/dist/{reporters → adapters/reporters}/text.js +0 -0
- /package/dist/builtins/module-cycle/{moduleCycle.js → rule.js} +0 -0
- /package/dist/builtins/no-cycle/{noCycle.js → rule.js} +0 -0
- /package/dist/{model → domain/errors}/configError.d.ts +0 -0
- /package/dist/{model → domain/errors}/configError.js +0 -0
- /package/dist/{model → domain/facts}/facts.js +0 -0
- /package/dist/{model/archetype → domain/model}/data.js +0 -0
- /package/dist/{model/archetype → domain/model}/shared.d.ts +0 -0
- /package/dist/{model/archetype → domain/model}/shared.js +0 -0
- /package/dist/{rules → domain/rules}/diff.d.ts +0 -0
- /package/dist/{rules → domain/rules}/diff.js +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import { diskFolders } from './analysis/folders.js';
|
|
6
|
-
import { typescriptAnalyzer } from './analysis/typescript.js';
|
|
5
|
+
import { diskFolders } from './adapters/analysis/folders.js';
|
|
6
|
+
import { typescriptAnalyzer } from './adapters/analysis/typescript.js';
|
|
7
7
|
import { modelProject, projectCheck } from './app/check.js';
|
|
8
8
|
import { placeProblems } from './app/configLines.js';
|
|
9
|
-
import { factsStore } from './
|
|
9
|
+
import { factsStore } from './adapters/git/factsStore.js';
|
|
10
|
+
import { failures } from './app/failures.js';
|
|
10
11
|
import { diffProject, parseRange } from './app/diff.js';
|
|
11
|
-
import {
|
|
12
|
-
import { findConfig,
|
|
13
|
-
import { toolDigest } from './
|
|
14
|
-
import { gitDirCache } from './git/cache.js';
|
|
15
|
-
import { gitRepository, projectPathOf } from './git/repository.js';
|
|
16
|
-
import { anyRuleOn, rulesOf } from './model/
|
|
17
|
-
import { recommended } from './
|
|
18
|
-
import {
|
|
19
|
-
import { ConfigError } from './
|
|
20
|
-
import { reporters } from './reporters/index.js';
|
|
21
|
-
import { modelJson, modelText } from './reporters/model.js';
|
|
22
|
-
import { actionable } from './reporters/reporter.js';
|
|
12
|
+
import { warp } from './builtins/index.js';
|
|
13
|
+
import { findConfig, yamlConfig } from './adapters/config/loadConfig.js';
|
|
14
|
+
import { toolDigest } from './adapters/git/toolDigest.js';
|
|
15
|
+
import { gitDirCache } from './adapters/git/cache.js';
|
|
16
|
+
import { gitRepository, projectPathOf } from './adapters/git/repository.js';
|
|
17
|
+
import { anyRuleOn, rulesOf } from './domain/model/settings.js';
|
|
18
|
+
import { recommended } from './domain/language/compile.js';
|
|
19
|
+
import { loadConfig } from './app/load.js';
|
|
20
|
+
import { ConfigError } from './domain/errors/configError.js';
|
|
21
|
+
import { reporters } from './adapters/reporters/index.js';
|
|
22
|
+
import { modelJson, modelText } from './adapters/reporters/model.js';
|
|
23
|
+
import { actionable } from './adapters/reporters/reporter.js';
|
|
23
24
|
const usage = `usage:
|
|
24
|
-
warp check [--config <file>] [--
|
|
25
|
-
warp diff <base>[..<head> | ...<head>] [--since-last-run] [--config <file>] [--
|
|
26
|
-
warp model [--config <file>] [--
|
|
25
|
+
warp check [--config <file>] [--reporter <name>] [--fail]
|
|
26
|
+
warp diff <base>[..<head> | ...<head>] [--since-last-run] [--config <file>] [--reporter <name>] [--fail]
|
|
27
|
+
warp model [--config <file>] [--rules] [--json]
|
|
27
28
|
|
|
28
29
|
check reports every finding in the working tree.
|
|
29
30
|
diff reports findings that are new or worse at <head> than at <base>. Without <head>, compares the working tree.
|
|
@@ -32,16 +33,17 @@ diff reports findings that are new or worse at <head> than at <base>. Without
|
|
|
32
33
|
model prints the modules the config finds, and which module each file is in.
|
|
33
34
|
|
|
34
35
|
--config path to the config file (default: warp.yaml)
|
|
35
|
-
--ruleset one of the config's rulesets (default: the one named default, if any)
|
|
36
36
|
--reporter ${[...reporters.keys()].join(', ')} (default: text)
|
|
37
37
|
--since-last-run with diff, compare with the last diff run that had this flag
|
|
38
38
|
--fail exit 1 when there are findings (check) or new or worse findings (diff)
|
|
39
39
|
--rules with model, list each module's rule settings that differ from the defaults
|
|
40
40
|
--json print the model as JSON, with every module's resolved rule settings`;
|
|
41
|
+
let toolHash;
|
|
42
|
+
const tool = () => (toolHash ??= toolDigest());
|
|
41
43
|
const adaptersAt = (root) => {
|
|
42
44
|
const adapters = { analyzer: typescriptAnalyzer, foldersAt: diskFolders };
|
|
43
45
|
try {
|
|
44
|
-
return { ...adapters, facts: factsStore(gitDirCache(root),
|
|
46
|
+
return { ...adapters, facts: factsStore(gitDirCache(root), tool(), gitRepository(root).projectPath()) };
|
|
45
47
|
}
|
|
46
48
|
catch {
|
|
47
49
|
return adapters;
|
|
@@ -53,7 +55,6 @@ const main = async (argv) => {
|
|
|
53
55
|
allowPositionals: true,
|
|
54
56
|
options: {
|
|
55
57
|
config: { type: 'string' },
|
|
56
|
-
ruleset: { type: 'string' },
|
|
57
58
|
rules: { type: 'boolean', default: false },
|
|
58
59
|
reporter: { type: 'string', default: 'text' },
|
|
59
60
|
fail: { type: 'boolean', default: false },
|
|
@@ -83,22 +84,13 @@ const help = (code) => {
|
|
|
83
84
|
const resolveConfig = async (options) => {
|
|
84
85
|
const configFile = realpathSync(options.config ? resolve(options.config) : findConfig(process.cwd()));
|
|
85
86
|
const root = dirname(configFile);
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const tsconfig of config.tsconfig.filter((path) => !existsSync(join(root, path))))
|
|
92
|
-
throw new ConfigError(`tsconfig: no ${tsconfig} beside ${file}; add it, or list the project's tsconfig files under tsconfig`);
|
|
93
|
-
return { root, config, rules, lines, digest };
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
if (error instanceof ConfigError)
|
|
97
|
-
throw new ConfigError(placeProblems(lines, file, error.message));
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
87
|
+
const source = yamlConfig(configFile);
|
|
88
|
+
const loaded = await loadConfig(source, { builtins: warp });
|
|
89
|
+
for (const tsconfig of loaded.config.tsconfig.filter((path) => !existsSync(join(root, path))))
|
|
90
|
+
throw new ConfigError(placeProblems(loaded.lines, source.file, `tsconfig: no ${tsconfig} beside ${source.file}; add it, or list the project's tsconfig files under tsconfig`));
|
|
91
|
+
return { root, ...loaded };
|
|
100
92
|
};
|
|
101
|
-
const checkOf = ({ root, config, rules, lines }) => projectCheck(adaptersAt(root), config, { rules,
|
|
93
|
+
const checkOf = ({ root, config, rules, lines }) => projectCheck(adaptersAt(root), config, { rules, lines });
|
|
102
94
|
const run = async (options, produce) => {
|
|
103
95
|
const reporter = reporters.get(options.reporter);
|
|
104
96
|
if (!reporter)
|
|
@@ -112,13 +104,13 @@ const run = async (options, produce) => {
|
|
|
112
104
|
if (output)
|
|
113
105
|
console.log(output);
|
|
114
106
|
if (reporter.renderFailure)
|
|
115
|
-
|
|
107
|
+
lastFailure().forget();
|
|
116
108
|
return options.fail && actionable(report).length > 0 ? 1 : 0;
|
|
117
109
|
}
|
|
118
110
|
catch (error) {
|
|
119
111
|
const code = failed(error, reporter.failureExitCode);
|
|
120
112
|
const problem = describe(error);
|
|
121
|
-
if (!reporter.renderFailure || !
|
|
113
|
+
if (!reporter.renderFailure || !lastFailure().isNew(problem))
|
|
122
114
|
return code;
|
|
123
115
|
console.log(reporter.renderFailure(problem));
|
|
124
116
|
return 0;
|
|
@@ -134,8 +126,7 @@ const placed = ({ lines, config }, run) => {
|
|
|
134
126
|
throw error;
|
|
135
127
|
}
|
|
136
128
|
};
|
|
137
|
-
const nothingOn = (file) => `No rules are on, so nothing was checked. Turn some on in ${file}:
|
|
138
|
-
const failureKey = () => `${toolDigest()}-failure`;
|
|
129
|
+
const nothingOn = (file) => `No rules are on, so nothing was checked. Turn some on in ${file}: root: { ruleset: [${recommended}] }`;
|
|
139
130
|
const failureCache = () => {
|
|
140
131
|
try {
|
|
141
132
|
return gitDirCache(process.cwd());
|
|
@@ -144,18 +135,7 @@ const failureCache = () => {
|
|
|
144
135
|
return undefined;
|
|
145
136
|
}
|
|
146
137
|
};
|
|
147
|
-
const
|
|
148
|
-
const cache = failureCache();
|
|
149
|
-
if (cache?.get(failureKey()) === problem)
|
|
150
|
-
return false;
|
|
151
|
-
cache?.set(failureKey(), problem);
|
|
152
|
-
return true;
|
|
153
|
-
};
|
|
154
|
-
const forgetFailure = () => {
|
|
155
|
-
const cache = failureCache();
|
|
156
|
-
if (cache?.get(failureKey()) !== undefined)
|
|
157
|
-
cache.prune((key) => key !== failureKey());
|
|
158
|
-
};
|
|
138
|
+
const lastFailure = () => failures(failureCache(), tool());
|
|
159
139
|
const printModel = async (options) => {
|
|
160
140
|
try {
|
|
161
141
|
const resolved = await resolveConfig(options);
|
|
@@ -169,7 +149,7 @@ const printModel = async (options) => {
|
|
|
169
149
|
return failed(error);
|
|
170
150
|
}
|
|
171
151
|
};
|
|
172
|
-
const delta = (range, root, project, configDigest, sinceLastRun) => diffProject({ range: parseRange(range), root, project, configDigest, toolDigest:
|
|
152
|
+
const delta = (range, root, project, configDigest, sinceLastRun) => diffProject({ range: parseRange(range), root, project, configDigest, toolDigest: tool(), sinceLastRun }, { repository: gitRepository(root), cache: gitDirCache(root) });
|
|
173
153
|
const version = () => JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
174
154
|
const describe = (error) => error instanceof ConfigError
|
|
175
155
|
? `warp config: ${error.message}`
|
|
@@ -9,6 +9,8 @@ export interface FileFacts {
|
|
|
9
9
|
unresolved: UnresolvedImport[];
|
|
10
10
|
members: MemberGraph;
|
|
11
11
|
functions: FunctionFacts[];
|
|
12
|
+
classes: ClassFacts[];
|
|
13
|
+
chains: Chain[];
|
|
12
14
|
}
|
|
13
15
|
export interface ImportEdge {
|
|
14
16
|
from: string;
|
|
@@ -61,3 +63,21 @@ export interface Complexity {
|
|
|
61
63
|
reason: string;
|
|
62
64
|
}[];
|
|
63
65
|
}
|
|
66
|
+
export interface ClassFacts {
|
|
67
|
+
name: string;
|
|
68
|
+
line: number;
|
|
69
|
+
endLine: number;
|
|
70
|
+
lines: number;
|
|
71
|
+
members: MemberGraph;
|
|
72
|
+
}
|
|
73
|
+
export interface Chain {
|
|
74
|
+
line: number;
|
|
75
|
+
root?: Declared;
|
|
76
|
+
hops: Declared[];
|
|
77
|
+
call: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface Declared {
|
|
80
|
+
file: string;
|
|
81
|
+
name: string;
|
|
82
|
+
member?: string;
|
|
83
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ConfigData, RefData } from '
|
|
2
|
-
import type
|
|
1
|
+
import type { ConfigData, RefData } from '../model/data.ts';
|
|
2
|
+
import { type Model, type ModuleView } from '../model/resolve.ts';
|
|
3
3
|
export interface Site {
|
|
4
4
|
label: string;
|
|
5
5
|
holder: ModuleView;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { instanceOf, verdicts } from '
|
|
2
|
-
|
|
3
|
-
for (let at = module.parent; at; at = at.parent)
|
|
4
|
-
yield at;
|
|
5
|
-
};
|
|
1
|
+
import { instanceOf, verdicts } from '../model/reach.js';
|
|
2
|
+
import { ancestors, subtree } from '../model/resolve.js';
|
|
6
3
|
const lineage = (module) => [module, ...ancestors(module)];
|
|
7
4
|
export const namedArchetype = (config, name) => config.archetypes[name].inline ? namedArchetype(config, name.slice(0, name.lastIndexOf('.'))) : name;
|
|
8
5
|
const withArchetype = (config, name, change) => ({
|
|
@@ -208,7 +205,6 @@ const exposeFilesModule = (search, config, hiddenBy) => {
|
|
|
208
205
|
})),
|
|
209
206
|
};
|
|
210
207
|
};
|
|
211
|
-
const subtree = (module) => [module, ...module.children.flatMap(subtree)];
|
|
212
208
|
const uses = (config, model, from, under) => {
|
|
213
209
|
const judge = verdicts(config, model);
|
|
214
210
|
const reached = subtree(from).flatMap((module) => module.files.slice(0, 1).flatMap((file) => (judge.reach(file) ?? []).flatMap((grant) => [...grant.files])));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConfigData } from '../model/data.ts';
|
|
2
|
+
import { type Check } from './references.ts';
|
|
3
|
+
export { recommended } from './rulesets.ts';
|
|
4
|
+
export interface CompileOptions {
|
|
5
|
+
file?: string;
|
|
6
|
+
plugins?: readonly string[];
|
|
7
|
+
rulesets?: Readonly<Record<string, unknown>>;
|
|
8
|
+
ruleIds?: ReadonlySet<string> | undefined;
|
|
9
|
+
options?: Check['options'];
|
|
10
|
+
moduleOptions?: Check['moduleOptions'];
|
|
11
|
+
}
|
|
12
|
+
export declare const compileConfig: (raw: unknown, { file, plugins, rulesets, ruleIds, options, moduleOptions }?: CompileOptions) => ConfigData;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ConfigError } from '../errors/configError.js';
|
|
2
|
+
import { defined, isName, isRecord } from '../model/shared.js';
|
|
3
|
+
import { checkReferences, toRules } from './references.js';
|
|
4
|
+
import { checkInputs, markTests } from './requirements.js';
|
|
5
|
+
import { rulesets as namedRulesets } from './rulesets.js';
|
|
6
|
+
import { parseStructure } from './structure.js';
|
|
7
|
+
export { recommended } from './rulesets.js';
|
|
8
|
+
const keys = ['root', 'archetypes', 'rulesets', 'plugins', 'tsconfig'];
|
|
9
|
+
export const compileConfig = (raw, { file = 'warp.yaml', plugins = [], rulesets = {}, ruleIds, options = {}, moduleOptions = {} } = {}) => {
|
|
10
|
+
const errors = [];
|
|
11
|
+
const fail = (message) => {
|
|
12
|
+
if (!errors.includes(message))
|
|
13
|
+
errors.push(message);
|
|
14
|
+
};
|
|
15
|
+
const failed = () => {
|
|
16
|
+
if (errors.length > 0)
|
|
17
|
+
throw new ConfigError(errors.join('\n'));
|
|
18
|
+
};
|
|
19
|
+
if (!isRecord(raw))
|
|
20
|
+
throw new ConfigError(`${file}: expected a mapping, root: { modules: ... }`);
|
|
21
|
+
const unknownKeys = Object.keys(raw).filter((key) => !keys.includes(key));
|
|
22
|
+
for (const key of unknownKeys)
|
|
23
|
+
fail(`${key}: unknown key; a config takes ${keys.join(', ')}`);
|
|
24
|
+
checkPlugins(raw.plugins, plugins, fail);
|
|
25
|
+
const check = { fail, ruleIds, options, moduleOptions };
|
|
26
|
+
const named = namedRulesets(raw.rulesets, rulesets, (value, at, names) => toRules(check, value, at, names), fail);
|
|
27
|
+
const structure = parseStructure(raw.root, raw.archetypes, fail, named.parse);
|
|
28
|
+
named.checkUsed();
|
|
29
|
+
failed();
|
|
30
|
+
checkReferences(structure.archetypes, structure.pending, fail);
|
|
31
|
+
markTests(structure.archetypes, fail);
|
|
32
|
+
checkInputs(structure.archetypes, structure.pending, fail);
|
|
33
|
+
const config = {
|
|
34
|
+
file,
|
|
35
|
+
root: structure.root,
|
|
36
|
+
archetypes: Object.fromEntries(Object.entries(structure.archetypes).map(([name, archetype]) => [name, archetypeData(archetype)])),
|
|
37
|
+
tsconfig: tsconfigs(raw.tsconfig, fail),
|
|
38
|
+
};
|
|
39
|
+
failed();
|
|
40
|
+
return config;
|
|
41
|
+
};
|
|
42
|
+
const archetypeData = (archetype) => defined({ ...archetype, modules: archetype.modules.map(defined) });
|
|
43
|
+
const checkPlugins = (declared, loaded, fail) => {
|
|
44
|
+
if (declared === undefined)
|
|
45
|
+
return;
|
|
46
|
+
if (!isRecord(declared) || !Object.values(declared).every(isName)) {
|
|
47
|
+
fail('plugins: expected plugin paths by namespace, { wt: ./rules/wt.ts }');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const namespace of Object.keys(declared).filter((namespace) => !loaded.includes(namespace)))
|
|
51
|
+
fail(`plugins.${namespace}: not loaded; warp loads each plugin from its path before reading the config`);
|
|
52
|
+
};
|
|
53
|
+
const tsconfigs = (value, fail) => {
|
|
54
|
+
const paths = [value ?? 'tsconfig.json'].flat();
|
|
55
|
+
if (paths.length === 0 || !paths.every(isName))
|
|
56
|
+
fail('tsconfig: expected a path or a list of paths');
|
|
57
|
+
return paths;
|
|
58
|
+
};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { type ArchetypeData, type ExposesData, type
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import { type ArchetypeData, type ExposesData, type RuleSettingsData } from '../model/data.ts';
|
|
2
|
+
import type { Names } from './rulesets.ts';
|
|
3
|
+
import type { PendingRef } from './structure.ts';
|
|
4
|
+
import { type Fail } from '../model/shared.ts';
|
|
4
5
|
export interface Check {
|
|
5
6
|
fail: Fail;
|
|
6
7
|
ruleIds?: ReadonlySet<string> | undefined;
|
|
7
8
|
options: Readonly<Record<string, (raw: Record<string, unknown>, at: string) => unknown>>;
|
|
9
|
+
moduleOptions: Readonly<Record<string, readonly string[]>>;
|
|
8
10
|
}
|
|
9
|
-
export declare const packageText: (pattern: string) => string;
|
|
10
|
-
export declare const show: (ref: RefData) => string;
|
|
11
11
|
export declare const checkReferences: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;
|
|
12
12
|
interface Surfaces {
|
|
13
13
|
exposes: ExposesData | undefined;
|
|
14
14
|
testExposes: readonly string[];
|
|
15
15
|
}
|
|
16
16
|
export declare const exposedProblem: (subject: string, { exposes, testExposes }: Surfaces, surface: string | undefined, tests: boolean) => string | undefined;
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const toRules: (check: Check, value: unknown, where: string) => RuleSettingsData | undefined;
|
|
17
|
+
export declare const toRules: (check: Check, value: unknown, where: string, names?: Names) => RuleSettingsData | undefined;
|
|
19
18
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ConfigError } from '../configError.js';
|
|
2
|
-
import { isTestData } from '
|
|
3
|
-
import { isRecord, list } from '
|
|
4
|
-
|
|
5
|
-
export const show = (ref) => ref.kind === 'package'
|
|
6
|
-
? packageText(ref.pattern)
|
|
7
|
-
: `${ref.kind === 'module' && ref.top ? 'top.' : ''}${ref.kind === 'required' ? ref.name : ref.module}${ref.surface === undefined ? '' : `.${ref.surface}`}`;
|
|
1
|
+
import { ConfigError } from '../errors/configError.js';
|
|
2
|
+
import { isTestData, } from '../model/data.js';
|
|
3
|
+
import { isRecord, list } from '../model/shared.js';
|
|
4
|
+
import { exposesText, show } from '../model/text.js';
|
|
8
5
|
export const checkReferences = (archetypes, pending, fail) => {
|
|
9
6
|
for (const entry of pending) {
|
|
10
7
|
const problem = refProblem(archetypes, entry);
|
|
@@ -48,38 +45,36 @@ export const exposedProblem = (subject, { exposes, testExposes }, surface, tests
|
|
|
48
45
|
return `${subject} exposes ${list(named, 'nothing')}`;
|
|
49
46
|
return `${subject} exposes ${exposesText(exposes)}, not named surfaces`;
|
|
50
47
|
};
|
|
51
|
-
export const
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
54
|
-
if (
|
|
55
|
-
return '
|
|
56
|
-
if (exposes.kind === 'files')
|
|
57
|
-
return `{ files: [${exposes.patterns.join(', ')}] }`;
|
|
58
|
-
return Object.keys(exposes.surfaces).join(', ');
|
|
59
|
-
};
|
|
60
|
-
export const toRules = (check, value, where) => {
|
|
61
|
-
if (value === undefined || value === 'off')
|
|
62
|
-
return value;
|
|
48
|
+
export const toRules = (check, value, where, names) => {
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (value === 'off')
|
|
52
|
+
return { '*': false };
|
|
63
53
|
if (!isRecord(value)) {
|
|
64
54
|
check.fail(`${where}: expected off or rule settings by id`);
|
|
65
55
|
return undefined;
|
|
66
56
|
}
|
|
67
|
-
return Object.fromEntries(Object.entries(value).
|
|
57
|
+
return Object.fromEntries(Object.entries(value).flatMap(([id, setting]) => {
|
|
58
|
+
const parsed = toSetting(check, id, setting, where, names);
|
|
59
|
+
return parsed === undefined ? [] : [[id, parsed]];
|
|
60
|
+
}));
|
|
68
61
|
};
|
|
69
|
-
const toSetting = (check, id, setting, where) => {
|
|
62
|
+
const toSetting = (check, id, setting, where, names) => {
|
|
70
63
|
if (id !== '*' && check.ruleIds && !check.ruleIds.has(id))
|
|
71
64
|
check.fail(`${where}: no rule called ${id}`);
|
|
65
|
+
else if (id === '*' && setting !== 'off' && setting !== false)
|
|
66
|
+
check.fail(`${where}.*: expected off; turn rules on by name, or extend a ruleset such as warp:recommended`);
|
|
72
67
|
else if (setting === 'on' || setting === 'off')
|
|
73
68
|
return setting === 'on';
|
|
74
69
|
else if (typeof setting === 'boolean')
|
|
75
70
|
return setting;
|
|
76
|
-
else if (
|
|
77
|
-
return checkOptions(check, id, setting, where);
|
|
71
|
+
else if (isRecord(setting))
|
|
72
|
+
return checkOptions(check, id, setting, where, names);
|
|
78
73
|
else
|
|
79
|
-
check.fail(`${where}.${id}: expected on, off
|
|
74
|
+
check.fail(`${where}.${id}: expected on, off or options`);
|
|
80
75
|
return undefined;
|
|
81
76
|
};
|
|
82
|
-
const checkOptions = (check, id, options, where) => {
|
|
77
|
+
const checkOptions = (check, id, options, where, names) => {
|
|
83
78
|
try {
|
|
84
79
|
check.options[id]?.(options, `${where}.${id}`);
|
|
85
80
|
}
|
|
@@ -87,6 +82,26 @@ const checkOptions = (check, id, options, where) => {
|
|
|
87
82
|
if (!(error instanceof ConfigError))
|
|
88
83
|
throw error;
|
|
89
84
|
check.fail(error.message);
|
|
85
|
+
return { ...options };
|
|
86
|
+
}
|
|
87
|
+
const resolved = (check.moduleOptions[id] ?? [])
|
|
88
|
+
.filter((key) => options[key] !== undefined)
|
|
89
|
+
.map((key) => [key, modules(check, options[key], `${where}.${id}.${key}`, names)]);
|
|
90
|
+
return { ...options, ...Object.fromEntries(resolved) };
|
|
91
|
+
};
|
|
92
|
+
const modules = (check, entries, where, names) => {
|
|
93
|
+
if (!names) {
|
|
94
|
+
check.fail(`${where}: names modules, so it goes in a ruleset on the root, a module or an archetype`);
|
|
95
|
+
return [];
|
|
90
96
|
}
|
|
91
|
-
return
|
|
97
|
+
return entries.flatMap((entry) => {
|
|
98
|
+
const ref = names(entry, where);
|
|
99
|
+
if (ref === undefined)
|
|
100
|
+
return [];
|
|
101
|
+
if (ref.kind === 'package' || ref.surface !== undefined) {
|
|
102
|
+
check.fail(`${where}: '${entry}': name a module, not a package or a surface`);
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
return [ref];
|
|
106
|
+
});
|
|
92
107
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArchetypeData } from '
|
|
2
|
-
import type { PendingRef } from './
|
|
3
|
-
import type { Fail } from '
|
|
1
|
+
import type { ArchetypeData } from '../model/data.ts';
|
|
2
|
+
import type { PendingRef } from './structure.ts';
|
|
3
|
+
import type { Fail } from '../model/shared.ts';
|
|
4
4
|
export declare const markTests: (archetypes: Record<string, ArchetypeData>, fail: Fail) => void;
|
|
5
5
|
export declare const checkInputs: (archetypes: Record<string, ArchetypeData>, pending: readonly PendingRef[], fail: Fail) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { exposedProblem
|
|
1
|
+
import { exposedProblem } from './references.js';
|
|
2
|
+
import { show } from '../model/text.js';
|
|
2
3
|
const namedOf = (archetype) => archetype.split('.')[0];
|
|
3
4
|
const sitesOf = (archetypes) => Object.values(archetypes).flatMap((holder) => holder.modules
|
|
4
5
|
.filter((module) => module.kind === 'dir' && !archetypes[module.archetype]?.inline)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RefData, RuleSettingsData, RulesetData } from '../model/data.ts';
|
|
2
|
+
import { type Fail } from '../model/shared.ts';
|
|
3
|
+
export type Names = (entry: string, where: string) => RefData | undefined;
|
|
4
|
+
export type ParseRules = (value: unknown, at: string, names?: Names) => RuleSettingsData | undefined;
|
|
5
|
+
export type ParseRuleset = (value: unknown, at: string, names?: Names) => RulesetData | undefined;
|
|
6
|
+
export interface Rulesets {
|
|
7
|
+
parse: ParseRuleset;
|
|
8
|
+
checkUsed(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const recommended = "warp:recommended";
|
|
11
|
+
export declare const rulesets: (named: unknown, shared: Readonly<Record<string, unknown>>, parseRules: ParseRules, fail: Fail) => Rulesets;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isRecord, list } from '../model/shared.js';
|
|
2
|
+
export const recommended = 'warp:recommended';
|
|
3
|
+
const rulesetKeys = ['extends', 'rules'];
|
|
4
|
+
export const rulesets = (named, shared, parseRules, fail) => {
|
|
5
|
+
const state = {
|
|
6
|
+
local: localRulesets(named, fail),
|
|
7
|
+
shared,
|
|
8
|
+
parseRules,
|
|
9
|
+
fail,
|
|
10
|
+
extended: new Set(),
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
parse: (value, at, names) => (value === undefined ? undefined : flatten(state, value, at, [], names)),
|
|
14
|
+
checkUsed: () => {
|
|
15
|
+
for (const name of [...state.local.keys()].filter((name) => !state.extended.has(name)))
|
|
16
|
+
fail(`rulesets.${name}: nothing extends it; a named ruleset applies through a ruleset's extends`);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const localRulesets = (value, fail) => {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return new Map();
|
|
23
|
+
if (!isRecord(value)) {
|
|
24
|
+
fail('rulesets: expected rulesets by name, { strict: { rules: {...} } }');
|
|
25
|
+
return new Map();
|
|
26
|
+
}
|
|
27
|
+
for (const name of Object.keys(value).filter((name) => name.includes(':')))
|
|
28
|
+
fail(`rulesets.${name}: a name has no ':', which marks a plugin's ruleset`);
|
|
29
|
+
return new Map(Object.entries(value).filter(([name]) => !name.includes(':')));
|
|
30
|
+
};
|
|
31
|
+
const flatten = (state, value, at, seen, names) => {
|
|
32
|
+
const def = Array.isArray(value) ? { extends: value } : value === 'off' ? { rules: 'off' } : value;
|
|
33
|
+
if (!isRecord(def)) {
|
|
34
|
+
state.fail(`${at}: expected a ruleset, off, [${recommended}] or { extends: [${recommended}], rules: {...} }`);
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
for (const key of Object.keys(def).filter((key) => !rulesetKeys.includes(key)))
|
|
38
|
+
state.fail(`${at}: unknown key ${key}; a ruleset takes ${rulesetKeys.join(', ')}`);
|
|
39
|
+
const bases = [def.extends ?? []].flat().flatMap((base) => baseOf(state, base, `${at}.extends`, seen));
|
|
40
|
+
const own = state.parseRules(def.rules, `${at}.rules`, names);
|
|
41
|
+
return own ? [...bases, own] : bases;
|
|
42
|
+
};
|
|
43
|
+
const baseOf = (state, base, at, seen) => {
|
|
44
|
+
const local = typeof base === 'string' && state.local.has(base);
|
|
45
|
+
if (typeof base !== 'string' || !(local || Object.hasOwn(state.shared, base))) {
|
|
46
|
+
const known = [...Object.keys(state.shared), ...state.local.keys()];
|
|
47
|
+
state.fail(`${at}: '${String(base)}' is no ruleset; extend ${list(known, 'nothing')}`);
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
if (seen.includes(base)) {
|
|
51
|
+
state.fail(`${at}: ${[...seen, base].join(' extends ')}, a loop`);
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
state.extended.add(base);
|
|
55
|
+
return resolveNamed(state, base, local, seen);
|
|
56
|
+
};
|
|
57
|
+
const resolveNamed = (state, name, local, seen) => {
|
|
58
|
+
const def = local ? state.local.get(name) : state.shared[name];
|
|
59
|
+
return flatten(state, def, local ? `rulesets.${name}` : name, [...seen, name]);
|
|
60
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ArchetypeData, RefData } from '
|
|
2
|
-
import { type Fail } from '
|
|
1
|
+
import type { ArchetypeData, RefData } from '../model/data.ts';
|
|
2
|
+
import { type Fail } from '../model/shared.ts';
|
|
3
|
+
import type { ParseRuleset } from './rulesets.ts';
|
|
3
4
|
export interface PendingRef {
|
|
4
5
|
ref: RefData;
|
|
5
6
|
where: string;
|
|
@@ -13,4 +14,4 @@ export interface Structure {
|
|
|
13
14
|
pending: PendingRef[];
|
|
14
15
|
}
|
|
15
16
|
export declare const rootName = "root";
|
|
16
|
-
export declare const parseStructure: (root: unknown, archetypes: unknown, fail: Fail) => Structure;
|
|
17
|
+
export declare const parseStructure: (root: unknown, archetypes: unknown, fail: Fail, ruleset: ParseRuleset) => Structure;
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
import { isName, isRecord, list } from '
|
|
1
|
+
import { isName, isRecord, list } from '../model/shared.js';
|
|
2
2
|
export const rootName = 'root';
|
|
3
|
-
const moduleKeys = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const moduleKeys = [
|
|
4
|
+
'description',
|
|
5
|
+
'dir',
|
|
6
|
+
'files',
|
|
7
|
+
'entry',
|
|
8
|
+
'archetype',
|
|
9
|
+
'dependencies',
|
|
10
|
+
'exposes',
|
|
11
|
+
'modules',
|
|
12
|
+
'test',
|
|
13
|
+
'ruleset',
|
|
14
|
+
];
|
|
15
|
+
const archetypeKeys = ['description', 'marker', 'requires', 'entry', 'exposes', 'modules', 'test', 'ruleset'];
|
|
16
|
+
const rootKeys = ['description', 'modules', 'test', 'ruleset'];
|
|
17
|
+
const testKeys = ['requires', 'dependencies', 'provides', 'exposes', 'modules', 'ruleset'];
|
|
7
18
|
const kindOf = new Map([
|
|
8
19
|
[archetypeKeys, 'an archetype'],
|
|
9
20
|
[rootKeys, 'the root'],
|
|
10
21
|
[testKeys, 'a test block'],
|
|
11
22
|
]);
|
|
12
|
-
const testModuleKeys = ['description', 'dir', 'files', 'archetype', 'dependencies', 'exposes', 'modules'];
|
|
13
|
-
export const parseStructure = (root, archetypes, fail) => {
|
|
23
|
+
const testModuleKeys = ['description', 'dir', 'files', 'archetype', 'dependencies', 'exposes', 'modules', 'ruleset'];
|
|
24
|
+
export const parseStructure = (root, archetypes, fail, ruleset) => {
|
|
14
25
|
const defs = archetypes === undefined ? {} : isRecord(archetypes) ? archetypes : {};
|
|
15
26
|
if (archetypes !== undefined && !isRecord(archetypes))
|
|
16
27
|
fail('archetypes: expected archetypes by name');
|
|
17
|
-
const state = { defs, archetypes: {}, pending: [], fail };
|
|
28
|
+
const state = { defs, archetypes: {}, pending: [], fail, ruleset };
|
|
18
29
|
if (Object.hasOwn(defs, rootName))
|
|
19
30
|
fail(`archetypes.${rootName}: root is the repository; name the archetype otherwise`);
|
|
20
31
|
for (const [name, def] of Object.entries(defs)) {
|
|
@@ -70,6 +81,7 @@ const archetype = (state, name, def, options) => {
|
|
|
70
81
|
inputs: options.parent?.inputs ?? new Set(data.requires),
|
|
71
82
|
testInputs: options.parent?.testInputs ?? new Set(data.testRequires),
|
|
72
83
|
};
|
|
84
|
+
Object.assign(data, rulesetsAt(state, scope, where, def.ruleset, test.ruleset));
|
|
73
85
|
state.archetypes[name] = data;
|
|
74
86
|
const build = options.test ? testModule : productionModule;
|
|
75
87
|
for (const [module, raw] of Object.entries(modules))
|
|
@@ -98,6 +110,12 @@ const inlineData = (state, name, where, test) => {
|
|
|
98
110
|
state.fail(`${where}.test.requires: only an archetype requires; its modules see what it requires`);
|
|
99
111
|
return { name, inline: true, requires: [], modules: [] };
|
|
100
112
|
};
|
|
113
|
+
const rulesetsAt = (state, scope, where, ruleset, testRuleset) => {
|
|
114
|
+
const names = (entry, at) => resolveName(state, scope, entry, false, at);
|
|
115
|
+
const own = state.ruleset(ruleset, `${where}.ruleset`, names);
|
|
116
|
+
const tests = state.ruleset(testRuleset, `${where}.test.ruleset`, names);
|
|
117
|
+
return { ...(own ? { ruleset: own } : {}), ...(tests ? { testRuleset: tests } : {}) };
|
|
118
|
+
};
|
|
101
119
|
const testBlock = (state, where, value) => {
|
|
102
120
|
if (value === undefined)
|
|
103
121
|
return {};
|
|
@@ -185,6 +203,7 @@ const testFiles = (state, scope, name, def, of) => {
|
|
|
185
203
|
...(of === undefined ? {} : { of }),
|
|
186
204
|
using: references(state, scope, `${where}.dependencies`, def.dependencies, true),
|
|
187
205
|
...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
|
|
206
|
+
...rulesetsAt(state, scope, where, def.ruleset, undefined),
|
|
188
207
|
...description(state, where, def.description),
|
|
189
208
|
};
|
|
190
209
|
};
|
|
@@ -213,7 +232,7 @@ const instance = (state, scope, name, def, test) => {
|
|
|
213
232
|
state.fail(`${where}.${key}: ${named} defines what is inside; declare ${key} there`);
|
|
214
233
|
const own = bindings(state, scope, `${where}.dependencies`, def.dependencies, test);
|
|
215
234
|
const testBlock = isRecord(def.test) ? def.test : {};
|
|
216
|
-
for (const key of Object.keys(testBlock).filter((key) => key !== 'dependencies'))
|
|
235
|
+
for (const key of Object.keys(testBlock).filter((key) => key !== 'dependencies' && key !== 'ruleset'))
|
|
217
236
|
state.fail(`${where}.test.${key}: ${named} defines its test code; declare ${key} there`);
|
|
218
237
|
const tests = bindings(state, scope, `${where}.test.dependencies`, testBlock.dependencies, true);
|
|
219
238
|
return {
|
|
@@ -225,6 +244,7 @@ const instance = (state, scope, name, def, test) => {
|
|
|
225
244
|
using: Object.values(own),
|
|
226
245
|
...(Object.keys(own).length > 0 ? { inputs: own } : {}),
|
|
227
246
|
...(Object.keys(tests).length > 0 ? { testInputs: tests } : {}),
|
|
247
|
+
...rulesetsAt(state, scope, where, def.ruleset, testBlock.ruleset),
|
|
228
248
|
...description(state, where, def.description),
|
|
229
249
|
};
|
|
230
250
|
};
|
|
@@ -249,17 +269,18 @@ const filesModule = (state, scope, name, def) => {
|
|
|
249
269
|
for (const key of ['modules', 'entry'].filter((key) => def[key] !== undefined))
|
|
250
270
|
state.fail(`${where}.${key}: a files module has no modules; use dir for a folder of them`);
|
|
251
271
|
const exposed = exposes(state, scope, `${where}.exposes`, def.exposes, undefined, false, false);
|
|
272
|
+
const test = isRecord(def.test) ? def.test : {};
|
|
252
273
|
const module = {
|
|
253
274
|
kind: 'files',
|
|
254
275
|
name,
|
|
255
276
|
patterns: patterns(state, `${where}.files`, def.files),
|
|
256
277
|
using: references(state, scope, `${where}.dependencies`, def.dependencies, false),
|
|
257
278
|
...(exposed && exposed.kind !== 'surfaces' ? { exposes: exposed } : {}),
|
|
279
|
+
...rulesetsAt(state, scope, where, def.ruleset, test.ruleset),
|
|
258
280
|
...description(state, where, def.description),
|
|
259
281
|
};
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
state.fail(`${where}.test.${key}: a files module's test block holds its test modules only`);
|
|
282
|
+
for (const key of Object.keys(test).filter((key) => key !== 'modules' && key !== 'ruleset'))
|
|
283
|
+
state.fail(`${where}.test.${key}: a files module's test block holds its test modules and ruleset only`);
|
|
263
284
|
const tests = test.modules === undefined ? {} : record(state, `${where}.test.modules`, test.modules);
|
|
264
285
|
const lifted = Object.entries(tests).map(([inner, raw]) => {
|
|
265
286
|
const testDef = record(state, `${where}.test.modules.${inner}`, raw);
|