@webpieces/code-rules 0.4.819 → 0.4.821
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 +2 -2
- package/src/api-lib-source-rule.d.ts +5 -2
- package/src/api-lib-source-rule.js +8 -4
- package/src/api-lib-source-rule.js.map +1 -1
- package/src/cli.js +13 -14
- package/src/cli.js.map +1 -1
- package/src/code-rules-bootstrap.d.ts +31 -8
- package/src/code-rules-bootstrap.js +136 -18
- package/src/code-rules-bootstrap.js.map +1 -1
- package/src/code-rules-config-table.d.ts +3 -1
- package/src/code-rules-config-table.js +0 -6
- package/src/code-rules-config-table.js.map +1 -1
- package/src/code-rules-engine.d.ts +4 -13
- package/src/code-rules-engine.js +9 -31
- package/src/code-rules-engine.js.map +1 -1
- package/src/code-rules-run-request.d.ts +30 -34
- package/src/code-rules-run-request.js +43 -80
- package/src/code-rules-run-request.js.map +1 -1
- package/src/index.d.ts +3 -1
- package/src/index.js +13 -2
- package/src/index.js.map +1 -1
- package/src/resolve-mode.d.ts +1 -1
- package/src/resolve-mode.js +2 -3
- package/src/resolve-mode.js.map +1 -1
- package/src/scan-scope.d.ts +82 -0
- package/src/scan-scope.js +200 -0
- package/src/scan-scope.js.map +1 -0
- package/src/validate-catch-error-pattern.d.ts +3 -1
- package/src/validate-catch-error-pattern.js +11 -6
- package/src/validate-catch-error-pattern.js.map +1 -1
- package/src/validate-code.d.ts +4 -5
- package/src/validate-code.js +6 -17
- package/src/validate-code.js.map +1 -1
- package/src/validate-inject-annotation-not-needed-for-concrete-class.d.ts +3 -1
- package/src/validate-inject-annotation-not-needed-for-concrete-class.js +11 -6
- package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
- package/src/validate-match-rules.d.ts +3 -0
- package/src/validate-match-rules.js +10 -3
- package/src/validate-match-rules.js.map +1 -1
- package/src/validate-no-any-unknown.d.ts +3 -1
- package/src/validate-no-any-unknown.js +11 -6
- package/src/validate-no-any-unknown.js.map +1 -1
- package/src/validate-no-client-creation-outside-server-or-client.d.ts +4 -2
- package/src/validate-no-client-creation-outside-server-or-client.js +10 -5
- package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
- package/src/validate-no-custom-css.d.ts +4 -2
- package/src/validate-no-custom-css.js +9 -5
- package/src/validate-no-custom-css.js.map +1 -1
- package/src/validate-no-destructure.d.ts +3 -1
- package/src/validate-no-destructure.js +11 -6
- package/src/validate-no-destructure.js.map +1 -1
- package/src/validate-no-function-outside-class.d.ts +3 -1
- package/src/validate-no-function-outside-class.js +12 -6
- package/src/validate-no-function-outside-class.js.map +1 -1
- package/src/validate-no-implicit-any.d.ts +3 -1
- package/src/validate-no-implicit-any.js +13 -8
- package/src/validate-no-implicit-any.js.map +1 -1
- package/src/validate-no-inline-import-in-api-lib.d.ts +2 -1
- package/src/validate-no-inline-import-in-api-lib.js +4 -3
- package/src/validate-no-inline-import-in-api-lib.js.map +1 -1
- package/src/validate-no-process-exit-outside-main.d.ts +3 -1
- package/src/validate-no-process-exit-outside-main.js +12 -6
- package/src/validate-no-process-exit-outside-main.js.map +1 -1
- package/src/validate-no-state-paths-in-templates.d.ts +4 -2
- package/src/validate-no-state-paths-in-templates.js +9 -5
- package/src/validate-no-state-paths-in-templates.js.map +1 -1
- package/src/validate-no-symbol-di-tokens.d.ts +3 -1
- package/src/validate-no-symbol-di-tokens.js +11 -6
- package/src/validate-no-symbol-di-tokens.js.map +1 -1
- package/src/validate-no-unmanaged-exceptions.d.ts +3 -1
- package/src/validate-no-unmanaged-exceptions.js +11 -6
- package/src/validate-no-unmanaged-exceptions.js.map +1 -1
- package/src/validate-no-utility-types-in-api-lib.d.ts +2 -1
- package/src/validate-no-utility-types-in-api-lib.js +4 -3
- package/src/validate-no-utility-types-in-api-lib.js.map +1 -1
- package/src/validate-one-enum-spelling-in-api-lib.d.ts +2 -1
- package/src/validate-one-enum-spelling-in-api-lib.js +4 -3
- package/src/validate-one-enum-spelling-in-api-lib.js.map +1 -1
- package/src/validate-required-type-suffix.d.ts +2 -1
- package/src/validate-required-type-suffix.js +7 -3
- package/src/validate-required-type-suffix.js.map +1 -1
- package/src/wp-ci.d.ts +2 -2
- package/src/wp-ci.js +11 -5
- package/src/wp-ci.js.map +1 -1
- package/src/debug-run-report.d.ts +0 -22
- package/src/debug-run-report.js +0 -127
- package/src/debug-run-report.js.map +0 -1
- package/src/rule-scope-plan.d.ts +0 -72
- package/src/rule-scope-plan.js +0 -132
- package/src/rule-scope-plan.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/code-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.821",
|
|
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,7 +16,7 @@
|
|
|
16
16
|
"directory": "packages/tooling/code-rules"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/rules-config": "0.4.821",
|
|
20
20
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2"
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP
|
|
8
8
|
* generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the
|
|
9
9
|
* changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES
|
|
10
|
-
* judges every site in a changed file
|
|
10
|
+
* judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every
|
|
11
|
+
* file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape
|
|
11
12
|
* hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which
|
|
12
13
|
* `RuleReporter` renders. A subclass only says what a violating site IS.
|
|
13
14
|
*
|
|
@@ -18,6 +19,7 @@ import * as ts from 'typescript';
|
|
|
18
19
|
import { DiffScope, NoInlineImportInApiLibConfig, NoUtilityTypesInApiLibConfig, OneEnumSpellingInApiLibConfig, RequiredTypeSuffixConfig } from '@webpieces/rules-config';
|
|
19
20
|
import { CodeValidator, ExecutorResult } from './code-validator';
|
|
20
21
|
import { ProjectRoleResolver } from './project-role-resolver';
|
|
22
|
+
import { ScanScope } from './scan-scope';
|
|
21
23
|
/** One violating site: where, what it is, and the edit that replaces it. Data-only. */
|
|
22
24
|
export declare class ApiLibSite {
|
|
23
25
|
/** 1-based line of the site's first character. */
|
|
@@ -53,7 +55,8 @@ type ApiLibConfig = NoInlineImportInApiLibConfig | OneEnumSpellingInApiLibConfig
|
|
|
53
55
|
export declare abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {
|
|
54
56
|
private readonly roleResolver;
|
|
55
57
|
private readonly diffScope;
|
|
56
|
-
|
|
58
|
+
private readonly scanScope;
|
|
59
|
+
constructor(config: C, ruleName: string, roleResolver: ProjectRoleResolver, diffScope: DiffScope, scanScope: ScanScope);
|
|
57
60
|
/** Every violating site in one api-library file. */
|
|
58
61
|
protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];
|
|
59
62
|
/** The one-sentence WHY printed above the sites. */
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP
|
|
9
9
|
* generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the
|
|
10
10
|
* changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES
|
|
11
|
-
* judges every site in a changed file
|
|
11
|
+
* judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every
|
|
12
|
+
* file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape
|
|
12
13
|
* hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which
|
|
13
14
|
* `RuleReporter` renders. A subclass only says what a violating site IS.
|
|
14
15
|
*
|
|
@@ -80,10 +81,12 @@ class FoundSite {
|
|
|
80
81
|
class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
81
82
|
roleResolver;
|
|
82
83
|
diffScope;
|
|
83
|
-
|
|
84
|
+
scanScope;
|
|
85
|
+
constructor(config, ruleName, roleResolver, diffScope, scanScope) {
|
|
84
86
|
super(config, ruleName, ruleName);
|
|
85
87
|
this.roleResolver = roleResolver;
|
|
86
88
|
this.diffScope = diffScope;
|
|
89
|
+
this.scanScope = scanScope;
|
|
87
90
|
}
|
|
88
91
|
async run(workspaceRoot) {
|
|
89
92
|
const mode = this.config.mode;
|
|
@@ -97,18 +100,19 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
|
97
100
|
return { success: true };
|
|
98
101
|
}
|
|
99
102
|
const found = [];
|
|
100
|
-
for (const relFile of this.
|
|
103
|
+
for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {
|
|
101
104
|
found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));
|
|
102
105
|
}
|
|
103
106
|
if (found.length === 0)
|
|
104
107
|
return { success: true };
|
|
108
|
+
this.scanScope.recordSites(this.name, found.map((each) => each.relFile));
|
|
105
109
|
throw this.failure(found);
|
|
106
110
|
}
|
|
107
111
|
/** The unexempt, in-scope violating sites of one changed file. */
|
|
108
112
|
judge(workspaceRoot, relFile, mode, base, head) {
|
|
109
113
|
if (!this.inScope(workspaceRoot, relFile))
|
|
110
114
|
return [];
|
|
111
|
-
const changedLines = mode
|
|
115
|
+
const changedLines = this.scanScope.isLineScoped(mode)
|
|
112
116
|
? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))
|
|
113
117
|
: undefined;
|
|
114
118
|
if (changedLines !== undefined && changedLines.size === 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAWiC;AACjC,qDAAiE;AAGjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AATD,gCASC;AAED,+FAA+F;AAC/F,MAAa,UAAU;IAGN;IACA;IAEA;IALb;IACI,0BAA0B;IACjB,OAAe,EACf,MAAqB;IAC9B,sFAAsF;IAC7E,UAAkB;QAHlB,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAe;QAErB,eAAU,GAAV,UAAU,CAAQ;IAC5B,CAAC;IAEJ,yCAAyC;IACzC,MAAM,CAAC,IAAa;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;IAC1F,CAAC;IAED,wDAAwD;IACxD,IAAI,CAAC,IAAa,EAAE,IAAY,EAAE,IAAY;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACnE,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,CAAC,IAAI,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAC3G,CAAC;IACN,CAAC;CACJ;AAxGD,4CAwGC","sourcesContent":["/**\n * The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport {\n DiffScope,\n ModifiedCodeMode,\n NoInlineImportInApiLibConfig,\n NoUtilityTypesInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n Option,\n RequiredTypeSuffixConfig,\n RuleFailError,\n hasDisable,\n isPathExcluded,\n} from '@webpieces/rules-config';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of this.diffScope.getChangedFiles(workspaceRoot, base, range.head)) {\n found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): FoundSite[] {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = mode === 'NEW_AND_MODIFIED_CODE'\n ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (isPathExcluded(relFile, this.config.allowedPaths ?? [])) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAWiC;AACjC,qDAAiE;AAIjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,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role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every\n * file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport {\n DiffScope,\n ModifiedCodeMode,\n NoInlineImportInApiLibConfig,\n NoUtilityTypesInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n Option,\n RequiredTypeSuffixConfig,\n RuleFailError,\n hasDisable,\n isPathExcluded,\n} from '@webpieces/rules-config';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n private readonly scanScope: ScanScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {\n found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n this.scanScope.recordSites(this.name, found.map((each: FoundSite) => each.relFile));\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): FoundSite[] {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = this.scanScope.isLineScoped(mode)\n ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (isPathExcluded(relFile, this.config.allowedPaths ?? [])) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
|
package/src/cli.js
CHANGED
|
@@ -3,32 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const code_rules_app_1 = require("./code-rules-app");
|
|
7
6
|
const code_rules_bootstrap_1 = require("./code-rules-bootstrap");
|
|
8
7
|
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
8
|
+
const USAGE = new rules_config_1.CliUsage('wp-validate-code', 'run the code rules against the diff, exactly as the gate does — or, with --rule, a DEBUG run of one rule', [
|
|
9
|
+
new rules_config_1.CliFlag('--rule', 'DEBUG: run only this rule (e.g. one-enum-spelling-in-api-lib). Nothing is written; the gate is unaffected.', true),
|
|
10
|
+
new rules_config_1.CliFlag('--mode', 'DEBUG: run --rule at this mode instead of its committed one (e.g. RUN_EVERY_TIME, MODIFIED_PROJECTS).', true),
|
|
11
|
+
new rules_config_1.CliFlag('--projects', 'DEBUG: judge only files owned by these nx projects, comma-separated (e.g. lang-apis,lang-fsdb-api).', true),
|
|
12
|
+
]);
|
|
9
13
|
async function main() {
|
|
10
14
|
// webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI
|
|
11
15
|
try {
|
|
16
|
+
const args = new rules_config_1.CliArgs().parse(USAGE);
|
|
17
|
+
const request = new code_rules_run_request_1.RunRequestParser().parse(args.has('--rule') ? args.value('--rule') : undefined, args.has('--mode') ? args.value('--mode') : undefined, args.has('--projects') ? args.value('--projects') : undefined);
|
|
12
18
|
// Anchor at the repo root so `.webpieces/instruct-ai` docs land there, not in whatever subdir
|
|
13
19
|
// this CLI ran from; load config from there.
|
|
14
20
|
const workspaceRoot = new rules_config_1.RepoRootFinder().resolveRepoRoot(process.cwd());
|
|
15
|
-
const
|
|
16
|
-
if (loaded.configPath === null) {
|
|
17
|
-
console.error('\n❌ No webpieces.config.json found at workspace root (or any ancestor).\n');
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
console.log(`\n📄 Loaded config: ${loaded.configPath}`);
|
|
21
|
-
// Composition root: the shared bootstrap binds the runtime values (workspace root, the run
|
|
22
|
-
// request, each rule's planned config) and inversify builds the ENTIRE validator DAG.
|
|
23
|
-
const request = new code_rules_run_request_1.CodeRulesRunRequestParser().fromArgv(process.argv.slice(2));
|
|
24
|
-
const container = new code_rules_bootstrap_1.CodeRulesBootstrap().container(workspaceRoot, loaded, request);
|
|
25
|
-
const app = container.get(code_rules_app_1.CodeRulesApp);
|
|
26
|
-
const result = await app.run();
|
|
21
|
+
const result = await new code_rules_bootstrap_1.CodeRulesBootstrap().run(workspaceRoot, request);
|
|
27
22
|
process.exit(result.success ? 0 : 1);
|
|
28
23
|
}
|
|
29
24
|
catch (err) {
|
|
30
25
|
const error = (0, rules_config_1.toError)(err);
|
|
31
|
-
if (error instanceof rules_config_1.
|
|
26
|
+
if (error instanceof rules_config_1.CliExitError) {
|
|
27
|
+
console.error(error.message);
|
|
28
|
+
process.exit(error.exitCode);
|
|
29
|
+
}
|
|
30
|
+
else if (error instanceof rules_config_1.RuleFailError) {
|
|
32
31
|
console.error((0, rules_config_1.renderRuleFailForHuman)(error));
|
|
33
32
|
}
|
|
34
33
|
else if (err instanceof rules_config_1.InformAiError) {
|
package/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAUiC;AAEjC,iEAA4D;AAC5D,qEAA4D;AAE5D,MAAM,KAAK,GAAG,IAAI,uBAAQ,CACtB,kBAAkB,EAClB,0GAA0G,EAC1G;IACI,IAAI,sBAAO,CAAC,QAAQ,EAAE,4GAA4G,EAAE,IAAI,CAAC;IACzI,IAAI,sBAAO,CAAC,QAAQ,EAAE,uGAAuG,EAAE,IAAI,CAAC;IACpI,IAAI,sBAAO,CAAC,YAAY,EAAE,qGAAqG,EAAE,IAAI,CAAC;CACzI,CACJ,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,qFAAqF;IACrF,IAAI,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,sBAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,OAAO,GAAG,IAAI,yCAAgB,EAAE,CAAC,KAAK,CACxC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EACrD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EACrD,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC;QACF,8FAA8F;QAC9F,6CAA6C;QAC7C,MAAM,aAAa,GAAG,IAAI,6BAAc,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,MAAM,IAAI,yCAAkB,EAAE,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,sBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,YAAY,2BAAY,EAAE,CAAC;YAChC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,KAAK,YAAY,4BAAa,EAAE,CAAC;YACxC,OAAO,CAAC,KAAK,CAAC,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,GAAG,YAAY,4BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport {\n CliArgs,\n CliExitError,\n CliFlag,\n CliUsage,\n InformAiError,\n RuleFailError,\n renderRuleFailForHuman,\n toError,\n RepoRootFinder,\n} from '@webpieces/rules-config';\n\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { RunRequestParser } from './code-rules-run-request';\n\nconst USAGE = new CliUsage(\n 'wp-validate-code',\n 'run the code rules against the diff, exactly as the gate does — or, with --rule, a DEBUG run of one rule',\n [\n new CliFlag('--rule', 'DEBUG: run only this rule (e.g. one-enum-spelling-in-api-lib). Nothing is written; the gate is unaffected.', true),\n new CliFlag('--mode', 'DEBUG: run --rule at this mode instead of its committed one (e.g. RUN_EVERY_TIME, MODIFIED_PROJECTS).', true),\n new CliFlag('--projects', 'DEBUG: judge only files owned by these nx projects, comma-separated (e.g. lang-apis,lang-fsdb-api).', true),\n ],\n);\n\nasync function main(): Promise<void> {\n // webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI\n try {\n const args = new CliArgs().parse(USAGE);\n const request = new RunRequestParser().parse(\n args.has('--rule') ? args.value('--rule') : undefined,\n args.has('--mode') ? args.value('--mode') : undefined,\n args.has('--projects') ? args.value('--projects') : undefined,\n );\n // Anchor at the repo root so `.webpieces/instruct-ai` docs land there, not in whatever subdir\n // this CLI ran from; load config from there.\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(process.cwd());\n const result = await new CodeRulesBootstrap().run(workspaceRoot, request);\n process.exit(result.success ? 0 : 1);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof CliExitError) {\n console.error(error.message);\n process.exit(error.exitCode);\n } else if (error instanceof RuleFailError) {\n console.error(renderRuleFailForHuman(error));\n } else if (err instanceof InformAiError) {\n console.error(error.message);\n } else {\n console.error(`[code-rules] unexpected error: ${error.message}`);\n }\n process.exit(1);\n }\n}\n\nmain();\n"]}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ExecutorResult } from './code-validator';
|
|
3
3
|
import { CodeRulesRunRequest } from './code-rules-run-request';
|
|
4
4
|
/**
|
|
5
|
-
* The ONE code-rules
|
|
6
|
-
* `validate-code`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the
|
|
6
|
+
* `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,
|
|
7
|
+
* then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.
|
|
8
|
+
*
|
|
9
|
+
* A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four
|
|
10
|
+
* ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two
|
|
11
|
+
* escape hatches are cleared (the question asked is "what is left?", which a time-boxed OFF must not
|
|
12
|
+
* hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing
|
|
13
|
+
* is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It
|
|
14
|
+
* prints the rule's own failure text, then one count per project, and fails when any site exists.
|
|
15
|
+
*
|
|
16
|
+
* A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an
|
|
17
|
+
* {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.
|
|
10
18
|
*/
|
|
11
19
|
export declare class CodeRulesBootstrap {
|
|
12
|
-
|
|
20
|
+
run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult>;
|
|
21
|
+
/** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */
|
|
22
|
+
private plan;
|
|
23
|
+
private refusal;
|
|
24
|
+
/** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
|
|
25
|
+
private wholeScopeModesOf;
|
|
26
|
+
private debuggableRules;
|
|
27
|
+
private committedModeOf;
|
|
28
|
+
private projectNames;
|
|
29
|
+
/** The match-rules, with the debugged one (if it is a match rule) overridden. */
|
|
30
|
+
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;
|
|
13
36
|
}
|
|
@@ -1,37 +1,155 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CodeRulesBootstrap = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
4
5
|
const inversify_1 = require("inversify");
|
|
5
6
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const
|
|
7
|
+
const code_rules_app_1 = require("./code-rules-app");
|
|
7
8
|
const code_rules_context_1 = require("./code-rules-context");
|
|
8
9
|
const code_rules_config_table_1 = require("./code-rules-config-table");
|
|
9
|
-
const
|
|
10
|
+
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
11
|
+
const scan_scope_1 = require("./scan-scope");
|
|
12
|
+
/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */
|
|
13
|
+
class DebugPlan {
|
|
14
|
+
rule;
|
|
15
|
+
mode;
|
|
16
|
+
committedMode;
|
|
17
|
+
projects;
|
|
18
|
+
constructor(rule, mode, committedMode, projects) {
|
|
19
|
+
this.rule = rule;
|
|
20
|
+
this.mode = mode;
|
|
21
|
+
this.committedMode = committedMode;
|
|
22
|
+
this.projects = projects;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
/**
|
|
11
|
-
* The ONE code-rules
|
|
12
|
-
* `validate-code`
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
26
|
+
* The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the
|
|
27
|
+
* `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,
|
|
28
|
+
* then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.
|
|
29
|
+
*
|
|
30
|
+
* A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four
|
|
31
|
+
* ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two
|
|
32
|
+
* escape hatches are cleared (the question asked is "what is left?", which a time-boxed OFF must not
|
|
33
|
+
* hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing
|
|
34
|
+
* is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It
|
|
35
|
+
* prints the rule's own failure text, then one count per project, and fails when any site exists.
|
|
36
|
+
*
|
|
37
|
+
* A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an
|
|
38
|
+
* {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.
|
|
16
39
|
*/
|
|
17
40
|
class CodeRulesBootstrap {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
41
|
+
async run(workspaceRoot, request) {
|
|
42
|
+
const loaded = (0, rules_config_1.loadAndValidate)(workspaceRoot);
|
|
43
|
+
if (loaded.configPath === null) {
|
|
44
|
+
throw new rules_config_1.InformAiError('No webpieces.config.json found at workspace root (or any ancestor).');
|
|
45
|
+
}
|
|
46
|
+
console.log(`\n📄 Loaded config: ${loaded.configPath}`);
|
|
47
|
+
const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;
|
|
48
|
+
if (plan !== undefined)
|
|
49
|
+
this.printBanner(plan);
|
|
21
50
|
// autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
|
|
22
51
|
const container = new inversify_1.Container({ autobind: true });
|
|
23
52
|
container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
|
|
24
|
-
container.bind(
|
|
53
|
+
container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(this.matchRules(loaded, plan)));
|
|
54
|
+
container.bind(code_rules_run_request_1.RuleSelection).toConstantValue(new code_rules_run_request_1.RuleSelection(plan?.rule));
|
|
55
|
+
container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(plan?.projects));
|
|
25
56
|
for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
|
|
26
57
|
const ConfigClass = binding[0];
|
|
27
|
-
const configured = loaded.rulesConfig[binding[1]]
|
|
28
|
-
const
|
|
29
|
-
container.bind(ConfigClass).toConstantValue(
|
|
58
|
+
const configured = loaded.rulesConfig[binding[1]];
|
|
59
|
+
const config = configured ?? new ConfigClass();
|
|
60
|
+
container.bind(ConfigClass).toConstantValue(plan?.rule === binding[1] ? this.overridden(config, plan) : config);
|
|
61
|
+
}
|
|
62
|
+
const result = await container.get(code_rules_app_1.CodeRulesApp).run();
|
|
63
|
+
if (plan === undefined)
|
|
64
|
+
return result;
|
|
65
|
+
// A debug run FAILS whenever a site exists — including a rule that only warns at the gate
|
|
66
|
+
// (no-client-creation-outside-server-or-client at severity "warn") — so it can gate a loop.
|
|
67
|
+
const sites = this.printCounts(workspaceRoot, plan, container.get(scan_scope_1.ScanScope), result);
|
|
68
|
+
return { success: result.success && sites === 0 };
|
|
69
|
+
}
|
|
70
|
+
/** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */
|
|
71
|
+
plan(workspaceRoot, loaded, request) {
|
|
72
|
+
const rule = request.rule;
|
|
73
|
+
if (rule === undefined)
|
|
74
|
+
throw this.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');
|
|
75
|
+
const modes = this.wholeScopeModesOf(rule, loaded);
|
|
76
|
+
if (modes === undefined) {
|
|
77
|
+
throw this.refusal(`--rule=${rule} is not a code rule that supports a debug run. Rules that do (they offer ` +
|
|
78
|
+
`MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`);
|
|
79
|
+
}
|
|
80
|
+
const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';
|
|
81
|
+
const mode = request.mode ?? committedMode;
|
|
82
|
+
if (!modes.includes(mode) || mode === 'OFF') {
|
|
83
|
+
const why = request.mode === undefined ? `its committed mode is ${committedMode}` : `--mode=${mode} is not one of its modes`;
|
|
84
|
+
throw this.refusal(`${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m) => m !== 'OFF').join(', ')}>.`);
|
|
85
|
+
}
|
|
86
|
+
const unknown = (request.projects ?? []).filter((name) => !this.projectNames(workspaceRoot).includes(name));
|
|
87
|
+
if (unknown.length > 0) {
|
|
88
|
+
throw this.refusal(`--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +
|
|
89
|
+
`${this.projectNames(workspaceRoot).join(', ')}.`);
|
|
90
|
+
}
|
|
91
|
+
return new DebugPlan(rule, mode, committedMode, request.projects);
|
|
92
|
+
}
|
|
93
|
+
refusal(reason) {
|
|
94
|
+
return new rules_config_1.InformAiError(`[debug run] ${reason}`);
|
|
95
|
+
}
|
|
96
|
+
/** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
|
|
97
|
+
wholeScopeModesOf(rule, loaded) {
|
|
98
|
+
if (loaded.matchRules.some((mr) => mr.name === rule))
|
|
99
|
+
return rules_config_1.MODIFIED_CODE_MODES;
|
|
100
|
+
if (!code_rules_config_table_1.CONFIG_BINDINGS.some((binding) => binding[1] === rule))
|
|
101
|
+
return undefined;
|
|
102
|
+
const modes = rules_config_1.RULE_SCHEMAS[rule]?.['mode']?.enumValues ?? [];
|
|
103
|
+
return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME') ? modes : undefined;
|
|
104
|
+
}
|
|
105
|
+
debuggableRules(loaded) {
|
|
106
|
+
const builtIns = code_rules_config_table_1.CONFIG_BINDINGS.map((binding) => binding[1]);
|
|
107
|
+
const names = [...builtIns, ...loaded.matchRules.map((mr) => mr.name)];
|
|
108
|
+
return names.filter((name) => this.wholeScopeModesOf(name, loaded) !== undefined);
|
|
109
|
+
}
|
|
110
|
+
committedModeOf(rule, loaded) {
|
|
111
|
+
const match = loaded.matchRules.find((mr) => mr.name === rule);
|
|
112
|
+
if (match !== undefined)
|
|
113
|
+
return match.mode;
|
|
114
|
+
const configured = loaded.rulesConfig[rule];
|
|
115
|
+
return configured?.mode;
|
|
116
|
+
}
|
|
117
|
+
projectNames(workspaceRoot) {
|
|
118
|
+
return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope()).all(workspaceRoot).map((p) => p.name).sort();
|
|
119
|
+
}
|
|
120
|
+
/** The match-rules, with the debugged one (if it is a match rule) overridden. */
|
|
121
|
+
matchRules(loaded, plan) {
|
|
122
|
+
return loaded.matchRules.map((mr) => (plan?.rule === mr.name ? this.overridden(mr, plan) : mr));
|
|
123
|
+
}
|
|
124
|
+
/** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
|
|
125
|
+
overridden(config, plan) {
|
|
126
|
+
const copy = Object.assign(Object.create(Object.getPrototypeOf(config)), config);
|
|
127
|
+
copy.mode = plan.mode;
|
|
128
|
+
copy.turnOffRuleUntilEpoch = 0;
|
|
129
|
+
copy.turnOffRuleWhileOnBranch = null;
|
|
130
|
+
return copy;
|
|
131
|
+
}
|
|
132
|
+
printBanner(plan) {
|
|
133
|
+
console.log('');
|
|
134
|
+
console.log(`🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`);
|
|
135
|
+
console.log(` Mode: ${plan.mode} (committed: ${plan.committedMode})` +
|
|
136
|
+
` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +
|
|
137
|
+
' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run');
|
|
138
|
+
}
|
|
139
|
+
/** Print one count per project and return the total. */
|
|
140
|
+
printCounts(workspaceRoot, plan, scan, result) {
|
|
141
|
+
const counts = scan.countsByProject(workspaceRoot);
|
|
142
|
+
const names = plan.projects ?? Array.from(counts.keys()).sort();
|
|
143
|
+
const total = Array.from(counts.values()).reduce((sum, n) => sum + n, 0);
|
|
144
|
+
console.log('');
|
|
145
|
+
console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);
|
|
146
|
+
for (const name of names)
|
|
147
|
+
console.log(` ${name}: ${counts.get(name) ?? 0}`);
|
|
148
|
+
if (!result.success && total === 0) {
|
|
149
|
+
console.log(' (the rule failed without reporting sites — read its output above)');
|
|
30
150
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
container.bind(rule_scope_plan_1.RuleScopes).toConstantValue(planner.result());
|
|
34
|
-
return container;
|
|
151
|
+
console.log('');
|
|
152
|
+
return total;
|
|
35
153
|
}
|
|
36
154
|
}
|
|
37
155
|
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,yCAAsC;AACtC,0DAOiC;AAEjC,qEAA+D;AAC/D,6DAAuE;AACvE,uEAA4D;AAC5D,uDAAiE;AAEjE;;;;;;GAMG;AACH,MAAa,kBAAkB;IAC3B,SAAS,CAAC,aAAqB,EAAE,MAAoB,EAAE,OAA4B;QAC/E,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,2BAAY,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5G,MAAM,OAAO,GAAG,IAAI,kCAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAErD,kHAAkH;QAClH,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,SAAS,CAAC,IAAI,CAAC,kCAAa,CAAC,CAAC,eAAe,CAAC,IAAI,kCAAa,CAAC,aAAa,CAAC,CAAC,CAAC;QAChF,SAAS,CAAC,IAAI,CAAC,4CAAmB,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC7D,KAAK,MAAM,OAAO,IAAI,yCAAe,EAAE,CAAC;YACpC,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,UAAU,GAAI,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAgC,IAAI,IAAI,WAAW,EAAE,CAAC;YACvG,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAA,+BAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACzF,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,kCAAmB,CAAC,CAAC,CAAC;QAClH,SAAS,CAAC,IAAI,CAAC,qCAAgB,CAAC,CAAC,eAAe,CAAC,IAAI,qCAAgB,CAAC,UAAU,CAAC,CAAC,CAAC;QACnF,SAAS,CAAC,IAAI,CAAC,4BAAU,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AApBD,gDAoBC","sourcesContent":["import { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n LoadedConfig,\n MatchRuleConfig,\n MODIFIED_CODE_MODES,\n ProjectIndex,\n schemaModeValues,\n} from '@webpieces/rules-config';\n\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\nimport { RuleScopePlanner, RuleScopes } from './rule-scope-plan';\n\n/**\n * The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx\n * `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace\n * root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's\n * `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then\n * resolves `CodeRulesApp`, and inversify builds the entire validator DAG.\n */\nexport class CodeRulesBootstrap {\n container(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): Container {\n const roots = request.projects === null ? null : new ProjectIndex(workspaceRoot).rootsFor(request.projects);\n const planner = new RuleScopePlanner(request, roots);\n\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(CodeRulesRunRequest).toConstantValue(request);\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding[0];\n const configured = (loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined) ?? new ConfigClass();\n const planned = planner.plan(binding[1], configured, schemaModeValues(binding[1]) ?? []);\n container.bind(ConfigClass).toConstantValue(planned);\n }\n const matchRules = loaded.matchRules.map((mr: MatchRuleConfig) => planner.plan(mr.name, mr, MODIFIED_CODE_MODES));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(matchRules));\n container.bind(RuleScopes).toConstantValue(planner.result());\n return container;\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,4BAA0B;AAC1B,yCAAsC;AACtC,0DASiC;AAGjC,qDAAgD;AAChD,6DAAuE;AACvE,uEAA2E;AAC3E,qEAA8E;AAC9E,6CAAwF;AAExF,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,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,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;AAxHD,gDAwHC","sourcesContent":["import 'reflect-metadata';\nimport { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n DiffScope,\n InformAiError,\n LoadedConfig,\n MatchRuleConfig,\n MODIFIED_CODE_MODES,\n RULE_SCHEMAS,\n loadAndValidate,\n} from '@webpieces/rules-config';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS, ConfigBinding } from './code-rules-config-table';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ProjectCatalog, ProjectEntry, ScanRestriction, 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('No webpieces.config.json found at workspace root (or any ancestor).');\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 // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n container.bind(ScanRestriction).toConstantValue(new ScanRestriction(plan?.projects));\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding[0];\n const configured = loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined;\n const config = configured ?? new ConfigClass();\n container.bind(ConfigClass).toConstantValue(plan?.rule === binding[1] ? this.overridden(config, plan) : config);\n }\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(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): DebugPlan {\n const rule = request.rule;\n if (rule === undefined) throw this.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.refusal(`--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 const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';\n const mode = request.mode ?? committedMode;\n if (!modes.includes(mode) || mode === 'OFF') {\n const why = request.mode === undefined ? `its committed mode is ${committedMode}` : `--mode=${mode} is not one of its modes`;\n throw this.refusal(`${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m: string) => m !== 'OFF').join(', ')}>.`);\n }\n const unknown = (request.projects ?? []).filter((name: string) => !this.projectNames(workspaceRoot).includes(name));\n if (unknown.length > 0) {\n throw this.refusal(`--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +\n `${this.projectNames(workspaceRoot).join(', ')}.`);\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)) return MODIFIED_CODE_MODES;\n if (!CONFIG_BINDINGS.some((binding: ConfigBinding) => binding[1] === rule)) return undefined;\n const modes = RULE_SCHEMAS[rule]?.['mode']?.enumValues ?? [];\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME') ? modes : undefined;\n }\n\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CONFIG_BINDINGS.map((binding: ConfigBinding) => binding[1] 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 BaseRuleConfig | undefined;\n return configured?.mode;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope()).all(workspaceRoot).map((p: ProjectEntry) => p.name).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) => (plan?.rule === mr.name ? this.overridden(mr, plan) : mr));\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(Object.create(Object.getPrototypeOf(config) as object) as C, config);\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(`🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`);\n console.log(` 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 /** Print one count per project and return the total. */\n private printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, result: ExecutorResult): 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"]}
|
|
@@ -7,4 +7,6 @@ export type ConfigCtor = new () => BaseRuleConfig;
|
|
|
7
7
|
* new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only
|
|
8
8
|
* — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
/** One `[config class, rule key]` row of {@link CONFIG_BINDINGS}. */
|
|
11
|
+
export type ConfigBinding = readonly [ConfigCtor, keyof WebpiecesRulesConfig];
|
|
12
|
+
export declare const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding>;
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CONFIG_BINDINGS = void 0;
|
|
4
4
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
|
-
/**
|
|
6
|
-
* The 1:1 table of `[config class, webpieces.config.json rule key]`. The composition root iterates it
|
|
7
|
-
* to bind each rule's config into the container (`bind(ConfigClass).toConstantValue(config[key] ??
|
|
8
|
-
* new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only
|
|
9
|
-
* — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).
|
|
10
|
-
*/
|
|
11
5
|
exports.CONFIG_BINDINGS = [
|
|
12
6
|
[rules_config_1.MaxMethodLinesConfig, 'max-method-lines'],
|
|
13
7
|
[rules_config_1.MaxFileLinesConfig, 'max-file-lines'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AAAA,0DA6BiC;
|
|
1
|
+
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AAAA,0DA6BiC;AAcpB,QAAA,eAAe,GAAiC;IACzD,CAAC,mCAAoB,EAAE,kBAAkB,CAAC;IAC1C,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,yCAA0B,EAAE,yBAAyB,CAAC;IACvD,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,kCAAmB,EAAE,iBAAiB,CAAC;IACxC,CAAC,uCAAwB,EAAE,sBAAsB,CAAC;IAClD,CAAC,oCAAqB,EAAE,kBAAkB,CAAC;IAC3C,CAAC,kCAAmB,EAAE,gBAAgB,CAAC;IACvC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,0CAA2B,EAAE,yBAAyB,CAAC;IACxD,CAAC,iDAAkC,EAAE,mCAAmC,CAAC;IACzE,CAAC,qCAAsB,EAAE,qBAAqB,CAAC;IAC/C,CAAC,0DAA2C,EAAE,6CAA6C,CAAC;IAC5F,CAAC,gCAAiB,EAAE,eAAe,CAAC;IACpC,CAAC,4CAA6B,EAAE,6BAA6B,CAAC;IAC9D,CAAC,6CAA8B,EAAE,8BAA8B,CAAC;IAChE,CAAC,2CAA4B,EAAE,2BAA2B,CAAC;IAC3D;QACI,8DAA+C;QAC/C,iDAAiD;KACpD;IACD,CAAC,iCAAkB,EAAE,eAAe,CAAC;IACrC,CAAC,4BAAa,EAAE,UAAU,CAAC;IAC3B,CAAC,sCAAuB,EAAE,sBAAsB,CAAC;IACjD,CAAC,2CAA4B,EAAE,6BAA6B,CAAC;IAC7D,CAAC,4CAA6B,EAAE,8BAA8B,CAAC;IAC/D,CAAC,2CAA4B,EAAE,6BAA6B,CAAC;IAC7D,CAAC,uCAAwB,EAAE,sBAAsB,CAAC;CACrD,CAAC","sourcesContent":["import {\n BaseRuleConfig,\n WebpiecesRulesConfig,\n MaxMethodLinesConfig,\n MaxFileLinesConfig,\n RequireReturnTypeConfig,\n NoInlineTypeLiteralsConfig,\n NoAnyUnknownConfig,\n NoImplicitAnyConfig,\n PrismaValidateDtosConfig,\n PrismaConverterConfig,\n NoDestructureConfig,\n CatchErrorPatternConfig,\n NoUnmanagedExceptionsConfig,\n AngularNoDirectApiInResolverConfig,\n NoSymbolDiTokensConfig,\n NoClientCreationOutsideServerOrClientConfig,\n NoCustomCssConfig,\n NoStatePathsInTemplatesConfig,\n NoProcessExitOutsideMainConfig,\n NoFunctionOutsideClassConfig,\n InjectAnnotationNotNeededForConcreteClassConfig,\n FrameworkTagConfig,\n RoleTagConfig,\n EnsureWeAreSecureConfig,\n NoInlineImportInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n NoUtilityTypesInApiLibConfig,\n RequiredTypeSuffixConfig,\n} from '@webpieces/rules-config';\n\n/** A rule config class usable as an inversify inject-by-type token. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\n/**\n * The 1:1 table of `[config class, webpieces.config.json rule key]`. The composition root iterates it\n * to bind each rule's config into the container (`bind(ConfigClass).toConstantValue(config[key] ??\n * new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only\n * — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).\n */\n/** One `[config class, rule key]` row of {@link CONFIG_BINDINGS}. */\nexport type ConfigBinding = readonly [ConfigCtor, keyof WebpiecesRulesConfig];\n\nexport const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding> = [\n [MaxMethodLinesConfig, 'max-method-lines'],\n [MaxFileLinesConfig, 'max-file-lines'],\n [RequireReturnTypeConfig, 'require-return-type'],\n [NoInlineTypeLiteralsConfig, 'no-inline-type-literals'],\n [NoAnyUnknownConfig, 'no-any-unknown'],\n [NoImplicitAnyConfig, 'no-implicit-any'],\n [PrismaValidateDtosConfig, 'prisma-validate-dtos'],\n [PrismaConverterConfig, 'prisma-converter'],\n [NoDestructureConfig, 'no-destructure'],\n [CatchErrorPatternConfig, 'catch-error-pattern'],\n [NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions'],\n [AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver'],\n [NoSymbolDiTokensConfig, 'no-symbol-di-tokens'],\n [NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client'],\n [NoCustomCssConfig, 'no-custom-css'],\n [NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates'],\n [NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main'],\n [NoFunctionOutsideClassConfig, 'no-function-outside-class'],\n [\n InjectAnnotationNotNeededForConcreteClassConfig,\n 'inject-annotation-not-needed-for-concrete-class',\n ],\n [FrameworkTagConfig, 'framework-tag'],\n [RoleTagConfig, 'role-tag'],\n [EnsureWeAreSecureConfig, 'ensure-we-are-secure'],\n [NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib'],\n [OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib'],\n [NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib'],\n [RequiredTypeSuffixConfig, 'required-type-suffix'],\n];\n"]}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { DiffScope } from '@webpieces/rules-config';
|
|
2
1
|
import { ExecutorResult } from './code-validator';
|
|
3
2
|
import { RuleReporter } from './rule-reporter';
|
|
4
3
|
import { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';
|
|
5
|
-
import {
|
|
6
|
-
import { DebugRunReport } from './debug-run-report';
|
|
7
|
-
import { RuleScopes } from './rule-scope-plan';
|
|
4
|
+
import { RuleSelection } from './code-rules-run-request';
|
|
8
5
|
import { MatchRulesChecker } from './validate-match-rules';
|
|
9
6
|
import { MaxMethodLinesValidator } from './validate-modified-methods';
|
|
10
7
|
import { MaxFileLinesValidator } from './validate-modified-files';
|
|
@@ -43,10 +40,7 @@ export declare class CodeRulesEngine {
|
|
|
43
40
|
private readonly reporter;
|
|
44
41
|
private readonly matchRules;
|
|
45
42
|
private readonly matchChecker;
|
|
46
|
-
private readonly
|
|
47
|
-
private readonly scopes;
|
|
48
|
-
private readonly debugReport;
|
|
49
|
-
private readonly diffScope;
|
|
43
|
+
private readonly selection;
|
|
50
44
|
private readonly maxMethodLines;
|
|
51
45
|
private readonly maxFileLines;
|
|
52
46
|
private readonly requireReturnType;
|
|
@@ -73,19 +67,16 @@ export declare class CodeRulesEngine {
|
|
|
73
67
|
private readonly oneEnumSpellingInApiLib;
|
|
74
68
|
private readonly noUtilityTypesInApiLib;
|
|
75
69
|
private readonly requiredTypeSuffix;
|
|
76
|
-
constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker,
|
|
70
|
+
constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, selection: RuleSelection, maxMethodLines: MaxMethodLinesValidator, maxFileLines: MaxFileLinesValidator, requireReturnType: RequireReturnTypeValidator, noInlineTypeLiterals: NoInlineTypeLiteralsValidator, noAnyUnknown: NoAnyUnknownValidator, noImplicitAny: NoImplicitAnyValidator, prismaValidateDtos: PrismaValidateDtosValidator, prismaConverter: PrismaConverterValidator, noDestructure: NoDestructureValidator, catchErrorPattern: CatchErrorPatternValidator, noUnmanagedExceptions: NoUnmanagedExceptionsValidator, noDirectApiResolver: NoDirectApiResolverValidator, noSymbolDiTokens: NoSymbolDiTokensValidator, noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator, noCustomCss: NoCustomCssValidator, noStatePathsInTemplates: NoStatePathsInTemplatesValidator, noProcessExitOutsideMain: NoProcessExitOutsideMainValidator, noFunctionOutsideClass: NoFunctionOutsideClassValidator, injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator, frameworkTag: FrameworkTagValidator, roleTag: RoleTagValidator, ensureWeAreSecure: EnsureWeAreSecureValidator, noInlineImportInApiLib: NoInlineImportInApiLibValidator, oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator, noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator, requiredTypeSuffix: RequiredTypeSuffixValidator);
|
|
77
71
|
/** The injected built-in validators, in run order. */
|
|
78
72
|
private builtIns;
|
|
79
73
|
/**
|
|
80
74
|
* Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected
|
|
81
75
|
* match-rule check per configured entry that is active. Built as {@link RuleRun} value objects
|
|
82
76
|
* (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.
|
|
77
|
+
* A debug run (#1027) narrows the set to the one rule its {@link RuleSelection} names.
|
|
83
78
|
*/
|
|
84
79
|
private activeRuns;
|
|
85
|
-
/** The gate runs every rule; a debug run only the one it names. */
|
|
86
|
-
private selected;
|
|
87
|
-
/** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */
|
|
88
|
-
private scoped;
|
|
89
80
|
/**
|
|
90
81
|
* Run all configured code validators against the workspace. A validator runs only when
|
|
91
82
|
* `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives
|