@webpieces/code-rules 0.4.952 → 0.4.953
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/package.json +6 -6
- package/src/code-rules-bootstrap.d.ts +17 -7
- package/src/code-rules-bootstrap.js +55 -78
- package/src/code-rules-bootstrap.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/rule-debug-run.d.ts +46 -0
- package/src/rule-debug-run.js +110 -0
- package/src/rule-debug-run.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/code-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.953",
|
|
4
4
|
"description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
"directory": "packages/tooling/code-rules"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/rules-config": "0.4.953",
|
|
20
20
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
25
|
-
"@webpieces/rules-sdk": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.953",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.953",
|
|
25
|
+
"@webpieces/rules-sdk": "0.4.953"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
31
|
+
"@webpieces/tooling-testkit": "0.4.953"
|
|
32
32
|
},
|
|
33
33
|
"exports": {
|
|
34
34
|
".": "./src/index.js",
|
|
@@ -13,24 +13,34 @@ import { CodeRulesRunRequest } from './code-rules-run-request';
|
|
|
13
13
|
* is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It
|
|
14
14
|
* prints the rule's own failure text, then one count per project, and fails when any site exists.
|
|
15
15
|
*
|
|
16
|
+
* A rule another rule pack contributes to the build — a repo-local rule (#1330) — is not run here: the
|
|
17
|
+
* debug request is handed to that pack's own `buildDebugRuntime`, which shares {@link RuleDebugRun} so
|
|
18
|
+
* its refusals, banner and counts are identical.
|
|
19
|
+
*
|
|
16
20
|
* A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an
|
|
17
21
|
* {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.
|
|
18
22
|
*/
|
|
19
23
|
export declare class CodeRulesBootstrap {
|
|
24
|
+
private readonly debug;
|
|
20
25
|
run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult>;
|
|
21
26
|
/** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */
|
|
22
27
|
private plan;
|
|
23
|
-
|
|
28
|
+
/** True for a rule THIS pack runs: a built-in code rule or a match-rule. */
|
|
29
|
+
private isOwnRule;
|
|
30
|
+
/**
|
|
31
|
+
* The build contribution of ANOTHER rule pack (a repo-local pack, #1330) that runs `rule`, when the
|
|
32
|
+
* rule's modes support a debug run; undefined otherwise.
|
|
33
|
+
*/
|
|
34
|
+
private packProvider;
|
|
35
|
+
private packBuildGroups;
|
|
36
|
+
private schemaModesOf;
|
|
37
|
+
/** Hand the debug request to the pack that owns the rule; it refuses, prints and counts as this runner does. */
|
|
38
|
+
private runPackDebug;
|
|
24
39
|
/** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
|
|
25
40
|
private wholeScopeModesOf;
|
|
41
|
+
/** Every rule a debug run accepts: built-in code rules, match-rules, and other packs' rules (#1330). */
|
|
26
42
|
private debuggableRules;
|
|
27
43
|
private committedModeOf;
|
|
28
|
-
private projectNames;
|
|
29
44
|
/** The match-rules, with the debugged one (if it is a match rule) overridden. */
|
|
30
45
|
private matchRules;
|
|
31
|
-
/** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
|
|
32
|
-
private overridden;
|
|
33
|
-
private printBanner;
|
|
34
|
-
/** Print one count per project and return the total. */
|
|
35
|
-
private printCounts;
|
|
36
46
|
}
|
|
@@ -12,19 +12,8 @@ const code_rules_context_1 = require("./code-rules-context");
|
|
|
12
12
|
const code_policy_registry_1 = require("./code-policy-registry");
|
|
13
13
|
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
14
14
|
const scan_scope_1 = require("./scan-scope");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
rule;
|
|
18
|
-
mode;
|
|
19
|
-
committedMode;
|
|
20
|
-
projects;
|
|
21
|
-
constructor(rule, mode, committedMode, projects) {
|
|
22
|
-
this.rule = rule;
|
|
23
|
-
this.mode = mode;
|
|
24
|
-
this.committedMode = committedMode;
|
|
25
|
-
this.projects = projects;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
15
|
+
const rule_debug_run_1 = require("./rule-debug-run");
|
|
16
|
+
const rule_pack_1 = require("./rule-pack");
|
|
28
17
|
/**
|
|
29
18
|
* The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the
|
|
30
19
|
* `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,
|
|
@@ -37,23 +26,33 @@ class DebugPlan {
|
|
|
37
26
|
* is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It
|
|
38
27
|
* prints the rule's own failure text, then one count per project, and fails when any site exists.
|
|
39
28
|
*
|
|
29
|
+
* A rule another rule pack contributes to the build — a repo-local rule (#1330) — is not run here: the
|
|
30
|
+
* debug request is handed to that pack's own `buildDebugRuntime`, which shares {@link RuleDebugRun} so
|
|
31
|
+
* its refusals, banner and counts are identical.
|
|
32
|
+
*
|
|
40
33
|
* A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an
|
|
41
34
|
* {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.
|
|
42
35
|
*/
|
|
43
36
|
class CodeRulesBootstrap {
|
|
37
|
+
debug = new rule_debug_run_1.RuleDebugRun();
|
|
44
38
|
async run(workspaceRoot, request) {
|
|
45
39
|
const loaded = (0, rules_config_1.loadAndValidate)(workspaceRoot);
|
|
46
40
|
if (loaded.configPath === null) {
|
|
47
41
|
throw new tooling_common_1.InformAiError('No webpieces.config.json found at workspace root (or any ancestor).');
|
|
48
42
|
}
|
|
49
43
|
console.log(`\n📄 Loaded config: ${loaded.configPath}`);
|
|
44
|
+
const provider = request.rule === undefined || this.isOwnRule(request.rule, loaded)
|
|
45
|
+
? undefined
|
|
46
|
+
: this.packProvider(request.rule, loaded);
|
|
47
|
+
if (provider !== undefined)
|
|
48
|
+
return this.runPackDebug(workspaceRoot, loaded, provider, request);
|
|
50
49
|
const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;
|
|
51
50
|
if (plan !== undefined)
|
|
52
|
-
this.printBanner(plan);
|
|
51
|
+
this.debug.printBanner(plan);
|
|
53
52
|
const configs = {};
|
|
54
53
|
for (const policy of code_policy_registry_1.CODE_POLICIES) {
|
|
55
54
|
const config = loaded.rulesConfig[policy.ruleId];
|
|
56
|
-
configs[policy.ruleId] = (plan?.rule === policy.ruleId ? this.overridden(config, plan) : config);
|
|
55
|
+
configs[policy.ruleId] = (plan?.rule === policy.ruleId ? this.debug.overridden(config, plan) : config);
|
|
57
56
|
}
|
|
58
57
|
const runtimeRequest = new rules_sdk_1.PolicyRuntimeRequest(workspaceRoot, configs, code_policy_registry_1.CODE_POLICIES.map((policy) => policy.ruleId), loaded.excludePaths.paths);
|
|
59
58
|
const container = await new code_policy_composition_1.CodeRuleRuntime().compose(runtimeRequest, plan?.projects);
|
|
@@ -66,53 +65,67 @@ class CodeRulesBootstrap {
|
|
|
66
65
|
return result;
|
|
67
66
|
// A debug run FAILS whenever a site exists — including a rule that only warns at the gate
|
|
68
67
|
// (no-client-creation-outside-server-or-client at severity "warn") — so it can gate a loop.
|
|
69
|
-
const sites = this.printCounts(workspaceRoot, plan, container.get(scan_scope_1.ScanScope), result);
|
|
68
|
+
const sites = this.debug.printCounts(workspaceRoot, plan, container.get(scan_scope_1.ScanScope), result.success);
|
|
70
69
|
return { success: result.success && sites === 0 };
|
|
71
70
|
}
|
|
72
71
|
/** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */
|
|
73
72
|
plan(workspaceRoot, loaded, request) {
|
|
74
73
|
const rule = request.rule;
|
|
75
74
|
if (rule === undefined)
|
|
76
|
-
throw this.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');
|
|
75
|
+
throw this.debug.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');
|
|
77
76
|
const modes = this.wholeScopeModesOf(rule, loaded);
|
|
78
77
|
if (modes === undefined) {
|
|
79
|
-
throw this.refusal(`--rule=${rule} is not a
|
|
78
|
+
throw this.debug.refusal(`--rule=${rule} is not a rule that supports a debug run. Rules that do (they offer ` +
|
|
80
79
|
`MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`);
|
|
81
80
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return new DebugPlan(rule, mode, committedMode, request.projects);
|
|
81
|
+
return this.debug.plan(workspaceRoot, new rule_debug_run_1.DebugAsk(rule, request.mode, this.committedModeOf(rule, loaded) ?? 'OFF', modes, request.projects));
|
|
82
|
+
}
|
|
83
|
+
/** True for a rule THIS pack runs: a built-in code rule or a match-rule. */
|
|
84
|
+
isOwnRule(rule, loaded) {
|
|
85
|
+
return (code_policy_registry_1.CODE_POLICIES.some((binding) => binding.ruleId === rule) ||
|
|
86
|
+
loaded.matchRules.some((mr) => mr.name === rule));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The build contribution of ANOTHER rule pack (a repo-local pack, #1330) that runs `rule`, when the
|
|
90
|
+
* rule's modes support a debug run; undefined otherwise.
|
|
91
|
+
*/
|
|
92
|
+
packProvider(rule, loaded) {
|
|
93
|
+
return this.packBuildGroups(loaded).find((group) => group.ruleIds.includes(rule) && this.debug.supports(this.schemaModesOf(rule, loaded)));
|
|
96
94
|
}
|
|
97
|
-
|
|
98
|
-
return new
|
|
95
|
+
packBuildGroups(loaded) {
|
|
96
|
+
return new rules_config_1.RuleRuntimeModules()
|
|
97
|
+
.groups(loaded.ruleRegistry, 'build')
|
|
98
|
+
.filter((group) => group.providerPack !== rule_pack_1.rulePackManifest.packageName);
|
|
99
|
+
}
|
|
100
|
+
schemaModesOf(rule, loaded) {
|
|
101
|
+
return loaded.ruleRegistry.schemaFor(rule)['mode']?.enumValues ?? [];
|
|
102
|
+
}
|
|
103
|
+
/** Hand the debug request to the pack that owns the rule; it refuses, prints and counts as this runner does. */
|
|
104
|
+
async runPackDebug(workspaceRoot, loaded, group, request) {
|
|
105
|
+
const modules = new rules_config_1.RuleRuntimeModules();
|
|
106
|
+
const exports = modules.load(group, loaded.ruleRegistry.manifestModules, new rules_config_1.NodeRuleRuntimeModuleLoader(workspaceRoot));
|
|
107
|
+
const result = await modules.runBuildDebug(exports, new rules_sdk_1.BuildDebugRequest(workspaceRoot, new rules_sdk_1.PolicyDebugSelection(request.rule, request.mode, request.projects)));
|
|
108
|
+
return { success: result.success };
|
|
99
109
|
}
|
|
100
110
|
/** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
|
|
101
111
|
wholeScopeModesOf(rule, loaded) {
|
|
102
112
|
if (loaded.matchRules.some((mr) => mr.name === rule))
|
|
103
113
|
return rules_sdk_2.MODIFIED_CODE_MODES;
|
|
104
|
-
|
|
114
|
+
const binding = code_policy_registry_1.CODE_POLICIES.find((each) => each.ruleId === rule);
|
|
115
|
+
if (binding === undefined)
|
|
105
116
|
return undefined;
|
|
106
|
-
const modes =
|
|
107
|
-
|
|
108
|
-
return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME')
|
|
109
|
-
? modes
|
|
110
|
-
: undefined;
|
|
117
|
+
const modes = binding.schema['mode']?.enumValues ?? [];
|
|
118
|
+
return this.debug.supports(modes) ? modes : undefined;
|
|
111
119
|
}
|
|
120
|
+
/** Every rule a debug run accepts: built-in code rules, match-rules, and other packs' rules (#1330). */
|
|
112
121
|
debuggableRules(loaded) {
|
|
113
122
|
const builtIns = code_policy_registry_1.CODE_POLICIES.map((binding) => binding.ruleId);
|
|
114
123
|
const names = [...builtIns, ...loaded.matchRules.map((mr) => mr.name)];
|
|
115
|
-
|
|
124
|
+
const own = names.filter((name) => this.wholeScopeModesOf(name, loaded) !== undefined);
|
|
125
|
+
const packs = this.packBuildGroups(loaded)
|
|
126
|
+
.flatMap((group) => [...group.ruleIds])
|
|
127
|
+
.filter((name) => this.packProvider(name, loaded) !== undefined);
|
|
128
|
+
return [...own, ...packs];
|
|
116
129
|
}
|
|
117
130
|
committedModeOf(rule, loaded) {
|
|
118
131
|
const match = loaded.matchRules.find((mr) => mr.name === rule);
|
|
@@ -121,45 +134,9 @@ class CodeRulesBootstrap {
|
|
|
121
134
|
const configured = loaded.rulesConfig[rule];
|
|
122
135
|
return configured?.mode;
|
|
123
136
|
}
|
|
124
|
-
projectNames(workspaceRoot) {
|
|
125
|
-
return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope())
|
|
126
|
-
.all(workspaceRoot)
|
|
127
|
-
.map((p) => p.name)
|
|
128
|
-
.sort();
|
|
129
|
-
}
|
|
130
137
|
/** The match-rules, with the debugged one (if it is a match rule) overridden. */
|
|
131
138
|
matchRules(loaded, plan) {
|
|
132
|
-
return loaded.matchRules.map((mr) => plan?.rule === mr.name ? this.overridden(mr, plan) : mr);
|
|
133
|
-
}
|
|
134
|
-
/** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
|
|
135
|
-
overridden(config, plan) {
|
|
136
|
-
const copy = Object.assign(Object.create(Object.getPrototypeOf(config)), config);
|
|
137
|
-
copy.mode = plan.mode;
|
|
138
|
-
copy.turnOffRuleUntilEpoch = 0;
|
|
139
|
-
copy.turnOffRuleWhileOnBranch = null;
|
|
140
|
-
return copy;
|
|
141
|
-
}
|
|
142
|
-
printBanner(plan) {
|
|
143
|
-
console.log('');
|
|
144
|
-
console.log(`🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`);
|
|
145
|
-
console.log(` Mode: ${plan.mode} (committed: ${plan.committedMode})` +
|
|
146
|
-
` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +
|
|
147
|
-
' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run');
|
|
148
|
-
}
|
|
149
|
-
/** Print one count per project and return the total. */
|
|
150
|
-
printCounts(workspaceRoot, plan, scan, result) {
|
|
151
|
-
const counts = scan.countsByProject(workspaceRoot);
|
|
152
|
-
const names = plan.projects ?? Array.from(counts.keys()).sort();
|
|
153
|
-
const total = Array.from(counts.values()).reduce((sum, n) => sum + n, 0);
|
|
154
|
-
console.log('');
|
|
155
|
-
console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);
|
|
156
|
-
for (const name of names)
|
|
157
|
-
console.log(` ${name}: ${counts.get(name) ?? 0}`);
|
|
158
|
-
if (!result.success && total === 0) {
|
|
159
|
-
console.log(' (the rule failed without reporting sites — read its output above)');
|
|
160
|
-
}
|
|
161
|
-
console.log('');
|
|
162
|
-
return total;
|
|
139
|
+
return loaded.matchRules.map((mr) => plan?.rule === mr.name ? this.debug.overridden(mr, plan) : mr);
|
|
163
140
|
}
|
|
164
141
|
}
|
|
165
142
|
exports.CodeRulesBootstrap = CodeRulesBootstrap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAA0F;AAC1F,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAAoG;AACpG,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAM,SAAS;IAEE;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,kBAAkB;IAC3B,KAAK,CAAC,GAAG,CAAC,aAAqB,EAAE,OAA4B;QACzD,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,8BAAa,CACnB,qEAAqE,CACxE,CAAC;QACN,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvF,IAAI,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAE/C,MAAM,OAAO,GAAiC,EAAE,CAAC;QACjD,KAAK,MAAM,MAAM,IAAI,oCAAa,E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C,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC;QACtE,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA1KD,gDA0KC","sourcesContent":["import { BaseRuleConfig, ConfigObject, PolicyRuntimeRequest } from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport { DiffScope, LoadedConfig, MatchRuleConfig, loadAndValidate } from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nclass DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n loaded.excludePaths.paths,\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = this.printCounts(workspaceRoot, plan, container.get(ScanScope), result);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): DebugPlan {\n const rule = request.rule;\n if (rule === undefined)\n throw this.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.refusal(\n `--rule=${rule} is not a code rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';\n const mode = request.mode ?? committedMode;\n if (!modes.includes(mode) || mode === 'OFF') {\n const why =\n request.mode === undefined\n ? `its committed mode is ${committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const unknown = (request.projects ?? []).filter(\n (name: string) => !this.projectNames(workspaceRoot).includes(name),\n );\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +\n `${this.projectNames(workspaceRoot).join(', ')}.`,\n );\n }\n return new DebugPlan(rule, mode, committedMode, request.projects);\n }\n\n private refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n if (!CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule)) return undefined;\n const modes =\n CODE_POLICIES.find((binding: CodePolicy) => binding.ruleId === rule)?.schema['mode']\n ?.enumValues ?? [];\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME')\n ? modes\n : undefined;\n }\n\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n return names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope())\n .all(workspaceRoot)\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.overridden(mr, plan) : mr,\n );\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n private overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n private printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project and return the total. */\n private printCounts(\n workspaceRoot: string,\n plan: DebugPlan,\n scan: ScanScope,\n result: ExecutorResult,\n ): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!result.success && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAM8B;AAC9B,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAOiC;AACjC,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAyC;AACzC,qDAAqE;AACrE,2CAA+C;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,kBAAkB;IACV,KAAK,GAAG,IAAI,6BAAY,EAAE,CAAC;IAE5C,KAAK,CAAC,GAAG,CAAC,aAAqB,EAAE,OAA4B;QACzD,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,8BAAa,CACnB,qEAAqE,CACxE,CAAC;QACN,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,MAAM,QAAQ,GACV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AmB,EAAE,EAAE,CACjD,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;IACN,CAAC;CACJ;AAhKD,gDAgKC","sourcesContent":["import {\n BaseRuleConfig,\n BuildDebugRequest,\n ConfigObject,\n PolicyDebugSelection,\n PolicyRuntimeRequest,\n} from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport {\n LoadedConfig,\n MatchRuleConfig,\n NodeRuleRuntimeModuleLoader,\n RuleRuntimeModules,\n RuntimeContributionGroup,\n loadAndValidate,\n} from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ScanScope } from './scan-scope';\nimport { DebugAsk, DebugPlan, RuleDebugRun } from './rule-debug-run';\nimport { rulePackManifest } from './rule-pack';\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A rule another rule pack contributes to the build — a repo-local rule (#1330) — is not run here: the\n * debug request is handed to that pack's own `buildDebugRuntime`, which shares {@link RuleDebugRun} so\n * its refusals, banner and counts are identical.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n private readonly debug = new RuleDebugRun();\n\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const provider =\n request.rule === undefined || this.isOwnRule(request.rule, loaded)\n ? undefined\n : this.packProvider(request.rule, loaded);\n if (provider !== undefined) return this.runPackDebug(workspaceRoot, loaded, provider, request);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.debug.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.debug.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n loaded.excludePaths.paths,\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = this.debug.printCounts(workspaceRoot, plan, container.get(ScanScope), result.success);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): DebugPlan {\n const rule = request.rule;\n if (rule === undefined)\n throw this.debug.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.debug.refusal(\n `--rule=${rule} is not a rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n return this.debug.plan(\n workspaceRoot,\n new DebugAsk(rule, request.mode, this.committedModeOf(rule, loaded) ?? 'OFF', modes, request.projects),\n );\n }\n\n /** True for a rule THIS pack runs: a built-in code rule or a match-rule. */\n private isOwnRule(rule: string, loaded: LoadedConfig): boolean {\n return (\n CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule) ||\n loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule)\n );\n }\n\n /**\n * The build contribution of ANOTHER rule pack (a repo-local pack, #1330) that runs `rule`, when the\n * rule's modes support a debug run; undefined otherwise.\n */\n private packProvider(rule: string, loaded: LoadedConfig): RuntimeContributionGroup | undefined {\n return this.packBuildGroups(loaded).find(\n (group: RuntimeContributionGroup) =>\n group.ruleIds.includes(rule) && this.debug.supports(this.schemaModesOf(rule, loaded)),\n );\n }\n\n private packBuildGroups(loaded: LoadedConfig): readonly RuntimeContributionGroup[] {\n return new RuleRuntimeModules()\n .groups(loaded.ruleRegistry, 'build')\n .filter((group: RuntimeContributionGroup) => group.providerPack !== rulePackManifest.packageName);\n }\n\n private schemaModesOf(rule: string, loaded: LoadedConfig): readonly string[] {\n return loaded.ruleRegistry.schemaFor(rule)['mode']?.enumValues ?? [];\n }\n\n /** Hand the debug request to the pack that owns the rule; it refuses, prints and counts as this runner does. */\n private async runPackDebug(\n workspaceRoot: string,\n loaded: LoadedConfig,\n group: RuntimeContributionGroup,\n request: CodeRulesRunRequest,\n ): Promise<ExecutorResult> {\n const modules = new RuleRuntimeModules();\n const exports = modules.load(\n group,\n loaded.ruleRegistry.manifestModules,\n new NodeRuleRuntimeModuleLoader(workspaceRoot),\n );\n const result = await modules.runBuildDebug(\n exports,\n new BuildDebugRequest(\n workspaceRoot,\n new PolicyDebugSelection(request.rule!, request.mode, request.projects),\n ),\n );\n return { success: result.success };\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n const binding = CODE_POLICIES.find((each: CodePolicy) => each.ruleId === rule);\n if (binding === undefined) return undefined;\n const modes = binding.schema['mode']?.enumValues ?? [];\n return this.debug.supports(modes) ? modes : undefined;\n }\n\n /** Every rule a debug run accepts: built-in code rules, match-rules, and other packs' rules (#1330). */\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n const own = names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n const packs = this.packBuildGroups(loaded)\n .flatMap((group: RuntimeContributionGroup) => [...group.ruleIds])\n .filter((name: string) => this.packProvider(name, loaded) !== undefined);\n return [...own, ...packs];\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.debug.overridden(mr, plan) : mr,\n );\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export { default as validateCode } from './validate-code';
|
|
|
36
36
|
export { CodeRulesBootstrap } from './code-rules-bootstrap';
|
|
37
37
|
export { CodeRulesRunRequest, RuleSelection, RunRequestParser } from './code-rules-run-request';
|
|
38
38
|
export { ScanScope, GateScanScope, ScanRestriction, ProjectCatalog, ProjectEntry, RecordedSite } from './scan-scope';
|
|
39
|
+
export { RuleDebugRun, DebugAsk, DebugPlan } from './rule-debug-run';
|
|
39
40
|
export { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';
|
|
40
41
|
export { ReactNativeCompatibility } from './react-native-compatibility';
|
|
41
42
|
export { METHOD_LIMIT_MODES, RETURN_TYPE_MODES, INLINE_TYPE_MODES, PROJECT_MODES, PRISMA_DTOS_MODES, PRISMA_CONVERTER_MODES, DIRECT_API_RESOLVER_MODES, MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, NoUnmanagedExceptionsConfig, CatchErrorPatternConfig, AngularNoDirectApiInResolverConfig, NoCustomCssConfig, NoSymbolDiTokensConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig } from './configs/rule-configs';
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.frameworkTsconfigError = exports.TsconfigRuntimeViolation = exports.RuntimeCompilerOptions = exports.FrameworkTsconfigAudit = exports.FrameworkTsconfigValidator = exports.ScannedProject = exports.ProjectScanTargets = exports.ApiLibEnumIndex = exports.GoverningGlob = exports.SuffixRename = exports.SuffixEntryPicker = exports.ExportedTypeScanner = exports.RequiredTypeSuffixValidator = exports.UtilityTypeScanner = exports.NoUtilityTypesInApiLibValidator = exports.EnumSpellingScanner = exports.OneEnumSpellingInApiLibValidator = exports.InlineImportScanner = exports.NoInlineImportInApiLibValidator = exports.ApiLibSite = exports.ApiLibFile = exports.findDirectlyChangedProjectRoots = exports.auditSecurityContracts = exports.SecurityContractViolation = exports.EnsureWeAreSecureValidator = exports.RoleTagValidator = exports.FrameworkTagValidator = exports.findRedundantInjectInSource = exports.InjectAnnotationNotNeededForConcreteClassValidator = exports.NoFunctionOutsideClassValidator = exports.NoProcessExitOutsideMainValidator = exports.ProjectRoleResolver = exports.StatePathViolation = exports.StatePathHit = exports.NoStatePathsInTemplatesValidator = exports.NoClientCreationOutsideServerOrClientValidator = exports.NoSymbolDiTokensValidator = exports.NoDirectApiResolverValidator = exports.NoDestructureValidator = exports.NoUnmanagedExceptionsValidator = exports.CatchErrorPatternValidator = exports.NoInlineTypeLiteralsValidator = exports.RequireReturnTypeValidator = exports.MaxFileLinesValidator = exports.runNewMethods = exports.runModifiedMethods = exports.MaxMethodLinesValidator = exports.NoImplicitAnyValidator = exports.NoAnyUnknownValidator = exports.CodeValidator = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.FrameworkPackagesConfig = exports.FrameworkPackagesEntry = exports.FrameworkTsconfigConfig = exports.PROJECT_SCAN_MODES = exports.LocatedCatchFinding = exports.CatchMustPropagateValidator = exports.CatchMustPropagateConfig = exports.RequiredTypeSuffixConfig = exports.RequiredTypeSuffixEntry = exports.NoUtilityTypesInApiLibConfig = exports.OneEnumSpellingInApiLibConfig = exports.NoInlineImportInApiLibConfig = exports.NoStatePathsInTemplatesConfig = exports.DEFAULT_BANNED_STATE_PATH_PREFIXES = exports.DEFAULT_TEMPLATE_DIRS = exports.NoClientCreationOutsideServerOrClientConfig = void 0;
|
|
4
|
+
exports.FrameworkTagConfig = exports.InjectAnnotationNotNeededForConcreteClassConfig = exports.NoFunctionOutsideClassConfig = exports.NoProcessExitOutsideMainConfig = exports.NoSymbolDiTokensConfig = exports.NoCustomCssConfig = exports.AngularNoDirectApiInResolverConfig = exports.CatchErrorPatternConfig = exports.NoUnmanagedExceptionsConfig = exports.NoDestructureConfig = exports.PrismaConverterConfig = exports.PrismaValidateDtosConfig = exports.NoImplicitAnyConfig = exports.NoAnyUnknownConfig = exports.NoInlineTypeLiteralsConfig = exports.RequireReturnTypeConfig = exports.MaxFileLinesConfig = exports.MaxMethodLinesConfig = exports.DIRECT_API_RESOLVER_MODES = exports.PRISMA_CONVERTER_MODES = exports.PRISMA_DTOS_MODES = exports.PROJECT_MODES = exports.INLINE_TYPE_MODES = exports.RETURN_TYPE_MODES = exports.METHOD_LIMIT_MODES = exports.ReactNativeCompatibility = exports.RuleExclusionsFactory = exports.GlobalExcludePaths = exports.ExclusionScopedPolicy = exports.DebugPlan = exports.DebugAsk = exports.RuleDebugRun = exports.RecordedSite = exports.ProjectEntry = exports.ProjectCatalog = exports.ScanRestriction = exports.GateScanScope = exports.ScanScope = exports.RunRequestParser = exports.RuleSelection = exports.CodeRulesRunRequest = exports.CodeRulesBootstrap = exports.validateCode = exports.PrismaConverterValidator = exports.PrismaValidateDtosValidator = exports.EnumText = exports.frameworkPackagesError = exports.FrameworkPackageViolation = exports.FrameworkPackagesAudit = exports.FrameworkPackagesValidator = void 0;
|
|
5
|
+
exports.FrameworkPackagesConfig = exports.FrameworkPackagesEntry = exports.FrameworkTsconfigConfig = exports.PROJECT_SCAN_MODES = exports.LocatedCatchFinding = exports.CatchMustPropagateValidator = exports.CatchMustPropagateConfig = exports.RequiredTypeSuffixConfig = exports.RequiredTypeSuffixEntry = exports.NoUtilityTypesInApiLibConfig = exports.OneEnumSpellingInApiLibConfig = exports.NoInlineImportInApiLibConfig = exports.NoStatePathsInTemplatesConfig = exports.DEFAULT_BANNED_STATE_PATH_PREFIXES = exports.DEFAULT_TEMPLATE_DIRS = exports.NoClientCreationOutsideServerOrClientConfig = exports.CLIENT_CREATION_SEVERITIES = exports.EnsureWeAreSecureConfig = exports.RoleTagConfig = void 0;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
var code_validator_1 = require("./code-validator");
|
|
8
8
|
Object.defineProperty(exports, "CodeValidator", { enumerable: true, get: function () { return code_validator_1.CodeValidator; } });
|
|
@@ -110,6 +110,10 @@ Object.defineProperty(exports, "ScanRestriction", { enumerable: true, get: funct
|
|
|
110
110
|
Object.defineProperty(exports, "ProjectCatalog", { enumerable: true, get: function () { return scan_scope_1.ProjectCatalog; } });
|
|
111
111
|
Object.defineProperty(exports, "ProjectEntry", { enumerable: true, get: function () { return scan_scope_1.ProjectEntry; } });
|
|
112
112
|
Object.defineProperty(exports, "RecordedSite", { enumerable: true, get: function () { return scan_scope_1.RecordedSite; } });
|
|
113
|
+
var rule_debug_run_1 = require("./rule-debug-run");
|
|
114
|
+
Object.defineProperty(exports, "RuleDebugRun", { enumerable: true, get: function () { return rule_debug_run_1.RuleDebugRun; } });
|
|
115
|
+
Object.defineProperty(exports, "DebugAsk", { enumerable: true, get: function () { return rule_debug_run_1.DebugAsk; } });
|
|
116
|
+
Object.defineProperty(exports, "DebugPlan", { enumerable: true, get: function () { return rule_debug_run_1.DebugPlan; } });
|
|
113
117
|
// Where code-rules applies the framework-owned path exclusions to every rule it composes (#1253).
|
|
114
118
|
var rule_dispatch_1 = require("./rule-dispatch");
|
|
115
119
|
Object.defineProperty(exports, "ExclusionScopedPolicy", { enumerable: true, get: function () { return rule_dispatch_1.ExclusionScopedPolicy; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAiE;AAAxD,+GAAA,aAAa,OAAA;AAEtB,qE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iF;AAAxE,uIAAA,wBAAwB,OAAA;AACjC,iFAAmG;AAA1F,4IAAA,2BAA2B,OAAA;AAAE,oIAAA,mBAAmB,OAAA;AACzD,iEAA2I;AAAlI,uHAAA,kBAAkB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAAE,4HAAA,uBAAuB,OAAA","sourcesContent":["export { CodeValidator, ExecutorResult } from './code-validator';\n\nexport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nexport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nexport { MaxMethodLinesValidator, runModifiedMethods } from './validate-modified-methods';\nexport { runNewMethods } from './validate-new-methods';\nexport { MaxFileLinesValidator } from './validate-modified-files';\nexport { RequireReturnTypeValidator } from './validate-return-types';\nexport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nexport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nexport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nexport { NoDestructureValidator } from './validate-no-destructure';\nexport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nexport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nexport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nexport {\n NoStatePathsInTemplatesValidator,\n StatePathHit,\n StatePathViolation,\n} from './validate-no-state-paths-in-templates';\nexport { ProjectRoleResolver } from './project-role-resolver';\nexport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nexport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nexport {\n InjectAnnotationNotNeededForConcreteClassValidator,\n findRedundantInjectInSource,\n} from './validate-inject-annotation-not-needed-for-concrete-class';\nexport { FrameworkTagValidator } from './validate-framework-tag';\nexport { RoleTagValidator } from './validate-role-tag';\nexport {\n EnsureWeAreSecureValidator,\n SecurityContractViolation,\n auditSecurityContracts,\n findDirectlyChangedProjectRoots,\n} from './validate-ensure-we-are-secure';\nexport { ApiLibFile, ApiLibSite } from './api-lib-source-rule';\nexport { NoInlineImportInApiLibValidator, InlineImportScanner } from './validate-no-inline-import-in-api-lib';\nexport { OneEnumSpellingInApiLibValidator, EnumSpellingScanner } from './validate-one-enum-spelling-in-api-lib';\nexport { NoUtilityTypesInApiLibValidator, UtilityTypeScanner } from './validate-no-utility-types-in-api-lib';\nexport {\n RequiredTypeSuffixValidator,\n ExportedTypeScanner,\n SuffixEntryPicker,\n SuffixRename,\n GoverningGlob,\n} from './validate-required-type-suffix';\nexport { ApiLibEnumIndex } from './api-lib-enum-index';\nexport { ProjectScanTargets, ScannedProject } from './project-scan-targets';\nexport {\n FrameworkTsconfigValidator,\n FrameworkTsconfigAudit,\n RuntimeCompilerOptions,\n TsconfigRuntimeViolation,\n frameworkTsconfigError,\n} from './validate-framework-tsconfig';\nexport {\n FrameworkPackagesValidator,\n FrameworkPackagesAudit,\n FrameworkPackageViolation,\n frameworkPackagesError,\n} from './validate-framework-packages';\nexport { EnumText } from './api-lib-enum-text';\nexport { PrismaValidateDtosValidator } from './validate-dtos';\nexport { PrismaConverterValidator } from './validate-prisma-converters';\nexport { default as validateCode } from './validate-code';\nexport { CodeRulesBootstrap } from './code-rules-bootstrap';\nexport { CodeRulesRunRequest, RuleSelection, RunRequestParser } from './code-rules-run-request';\nexport { ScanScope, GateScanScope, ScanRestriction, ProjectCatalog, ProjectEntry, RecordedSite } from './scan-scope';\n// Where code-rules applies the framework-owned path exclusions to every rule it composes (#1253).\nexport { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';\n\nexport { ReactNativeCompatibility } from './react-native-compatibility';\n\nexport { METHOD_LIMIT_MODES, RETURN_TYPE_MODES, INLINE_TYPE_MODES, PROJECT_MODES, PRISMA_DTOS_MODES, PRISMA_CONVERTER_MODES, DIRECT_API_RESOLVER_MODES, MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, NoUnmanagedExceptionsConfig, CatchErrorPatternConfig, AngularNoDirectApiInResolverConfig, NoCustomCssConfig, NoSymbolDiTokensConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig } from './configs/rule-configs';\nexport type { MethodLimitMode, ReturnTypeMode, InlineTypeMode, ProjectMode, PrismaValidateDtosMode, PrismaConverterMode, DirectApiResolverMode } from './configs/rule-configs';\nexport { CLIENT_CREATION_SEVERITIES, NoClientCreationOutsideServerOrClientConfig } from './configs/no-client-creation-config';\nexport type { ClientCreationSeverity } from './configs/no-client-creation-config';\nexport { DEFAULT_TEMPLATE_DIRS, DEFAULT_BANNED_STATE_PATH_PREFIXES, NoStatePathsInTemplatesConfig } from './configs/no-state-paths-config';\nexport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from './configs/api-lib-spelling-configs';\nexport { NoUtilityTypesInApiLibConfig } from './configs/no-utility-types-config';\nexport { RequiredTypeSuffixEntry, RequiredTypeSuffixConfig } from './configs/required-type-suffix-config';\nexport { CatchMustPropagateConfig } from './configs/catch-must-propagate-config';\nexport { CatchMustPropagateValidator, LocatedCatchFinding } from './validate-catch-must-propagate';\nexport { PROJECT_SCAN_MODES, FrameworkTsconfigConfig, FrameworkPackagesEntry, FrameworkPackagesConfig } from './configs/tag-truth-configs';\nexport type { ProjectScanMode } from './configs/tag-truth-configs';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAiE;AAAxD,+GAAA,aAAa,OAAA;AAEtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,yEAA0F;AAAjF,oIA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IAAA,wBAAwB,OAAA;AACjC,iFAAmG;AAA1F,4IAAA,2BAA2B,OAAA;AAAE,oIAAA,mBAAmB,OAAA;AACzD,iEAA2I;AAAlI,uHAAA,kBAAkB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAAE,2HAAA,sBAAsB,OAAA;AAAE,4HAAA,uBAAuB,OAAA","sourcesContent":["export { CodeValidator, ExecutorResult } from './code-validator';\n\nexport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nexport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nexport { MaxMethodLinesValidator, runModifiedMethods } from './validate-modified-methods';\nexport { runNewMethods } from './validate-new-methods';\nexport { MaxFileLinesValidator } from './validate-modified-files';\nexport { RequireReturnTypeValidator } from './validate-return-types';\nexport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nexport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nexport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nexport { NoDestructureValidator } from './validate-no-destructure';\nexport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nexport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nexport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nexport {\n NoStatePathsInTemplatesValidator,\n StatePathHit,\n StatePathViolation,\n} from './validate-no-state-paths-in-templates';\nexport { ProjectRoleResolver } from './project-role-resolver';\nexport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nexport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nexport {\n InjectAnnotationNotNeededForConcreteClassValidator,\n findRedundantInjectInSource,\n} from './validate-inject-annotation-not-needed-for-concrete-class';\nexport { FrameworkTagValidator } from './validate-framework-tag';\nexport { RoleTagValidator } from './validate-role-tag';\nexport {\n EnsureWeAreSecureValidator,\n SecurityContractViolation,\n auditSecurityContracts,\n findDirectlyChangedProjectRoots,\n} from './validate-ensure-we-are-secure';\nexport { ApiLibFile, ApiLibSite } from './api-lib-source-rule';\nexport { NoInlineImportInApiLibValidator, InlineImportScanner } from './validate-no-inline-import-in-api-lib';\nexport { OneEnumSpellingInApiLibValidator, EnumSpellingScanner } from './validate-one-enum-spelling-in-api-lib';\nexport { NoUtilityTypesInApiLibValidator, UtilityTypeScanner } from './validate-no-utility-types-in-api-lib';\nexport {\n RequiredTypeSuffixValidator,\n ExportedTypeScanner,\n SuffixEntryPicker,\n SuffixRename,\n GoverningGlob,\n} from './validate-required-type-suffix';\nexport { ApiLibEnumIndex } from './api-lib-enum-index';\nexport { ProjectScanTargets, ScannedProject } from './project-scan-targets';\nexport {\n FrameworkTsconfigValidator,\n FrameworkTsconfigAudit,\n RuntimeCompilerOptions,\n TsconfigRuntimeViolation,\n frameworkTsconfigError,\n} from './validate-framework-tsconfig';\nexport {\n FrameworkPackagesValidator,\n FrameworkPackagesAudit,\n FrameworkPackageViolation,\n frameworkPackagesError,\n} from './validate-framework-packages';\nexport { EnumText } from './api-lib-enum-text';\nexport { PrismaValidateDtosValidator } from './validate-dtos';\nexport { PrismaConverterValidator } from './validate-prisma-converters';\nexport { default as validateCode } from './validate-code';\nexport { CodeRulesBootstrap } from './code-rules-bootstrap';\nexport { CodeRulesRunRequest, RuleSelection, RunRequestParser } from './code-rules-run-request';\nexport { ScanScope, GateScanScope, ScanRestriction, ProjectCatalog, ProjectEntry, RecordedSite } from './scan-scope';\nexport { RuleDebugRun, DebugAsk, DebugPlan } from './rule-debug-run';\n// Where code-rules applies the framework-owned path exclusions to every rule it composes (#1253).\nexport { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';\n\nexport { ReactNativeCompatibility } from './react-native-compatibility';\n\nexport { METHOD_LIMIT_MODES, RETURN_TYPE_MODES, INLINE_TYPE_MODES, PROJECT_MODES, PRISMA_DTOS_MODES, PRISMA_CONVERTER_MODES, DIRECT_API_RESOLVER_MODES, MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, NoUnmanagedExceptionsConfig, CatchErrorPatternConfig, AngularNoDirectApiInResolverConfig, NoCustomCssConfig, NoSymbolDiTokensConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig } from './configs/rule-configs';\nexport type { MethodLimitMode, ReturnTypeMode, InlineTypeMode, ProjectMode, PrismaValidateDtosMode, PrismaConverterMode, DirectApiResolverMode } from './configs/rule-configs';\nexport { CLIENT_CREATION_SEVERITIES, NoClientCreationOutsideServerOrClientConfig } from './configs/no-client-creation-config';\nexport type { ClientCreationSeverity } from './configs/no-client-creation-config';\nexport { DEFAULT_TEMPLATE_DIRS, DEFAULT_BANNED_STATE_PATH_PREFIXES, NoStatePathsInTemplatesConfig } from './configs/no-state-paths-config';\nexport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from './configs/api-lib-spelling-configs';\nexport { NoUtilityTypesInApiLibConfig } from './configs/no-utility-types-config';\nexport { RequiredTypeSuffixEntry, RequiredTypeSuffixConfig } from './configs/required-type-suffix-config';\nexport { CatchMustPropagateConfig } from './configs/catch-must-propagate-config';\nexport { CatchMustPropagateValidator, LocatedCatchFinding } from './validate-catch-must-propagate';\nexport { PROJECT_SCAN_MODES, FrameworkTsconfigConfig, FrameworkPackagesEntry, FrameworkPackagesConfig } from './configs/tag-truth-configs';\nexport type { ProjectScanMode } from './configs/tag-truth-configs';\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseRuleConfig } from '@webpieces/rules-sdk';
|
|
2
|
+
import { InformAiError } from '@webpieces/tooling-common';
|
|
3
|
+
import { ScanScope } from './scan-scope';
|
|
4
|
+
/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */
|
|
5
|
+
export declare class DebugPlan {
|
|
6
|
+
readonly rule: string;
|
|
7
|
+
readonly mode: string;
|
|
8
|
+
readonly committedMode: string;
|
|
9
|
+
readonly projects: readonly string[] | undefined;
|
|
10
|
+
constructor(rule: string, mode: string, committedMode: string, projects: readonly string[] | undefined);
|
|
11
|
+
}
|
|
12
|
+
/** What a debug run was asked, before it is validated against the rule's modes and the repo. Data-only. */
|
|
13
|
+
export declare class DebugAsk {
|
|
14
|
+
readonly rule: string;
|
|
15
|
+
/** `--mode`, or undefined to run at the committed mode. */
|
|
16
|
+
readonly mode: string | undefined;
|
|
17
|
+
readonly committedMode: string;
|
|
18
|
+
/** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */
|
|
19
|
+
readonly modes: readonly string[];
|
|
20
|
+
readonly projects: readonly string[] | undefined;
|
|
21
|
+
constructor(rule: string,
|
|
22
|
+
/** `--mode`, or undefined to run at the committed mode. */
|
|
23
|
+
mode: string | undefined, committedMode: string,
|
|
24
|
+
/** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */
|
|
25
|
+
modes: readonly string[], projects: readonly string[] | undefined);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The parts of a one-rule DEBUG run (#1027) every runner shares, so a built-in code rule and a repo-local
|
|
29
|
+
* rule (#1330) refuse, announce, override and count identically: the same refusals, the same banner, the
|
|
30
|
+
* same in-memory override (mode replaced, both escape hatches cleared) and the same per-project count.
|
|
31
|
+
* The runner owns only the part between banner and count — running the rule through a {@link ScanScope}
|
|
32
|
+
* restricted to the plan's projects and recording each site there.
|
|
33
|
+
*/
|
|
34
|
+
export declare class RuleDebugRun {
|
|
35
|
+
/** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */
|
|
36
|
+
supports(modes: readonly string[]): boolean;
|
|
37
|
+
/** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */
|
|
38
|
+
plan(workspaceRoot: string, ask: DebugAsk): DebugPlan;
|
|
39
|
+
refusal(reason: string): InformAiError;
|
|
40
|
+
/** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
|
|
41
|
+
overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C;
|
|
42
|
+
printBanner(plan: DebugPlan): void;
|
|
43
|
+
/** Print one count per project from the sites recorded in `scan`, and return the total. */
|
|
44
|
+
printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): number;
|
|
45
|
+
private projectNames;
|
|
46
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleDebugRun = exports.DebugAsk = exports.DebugPlan = void 0;
|
|
4
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const scan_scope_1 = require("./scan-scope");
|
|
7
|
+
/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */
|
|
8
|
+
class DebugPlan {
|
|
9
|
+
rule;
|
|
10
|
+
mode;
|
|
11
|
+
committedMode;
|
|
12
|
+
projects;
|
|
13
|
+
constructor(rule, mode, committedMode, projects) {
|
|
14
|
+
this.rule = rule;
|
|
15
|
+
this.mode = mode;
|
|
16
|
+
this.committedMode = committedMode;
|
|
17
|
+
this.projects = projects;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DebugPlan = DebugPlan;
|
|
21
|
+
/** What a debug run was asked, before it is validated against the rule's modes and the repo. Data-only. */
|
|
22
|
+
class DebugAsk {
|
|
23
|
+
rule;
|
|
24
|
+
mode;
|
|
25
|
+
committedMode;
|
|
26
|
+
modes;
|
|
27
|
+
projects;
|
|
28
|
+
constructor(rule,
|
|
29
|
+
/** `--mode`, or undefined to run at the committed mode. */
|
|
30
|
+
mode, committedMode,
|
|
31
|
+
/** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */
|
|
32
|
+
modes, projects) {
|
|
33
|
+
this.rule = rule;
|
|
34
|
+
this.mode = mode;
|
|
35
|
+
this.committedMode = committedMode;
|
|
36
|
+
this.modes = modes;
|
|
37
|
+
this.projects = projects;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.DebugAsk = DebugAsk;
|
|
41
|
+
/**
|
|
42
|
+
* The parts of a one-rule DEBUG run (#1027) every runner shares, so a built-in code rule and a repo-local
|
|
43
|
+
* rule (#1330) refuse, announce, override and count identically: the same refusals, the same banner, the
|
|
44
|
+
* same in-memory override (mode replaced, both escape hatches cleared) and the same per-project count.
|
|
45
|
+
* The runner owns only the part between banner and count — running the rule through a {@link ScanScope}
|
|
46
|
+
* restricted to the plan's projects and recording each site there.
|
|
47
|
+
*/
|
|
48
|
+
class RuleDebugRun {
|
|
49
|
+
/** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */
|
|
50
|
+
supports(modes) {
|
|
51
|
+
return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME');
|
|
52
|
+
}
|
|
53
|
+
/** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */
|
|
54
|
+
plan(workspaceRoot, ask) {
|
|
55
|
+
const mode = ask.mode ?? ask.committedMode;
|
|
56
|
+
if (!ask.modes.includes(mode) || mode === 'OFF') {
|
|
57
|
+
const why = ask.mode === undefined
|
|
58
|
+
? `its committed mode is ${ask.committedMode}`
|
|
59
|
+
: `--mode=${mode} is not one of its modes`;
|
|
60
|
+
throw this.refusal(`${ask.rule} cannot run: ${why}. Pass --mode=<one of ${ask.modes.filter((m) => m !== 'OFF').join(', ')}>.`);
|
|
61
|
+
}
|
|
62
|
+
const known = this.projectNames(workspaceRoot);
|
|
63
|
+
const unknown = (ask.projects ?? []).filter((name) => !known.includes(name));
|
|
64
|
+
if (unknown.length > 0) {
|
|
65
|
+
throw this.refusal(`--projects names no such nx project: ${unknown.join(', ')}. Known projects: ${known.join(', ')}.`);
|
|
66
|
+
}
|
|
67
|
+
return new DebugPlan(ask.rule, mode, ask.committedMode, ask.projects);
|
|
68
|
+
}
|
|
69
|
+
refusal(reason) {
|
|
70
|
+
return new tooling_common_1.InformAiError(`[debug run] ${reason}`);
|
|
71
|
+
}
|
|
72
|
+
/** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
|
|
73
|
+
overridden(config, plan) {
|
|
74
|
+
const copy = Object.assign(Object.create(Object.getPrototypeOf(config)), config);
|
|
75
|
+
copy.mode = plan.mode;
|
|
76
|
+
copy.turnOffRuleUntilEpoch = 0;
|
|
77
|
+
copy.turnOffRuleWhileOnBranch = null;
|
|
78
|
+
return copy;
|
|
79
|
+
}
|
|
80
|
+
printBanner(plan) {
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log(`🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`);
|
|
83
|
+
console.log(` Mode: ${plan.mode} (committed: ${plan.committedMode})` +
|
|
84
|
+
` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +
|
|
85
|
+
' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run');
|
|
86
|
+
}
|
|
87
|
+
/** Print one count per project from the sites recorded in `scan`, and return the total. */
|
|
88
|
+
printCounts(workspaceRoot, plan, scan, ruleSucceeded) {
|
|
89
|
+
const counts = scan.countsByProject(workspaceRoot);
|
|
90
|
+
const names = plan.projects ?? Array.from(counts.keys()).sort();
|
|
91
|
+
const total = Array.from(counts.values()).reduce((sum, n) => sum + n, 0);
|
|
92
|
+
console.log('');
|
|
93
|
+
console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);
|
|
94
|
+
for (const name of names)
|
|
95
|
+
console.log(` ${name}: ${counts.get(name) ?? 0}`);
|
|
96
|
+
if (!ruleSucceeded && total === 0) {
|
|
97
|
+
console.log(' (the rule failed without reporting sites — read its output above)');
|
|
98
|
+
}
|
|
99
|
+
console.log('');
|
|
100
|
+
return total;
|
|
101
|
+
}
|
|
102
|
+
projectNames(workspaceRoot) {
|
|
103
|
+
return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope())
|
|
104
|
+
.all(workspaceRoot)
|
|
105
|
+
.map((p) => p.name)
|
|
106
|
+
.sort();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.RuleDebugRun = RuleDebugRun;
|
|
110
|
+
//# sourceMappingURL=rule-debug-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-debug-run.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-debug-run.ts"],"names":[],"mappings":";;;AACA,0DAAoD;AACpD,8DAA0D;AAE1D,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAa,SAAS;IAEL;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAPD,8BAOC;AAED,2GAA2G;AAC3G,MAAa,QAAQ;IAEJ;IAEA;IACA;IAEA;IACA;IAPb,YACa,IAAY;IACrB,2DAA2D;IAClD,IAAwB,EACxB,aAAqB;IAC9B,yGAAyG;IAChG,KAAwB,EACxB,QAAuC;QANvC,SAAI,GAAJ,IAAI,CAAQ;QAEZ,SAAI,GAAJ,IAAI,CAAoB;QACxB,kBAAa,GAAb,aAAa,CAAQ;QAErB,UAAK,GAAL,KAAK,CAAmB;QACxB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAVD,4BAUC;AAED;;;;;;GAMG;AACH,MAAa,YAAY;IACrB,uGAAuG;IACvG,QAAQ,CAAC,KAAwB;QAC7B,OA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GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC;QACtE,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,aAAa,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,aAAqB;QACtC,OAAO,IAAI,2BAAc,CAAC,IAAI,wBAAS,EAAE,CAAC;aACrC,GAAG,CAAC,aAAa,CAAC;aAClB,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAChC,IAAI,EAAE,CAAC;IAChB,CAAC;CACJ;AA7ED,oCA6EC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport { DiffScope } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nexport class DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/** What a debug run was asked, before it is validated against the rule's modes and the repo. Data-only. */\nexport class DebugAsk {\n constructor(\n readonly rule: string,\n /** `--mode`, or undefined to run at the committed mode. */\n readonly mode: string | undefined,\n readonly committedMode: string,\n /** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */\n readonly modes: readonly string[],\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The parts of a one-rule DEBUG run (#1027) every runner shares, so a built-in code rule and a repo-local\n * rule (#1330) refuse, announce, override and count identically: the same refusals, the same banner, the\n * same in-memory override (mode replaced, both escape hatches cleared) and the same per-project count.\n * The runner owns only the part between banner and count — running the rule through a {@link ScanScope}\n * restricted to the plan's projects and recording each site there.\n */\nexport class RuleDebugRun {\n /** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */\n supports(modes: readonly string[]): boolean {\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME');\n }\n\n /** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */\n plan(workspaceRoot: string, ask: DebugAsk): DebugPlan {\n const mode = ask.mode ?? ask.committedMode;\n if (!ask.modes.includes(mode) || mode === 'OFF') {\n const why =\n ask.mode === undefined\n ? `its committed mode is ${ask.committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${ask.rule} cannot run: ${why}. Pass --mode=<one of ${ask.modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const known = this.projectNames(workspaceRoot);\n const unknown = (ask.projects ?? []).filter((name: string) => !known.includes(name));\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ${known.join(', ')}.`,\n );\n }\n return new DebugPlan(ask.rule, mode, ask.committedMode, ask.projects);\n }\n\n refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project from the sites recorded in `scan`, and return the total. */\n printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!ruleSucceeded && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope())\n .all(workspaceRoot)\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n}\n"]}
|