@webpieces/code-rules 0.4.813 → 0.4.815
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 +10 -5
- package/src/api-lib-source-rule.js +13 -4
- package/src/api-lib-source-rule.js.map +1 -1
- package/src/cli.js +6 -14
- package/src/cli.js.map +1 -1
- package/src/code-rules-bootstrap.d.ts +13 -0
- package/src/code-rules-bootstrap.js +38 -0
- package/src/code-rules-bootstrap.js.map +1 -0
- package/src/code-rules-config-table.js +1 -0
- package/src/code-rules-config-table.js.map +1 -1
- package/src/code-rules-engine.d.ts +15 -1
- package/src/code-rules-engine.js +38 -6
- package/src/code-rules-engine.js.map +1 -1
- package/src/code-rules-run-request.d.ts +41 -0
- package/src/code-rules-run-request.js +103 -0
- package/src/code-rules-run-request.js.map +1 -0
- package/src/debug-run-report.d.ts +22 -0
- package/src/debug-run-report.js +127 -0
- package/src/debug-run-report.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +7 -1
- package/src/index.js.map +1 -1
- package/src/rule-scope-plan.d.ts +72 -0
- package/src/rule-scope-plan.js +132 -0
- package/src/rule-scope-plan.js.map +1 -0
- package/src/validate-code.d.ts +7 -7
- package/src/validate-code.js +11 -20
- package/src/validate-code.js.map +1 -1
- package/src/validate-no-custom-css.d.ts +2 -1
- package/src/validate-no-custom-css.js +2 -1
- package/src/validate-no-custom-css.js.map +1 -1
- package/src/validate-no-state-paths-in-templates.d.ts +2 -1
- package/src/validate-no-state-paths-in-templates.js +2 -1
- package/src/validate-no-state-paths-in-templates.js.map +1 -1
- package/src/validate-no-utility-types-in-api-lib.d.ts +58 -0
- package/src/validate-no-utility-types-in-api-lib.js +176 -0
- package/src/validate-no-utility-types-in-api-lib.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.815",
|
|
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.815",
|
|
20
20
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The shared half of the two `role:api-lib` spelling rules (#1023)
|
|
3
|
-
* `one-enum-spelling-in-api-lib
|
|
2
|
+
* The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),
|
|
3
|
+
* `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, and `no-utility-types-in-api-lib`
|
|
4
|
+
* (#1026), which scopes itself by its configured `paths` globs instead of the role tag.
|
|
4
5
|
*
|
|
5
6
|
* Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP
|
|
6
7
|
* generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
* what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.
|
|
14
15
|
*/
|
|
15
16
|
import * as ts from 'typescript';
|
|
16
|
-
import { DiffScope, NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from '@webpieces/rules-config';
|
|
17
|
+
import { DiffScope, NoInlineImportInApiLibConfig, NoUtilityTypesInApiLibConfig, OneEnumSpellingInApiLibConfig } from '@webpieces/rules-config';
|
|
17
18
|
import { CodeValidator, ExecutorResult } from './code-validator';
|
|
18
19
|
import { ProjectRoleResolver } from './project-role-resolver';
|
|
19
20
|
/** One violating site: where, what it is, and the edit that replaces it. Data-only. */
|
|
@@ -47,7 +48,7 @@ export declare class ApiLibFile {
|
|
|
47
48
|
/** A site at `node`, its text collapsed to one line. */
|
|
48
49
|
site(node: ts.Node, what: string, cure: string): ApiLibSite;
|
|
49
50
|
}
|
|
50
|
-
type ApiLibConfig = NoInlineImportInApiLibConfig | OneEnumSpellingInApiLibConfig;
|
|
51
|
+
type ApiLibConfig = NoInlineImportInApiLibConfig | OneEnumSpellingInApiLibConfig | NoUtilityTypesInApiLibConfig;
|
|
51
52
|
export declare abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {
|
|
52
53
|
private readonly roleResolver;
|
|
53
54
|
private readonly diffScope;
|
|
@@ -59,8 +60,12 @@ export declare abstract class ApiLibSourceRule<C extends ApiLibConfig> extends C
|
|
|
59
60
|
run(workspaceRoot: string): Promise<ExecutorResult>;
|
|
60
61
|
/** The unexempt, in-scope violating sites of one changed file. */
|
|
61
62
|
private judge;
|
|
62
|
-
/** A non-test `.ts` file, not under `allowedPaths`,
|
|
63
|
+
/** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */
|
|
63
64
|
private inScope;
|
|
65
|
+
/** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */
|
|
66
|
+
protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean;
|
|
67
|
+
/** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */
|
|
68
|
+
protected scopeLabel(): string;
|
|
64
69
|
/** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */
|
|
65
70
|
private disabled;
|
|
66
71
|
/** The nearest ancestor of `relFile` holding a project.json, absolute. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* The shared half of the two `role:api-lib` spelling rules (#1023)
|
|
4
|
-
* `one-enum-spelling-in-api-lib
|
|
3
|
+
* The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),
|
|
4
|
+
* `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, and `no-utility-types-in-api-lib`
|
|
5
|
+
* (#1026), which scopes itself by its configured `paths` globs instead of the role tag.
|
|
5
6
|
*
|
|
6
7
|
* Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP
|
|
7
8
|
* generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the
|
|
@@ -121,7 +122,7 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
|
121
122
|
.filter((site) => !this.disabled(lines, site.line))
|
|
122
123
|
.map((site) => new FoundSite(relFile, site));
|
|
123
124
|
}
|
|
124
|
-
/** A non-test `.ts` file, not under `allowedPaths`,
|
|
125
|
+
/** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */
|
|
125
126
|
inScope(workspaceRoot, relFile) {
|
|
126
127
|
if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts'))
|
|
127
128
|
return false;
|
|
@@ -131,8 +132,16 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
|
131
132
|
return false;
|
|
132
133
|
if (!fs.existsSync(path.join(workspaceRoot, relFile)))
|
|
133
134
|
return false;
|
|
135
|
+
return this.isApiLibrarySource(workspaceRoot, relFile);
|
|
136
|
+
}
|
|
137
|
+
/** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */
|
|
138
|
+
isApiLibrarySource(workspaceRoot, relFile) {
|
|
134
139
|
return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;
|
|
135
140
|
}
|
|
141
|
+
/** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */
|
|
142
|
+
scopeLabel() {
|
|
143
|
+
return 'a role:api-lib project';
|
|
144
|
+
}
|
|
136
145
|
/** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */
|
|
137
146
|
disabled(lines, line) {
|
|
138
147
|
return (0, rules_config_1.hasDisable)(lines[line - 1] ?? '', this.name) || (0, rules_config_1.hasDisable)(lines[line - 2] ?? '', this.name);
|
|
@@ -146,7 +155,7 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
|
146
155
|
return dir;
|
|
147
156
|
}
|
|
148
157
|
failure(found) {
|
|
149
|
-
const message = `${found.length} site(s) in
|
|
158
|
+
const message = `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\n` +
|
|
150
159
|
found.map((each) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\n ${each.site.snippet}`).join('\n') +
|
|
151
160
|
`\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;
|
|
152
161
|
return new rules_config_1.RuleFailError(this.name, message, undefined, undefined, found.map((each) => new rules_config_1.Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)));
|
|
@@ -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;;;;;;;;;;;;;GAaG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DASiC;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,WAA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AAI,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChI,mDAAmD,IAAI,CAAC,IAAI,cAAc,CAAC;QAC/E,OAAO,IAAI,4BAAa,CACpB,IAAI,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;AA9FD,4CA8FC","sourcesContent":["/**\n * The shared half of the two `role:api-lib` spelling rules (#1023): `no-inline-import-in-api-lib` and\n * `one-enum-spelling-in-api-lib`.\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 OneEnumSpellingInApiLibConfig,\n Option,\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 = NoInlineImportInApiLibConfig | OneEnumSpellingInApiLibConfig;\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`, owned by a `role:api-lib` project. */\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.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\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 a role:api-lib project: ${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;;;;;;;;;;;;;;GAcG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAUiC;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,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f,CAAC;IAEO,OAAO,CAAC,KAA2B;QACvC,MAAM,OAAO,GACT,GAAG,KAAK,CAAC,MAAM,eAAe,IAAI,CAAC,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,IAAI;YAClE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChI,mDAAmD,IAAI,CAAC,IAAI,cAAc,CAAC;QAC/E,OAAO,IAAI,4BAAa,CACpB,IAAI,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`, and `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag.\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 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 = NoInlineImportInApiLibConfig | OneEnumSpellingInApiLibConfig | NoUtilityTypesInApiLibConfig;\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"]}
|
package/src/cli.js
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
require("reflect-metadata");
|
|
5
|
-
const inversify_1 = require("inversify");
|
|
6
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
6
|
const code_rules_app_1 = require("./code-rules-app");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const code_rules_bootstrap_1 = require("./code-rules-bootstrap");
|
|
8
|
+
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
10
9
|
async function main() {
|
|
11
10
|
// webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI
|
|
12
11
|
try {
|
|
@@ -19,17 +18,10 @@ async function main() {
|
|
|
19
18
|
process.exit(1);
|
|
20
19
|
}
|
|
21
20
|
console.log(`\n📄 Loaded config: ${loaded.configPath}`);
|
|
22
|
-
// Composition root:
|
|
23
|
-
// inversify
|
|
24
|
-
|
|
25
|
-
const container = new
|
|
26
|
-
container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
|
|
27
|
-
container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(loaded.matchRules));
|
|
28
|
-
for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
|
|
29
|
-
const ConfigClass = binding[0];
|
|
30
|
-
const configured = loaded.rulesConfig[binding[1]];
|
|
31
|
-
container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());
|
|
32
|
-
}
|
|
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);
|
|
33
25
|
const app = container.get(code_rules_app_1.CodeRulesApp);
|
|
34
26
|
const result = await app.run();
|
|
35
27
|
process.exit(result.success ? 0 : 1);
|
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,0DAAyI;AAEzI,qDAAgD;AAChD,iEAA4D;AAC5D,qEAAqE;AAErE,KAAK,UAAU,IAAI;IACf,qFAAqF;IACrF,IAAI,CAAC;QACD,8FAA8F;QAC9F,6CAA6C;QAC7C,MAAM,aAAa,GAAG,IAAI,6BAAc,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;YAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,2FAA2F;QAC3F,sFAAsF;QACtF,MAAM,OAAO,GAAG,IAAI,kDAAyB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAChF,MAAM,SAAS,GAAG,IAAI,yCAAkB,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACrF,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,6BAAY,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;QAC/B,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,4BAAa,EAAE,CAAC;YACjC,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 { InformAiError, RuleFailError, renderRuleFailForHuman, toError, loadAndValidate, RepoRootFinder } from '@webpieces/rules-config';\n\nimport { CodeRulesApp } from './code-rules-app';\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { CodeRulesRunRequestParser } from './code-rules-run-request';\n\nasync function main(): Promise<void> {\n // webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI\n try {\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 loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.error('\\n❌ No webpieces.config.json found at workspace root (or any ancestor).\\n');\n process.exit(1);\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n // Composition root: the shared bootstrap binds the runtime values (workspace root, the run\n // request, each rule's planned config) and inversify builds the ENTIRE validator DAG.\n const request = new CodeRulesRunRequestParser().fromArgv(process.argv.slice(2));\n const container = new CodeRulesBootstrap().container(workspaceRoot, loaded, request);\n const app = container.get(CodeRulesApp);\n const result = await app.run();\n process.exit(result.success ? 0 : 1);\n } catch (err: unknown) {\n const error = toError(err);\n 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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Container } from 'inversify';
|
|
2
|
+
import { LoadedConfig } from '@webpieces/rules-config';
|
|
3
|
+
import { CodeRulesRunRequest } from './code-rules-run-request';
|
|
4
|
+
/**
|
|
5
|
+
* The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx
|
|
6
|
+
* `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace
|
|
7
|
+
* root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's
|
|
8
|
+
* `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then
|
|
9
|
+
* resolves `CodeRulesApp`, and inversify builds the entire validator DAG.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CodeRulesBootstrap {
|
|
12
|
+
container(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): Container;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeRulesBootstrap = void 0;
|
|
4
|
+
const inversify_1 = require("inversify");
|
|
5
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
7
|
+
const code_rules_context_1 = require("./code-rules-context");
|
|
8
|
+
const code_rules_config_table_1 = require("./code-rules-config-table");
|
|
9
|
+
const rule_scope_plan_1 = require("./rule-scope-plan");
|
|
10
|
+
/**
|
|
11
|
+
* The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx
|
|
12
|
+
* `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace
|
|
13
|
+
* root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's
|
|
14
|
+
* `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then
|
|
15
|
+
* resolves `CodeRulesApp`, and inversify builds the entire validator DAG.
|
|
16
|
+
*/
|
|
17
|
+
class CodeRulesBootstrap {
|
|
18
|
+
container(workspaceRoot, loaded, request) {
|
|
19
|
+
const roots = request.projects === null ? null : new rules_config_1.ProjectIndex(workspaceRoot).rootsFor(request.projects);
|
|
20
|
+
const planner = new rule_scope_plan_1.RuleScopePlanner(request, roots);
|
|
21
|
+
// autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
|
|
22
|
+
const container = new inversify_1.Container({ autobind: true });
|
|
23
|
+
container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
|
|
24
|
+
container.bind(code_rules_run_request_1.CodeRulesRunRequest).toConstantValue(request);
|
|
25
|
+
for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
|
|
26
|
+
const ConfigClass = binding[0];
|
|
27
|
+
const configured = loaded.rulesConfig[binding[1]] ?? new ConfigClass();
|
|
28
|
+
const planned = planner.plan(binding[1], configured, (0, rules_config_1.schemaModeValues)(binding[1]) ?? []);
|
|
29
|
+
container.bind(ConfigClass).toConstantValue(planned);
|
|
30
|
+
}
|
|
31
|
+
const matchRules = loaded.matchRules.map((mr) => planner.plan(mr.name, mr, rules_config_1.MODIFIED_CODE_MODES));
|
|
32
|
+
container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(matchRules));
|
|
33
|
+
container.bind(rule_scope_plan_1.RuleScopes).toConstantValue(planner.result());
|
|
34
|
+
return container;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.CodeRulesBootstrap = CodeRulesBootstrap;
|
|
38
|
+
//# sourceMappingURL=code-rules-bootstrap.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -36,5 +36,6 @@ exports.CONFIG_BINDINGS = [
|
|
|
36
36
|
[rules_config_1.EnsureWeAreSecureConfig, 'ensure-we-are-secure'],
|
|
37
37
|
[rules_config_1.NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib'],
|
|
38
38
|
[rules_config_1.OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib'],
|
|
39
|
+
[rules_config_1.NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib'],
|
|
39
40
|
];
|
|
40
41
|
//# sourceMappingURL=code-rules-config-table.js.map
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AAAA,0DA4BiC;AAKjC;;;;;GAKG;AACU,QAAA,eAAe,GAAqE;IAC7F,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;CAChE,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} 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 */\nexport const CONFIG_BINDINGS: ReadonlyArray<readonly [ConfigCtor, keyof WebpiecesRulesConfig]> = [\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];\n"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { DiffScope } from '@webpieces/rules-config';
|
|
1
2
|
import { ExecutorResult } from './code-validator';
|
|
2
3
|
import { RuleReporter } from './rule-reporter';
|
|
3
4
|
import { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';
|
|
5
|
+
import { CodeRulesRunRequest } from './code-rules-run-request';
|
|
6
|
+
import { DebugRunReport } from './debug-run-report';
|
|
7
|
+
import { RuleScopes } from './rule-scope-plan';
|
|
4
8
|
import { MatchRulesChecker } from './validate-match-rules';
|
|
5
9
|
import { MaxMethodLinesValidator } from './validate-modified-methods';
|
|
6
10
|
import { MaxFileLinesValidator } from './validate-modified-files';
|
|
@@ -26,6 +30,7 @@ import { RoleTagValidator } from './validate-role-tag';
|
|
|
26
30
|
import { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';
|
|
27
31
|
import { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';
|
|
28
32
|
import { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';
|
|
33
|
+
import { NoUtilityTypesInApiLibValidator } from './validate-no-utility-types-in-api-lib';
|
|
29
34
|
/**
|
|
30
35
|
* Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config
|
|
31
36
|
* is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph
|
|
@@ -37,6 +42,10 @@ export declare class CodeRulesEngine {
|
|
|
37
42
|
private readonly reporter;
|
|
38
43
|
private readonly matchRules;
|
|
39
44
|
private readonly matchChecker;
|
|
45
|
+
private readonly request;
|
|
46
|
+
private readonly scopes;
|
|
47
|
+
private readonly debugReport;
|
|
48
|
+
private readonly diffScope;
|
|
40
49
|
private readonly maxMethodLines;
|
|
41
50
|
private readonly maxFileLines;
|
|
42
51
|
private readonly requireReturnType;
|
|
@@ -61,7 +70,8 @@ export declare class CodeRulesEngine {
|
|
|
61
70
|
private readonly ensureWeAreSecure;
|
|
62
71
|
private readonly noInlineImportInApiLib;
|
|
63
72
|
private readonly oneEnumSpellingInApiLib;
|
|
64
|
-
|
|
73
|
+
private readonly noUtilityTypesInApiLib;
|
|
74
|
+
constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, request: CodeRulesRunRequest, scopes: RuleScopes, debugReport: DebugRunReport, diffScope: DiffScope, 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);
|
|
65
75
|
/** The injected built-in validators, in run order. */
|
|
66
76
|
private builtIns;
|
|
67
77
|
/**
|
|
@@ -70,6 +80,10 @@ export declare class CodeRulesEngine {
|
|
|
70
80
|
* (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.
|
|
71
81
|
*/
|
|
72
82
|
private activeRuns;
|
|
83
|
+
/** The gate runs every rule; a debug run only the one it names. */
|
|
84
|
+
private selected;
|
|
85
|
+
/** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */
|
|
86
|
+
private scoped;
|
|
73
87
|
/**
|
|
74
88
|
* Run all configured code validators against the workspace. A validator runs only when
|
|
75
89
|
* `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives
|
package/src/code-rules-engine.js
CHANGED
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CodeRulesEngine = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
6
|
const inversify_1 = require("inversify");
|
|
6
7
|
const code_validator_1 = require("./code-validator");
|
|
7
8
|
const rule_reporter_1 = require("./rule-reporter");
|
|
8
9
|
const code_rules_context_1 = require("./code-rules-context");
|
|
10
|
+
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
11
|
+
const debug_run_report_1 = require("./debug-run-report");
|
|
12
|
+
const rule_scope_plan_1 = require("./rule-scope-plan");
|
|
9
13
|
const validate_match_rules_1 = require("./validate-match-rules");
|
|
10
14
|
const validate_modified_methods_1 = require("./validate-modified-methods");
|
|
11
15
|
const validate_modified_files_1 = require("./validate-modified-files");
|
|
@@ -31,6 +35,7 @@ const validate_role_tag_1 = require("./validate-role-tag");
|
|
|
31
35
|
const validate_ensure_we_are_secure_1 = require("./validate-ensure-we-are-secure");
|
|
32
36
|
const validate_no_inline_import_in_api_lib_1 = require("./validate-no-inline-import-in-api-lib");
|
|
33
37
|
const validate_one_enum_spelling_in_api_lib_1 = require("./validate-one-enum-spelling-in-api-lib");
|
|
38
|
+
const validate_no_utility_types_in_api_lib_1 = require("./validate-no-utility-types-in-api-lib");
|
|
34
39
|
/**
|
|
35
40
|
* Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config
|
|
36
41
|
* is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph
|
|
@@ -42,6 +47,10 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
42
47
|
reporter;
|
|
43
48
|
matchRules;
|
|
44
49
|
matchChecker;
|
|
50
|
+
request;
|
|
51
|
+
scopes;
|
|
52
|
+
debugReport;
|
|
53
|
+
diffScope;
|
|
45
54
|
maxMethodLines;
|
|
46
55
|
maxFileLines;
|
|
47
56
|
requireReturnType;
|
|
@@ -66,12 +75,17 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
66
75
|
ensureWeAreSecure;
|
|
67
76
|
noInlineImportInApiLib;
|
|
68
77
|
oneEnumSpellingInApiLib;
|
|
78
|
+
noUtilityTypesInApiLib;
|
|
69
79
|
// webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field
|
|
70
|
-
constructor(workspace, reporter, matchRules, matchChecker, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure, noInlineImportInApiLib, oneEnumSpellingInApiLib) {
|
|
80
|
+
constructor(workspace, reporter, matchRules, matchChecker, request, scopes, debugReport, diffScope, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure, noInlineImportInApiLib, oneEnumSpellingInApiLib, noUtilityTypesInApiLib) {
|
|
71
81
|
this.workspace = workspace;
|
|
72
82
|
this.reporter = reporter;
|
|
73
83
|
this.matchRules = matchRules;
|
|
74
84
|
this.matchChecker = matchChecker;
|
|
85
|
+
this.request = request;
|
|
86
|
+
this.scopes = scopes;
|
|
87
|
+
this.debugReport = debugReport;
|
|
88
|
+
this.diffScope = diffScope;
|
|
75
89
|
this.maxMethodLines = maxMethodLines;
|
|
76
90
|
this.maxFileLines = maxFileLines;
|
|
77
91
|
this.requireReturnType = requireReturnType;
|
|
@@ -96,6 +110,7 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
96
110
|
this.ensureWeAreSecure = ensureWeAreSecure;
|
|
97
111
|
this.noInlineImportInApiLib = noInlineImportInApiLib;
|
|
98
112
|
this.oneEnumSpellingInApiLib = oneEnumSpellingInApiLib;
|
|
113
|
+
this.noUtilityTypesInApiLib = noUtilityTypesInApiLib;
|
|
99
114
|
}
|
|
100
115
|
/** The injected built-in validators, in run order. */
|
|
101
116
|
builtIns() {
|
|
@@ -124,6 +139,7 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
124
139
|
this.ensureWeAreSecure,
|
|
125
140
|
this.noInlineImportInApiLib,
|
|
126
141
|
this.oneEnumSpellingInApiLib,
|
|
142
|
+
this.noUtilityTypesInApiLib,
|
|
127
143
|
];
|
|
128
144
|
}
|
|
129
145
|
/**
|
|
@@ -134,15 +150,23 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
134
150
|
activeRuns(root) {
|
|
135
151
|
const runs = [];
|
|
136
152
|
for (const v of this.builtIns()) {
|
|
137
|
-
if (v.shouldRun())
|
|
138
|
-
runs.push(new code_validator_1.RuleRun(v.name, () => v.run(root)));
|
|
153
|
+
if (this.selected(v.configKey) && v.shouldRun())
|
|
154
|
+
runs.push(new code_validator_1.RuleRun(v.name, () => this.scoped(this.scopes.of(v.configKey), () => v.run(root))));
|
|
139
155
|
}
|
|
140
156
|
for (const mr of this.matchRules.rules) {
|
|
141
|
-
if (this.matchChecker.shouldRun(mr))
|
|
142
|
-
runs.push(new code_validator_1.RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));
|
|
157
|
+
if (this.selected(mr.name) && this.matchChecker.shouldRun(mr))
|
|
158
|
+
runs.push(new code_validator_1.RuleRun(mr.name, () => this.scoped(this.scopes.of(mr.name), () => this.matchChecker.runForConfig(mr, root))));
|
|
143
159
|
}
|
|
144
160
|
return runs;
|
|
145
161
|
}
|
|
162
|
+
/** The gate runs every rule; a debug run only the one it names. */
|
|
163
|
+
selected(key) {
|
|
164
|
+
return this.request.rule === null || this.request.rule === key;
|
|
165
|
+
}
|
|
166
|
+
/** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */
|
|
167
|
+
scoped(scope, work) {
|
|
168
|
+
return this.diffScope.within(scope, work);
|
|
169
|
+
}
|
|
146
170
|
/**
|
|
147
171
|
* Run all configured code validators against the workspace. A validator runs only when
|
|
148
172
|
* `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives
|
|
@@ -150,6 +174,9 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
150
174
|
*/
|
|
151
175
|
async run() {
|
|
152
176
|
const runs = this.activeRuns(this.workspace.path);
|
|
177
|
+
const target = this.scopes.debugTarget;
|
|
178
|
+
if (target !== null)
|
|
179
|
+
return this.debugReport.run(this.workspace.path, runs, target);
|
|
153
180
|
if (runs.length === 0) {
|
|
154
181
|
console.log('\n⏭️ Skipping all code validations (all modes: OFF)\n');
|
|
155
182
|
return { success: true };
|
|
@@ -171,6 +198,10 @@ exports.CodeRulesEngine = CodeRulesEngine = tslib_1.__decorate([
|
|
|
171
198
|
rule_reporter_1.RuleReporter,
|
|
172
199
|
code_rules_context_1.MatchRulesHolder,
|
|
173
200
|
validate_match_rules_1.MatchRulesChecker,
|
|
201
|
+
code_rules_run_request_1.CodeRulesRunRequest,
|
|
202
|
+
rule_scope_plan_1.RuleScopes,
|
|
203
|
+
debug_run_report_1.DebugRunReport,
|
|
204
|
+
rules_config_1.DiffScope,
|
|
174
205
|
validate_modified_methods_1.MaxMethodLinesValidator,
|
|
175
206
|
validate_modified_files_1.MaxFileLinesValidator,
|
|
176
207
|
validate_return_types_1.RequireReturnTypeValidator,
|
|
@@ -194,6 +225,7 @@ exports.CodeRulesEngine = CodeRulesEngine = tslib_1.__decorate([
|
|
|
194
225
|
validate_role_tag_1.RoleTagValidator,
|
|
195
226
|
validate_ensure_we_are_secure_1.EnsureWeAreSecureValidator,
|
|
196
227
|
validate_no_inline_import_in_api_lib_1.NoInlineImportInApiLibValidator,
|
|
197
|
-
validate_one_enum_spelling_in_api_lib_1.OneEnumSpellingInApiLibValidator
|
|
228
|
+
validate_one_enum_spelling_in_api_lib_1.OneEnumSpellingInApiLibValidator,
|
|
229
|
+
validate_no_utility_types_in_api_lib_1.NoUtilityTypesInApiLibValidator])
|
|
198
230
|
], CodeRulesEngine);
|
|
199
231
|
//# sourceMappingURL=code-rules-engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AACA,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,uEA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U,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CACP,MAAM,CAAC,OAAO;YACV,CAAC,CAAC,mCAAmC;YACrC,CAAC,CAAC,oCAAoC,CAC7C,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AAxGY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIL,kCAAa;QACd,4BAAY;QACV,qCAAgB;QACd,wCAAiB;QACf,mDAAuB;QACzB,+CAAqB;QAChB,kDAA0B;QACvB,wDAA6B;QACrC,+CAAqB;QACpB,iDAAsB;QACjB,2CAA2B;QAC9B,qDAAwB;QAC1B,gDAAsB;QAClB,yDAA0B;QACtB,iEAA8B;QAChC,8DAA4B;QAC/B,wDAAyB;QACJ,qGAA8C;QACxE,6CAAoB;QACR,uEAAgC;QAC/B,yEAAiC;QACnC,oEAA+B;QAC5B,6GAAkD;QAC/D,8CAAqB;QAC1B,oCAAgB;QACN,0DAA0B;QACrB,sEAA+B;QAC9B,wEAAgC;GA9BrE,eAAe,CAwG3B","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\nimport { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';\nimport { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n private readonly noInlineImportInApiLib: NoInlineImportInApiLibValidator,\n private readonly oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n this.noInlineImportInApiLib,\n this.oneEnumSpellingInApiLib,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (v.shouldRun()) runs.push(new RuleRun(v.name, () => v.run(root)));\n }\n for (const mr of this.matchRules.rules) {\n if (this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));\n }\n return runs;\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n if (runs.length === 0) {\n console.log('\\n⏭️ Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\n✅ All code validations passed\\n'\n : '\\n❌ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AAAA,0DAA+E;AAC/E,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,qEAA+D;AAC/D,yDAAoD;AACpD,uDAA+C;AAC/C,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,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CAAC,CAAC;QAC/E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CACP,MAAM,CAAC,OAAO;YACV,CAAC,CAAC,mCAAmC;YACrC,CAAC,CAAC,oCAAoC,CAC7C,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AA3HY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIL,kCAAa;QACd,4BAAY;QACV,qCAAgB;QACd,wCAAiB;QACtB,4CAAmB;QACpB,4BAAU;QACL,iCAAc;QAChB,wBAAS;QACJ,mDAAuB;QACzB,+CAAqB;QAChB,kDAA0B;QACvB,wDAA6B;QACrC,+CAAqB;QACpB,iDAAsB;QACjB,2CAA2B;QAC9B,qDAAwB;QAC1B,gDAAsB;QAClB,yDAA0B;QACtB,iEAA8B;QAChC,8DAA4B;QAC/B,wDAAyB;QACJ,qGAA8C;QACxE,6CAAoB;QACR,uEAAgC;QAC/B,yEAAiC;QACnC,oEAA+B;QAC5B,6GAAkD;QAC/D,8CAAqB;QAC1B,oCAAgB;QACN,0DAA0B;QACrB,sEAA+B;QAC9B,wEAAgC;QACjC,sEAA+B;GAnCnE,eAAe,CA2H3B","sourcesContent":["import { BaseRuleConfig, DiffScope, FileScope } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { DebugRunReport } from './debug-run-report';\nimport { RuleScopes } from './rule-scope-plan';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\nimport { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';\nimport { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';\nimport { NoUtilityTypesInApiLibValidator } from './validate-no-utility-types-in-api-lib';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly request: CodeRulesRunRequest,\n private readonly scopes: RuleScopes,\n private readonly debugReport: DebugRunReport,\n private readonly diffScope: DiffScope,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n private readonly noInlineImportInApiLib: NoInlineImportInApiLibValidator,\n private readonly oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator,\n private readonly noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n this.noInlineImportInApiLib,\n this.oneEnumSpellingInApiLib,\n this.noUtilityTypesInApiLib,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (this.selected(v.configKey) && v.shouldRun())\n runs.push(new RuleRun(v.name, () => this.scoped(this.scopes.of(v.configKey), () => v.run(root))));\n }\n for (const mr of this.matchRules.rules) {\n if (this.selected(mr.name) && this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.scoped(this.scopes.of(mr.name), () => this.matchChecker.runForConfig(mr, root))));\n }\n return runs;\n }\n\n /** The gate runs every rule; a debug run only the one it names. */\n private selected(key: string): boolean {\n return this.request.rule === null || this.request.rule === key;\n }\n\n /** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */\n private scoped(scope: FileScope, work: () => Promise<ExecutorResult>): Promise<ExecutorResult> {\n return this.diffScope.within(scope, work);\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n const target = this.scopes.debugTarget;\n if (target !== null) return this.debugReport.run(this.workspace.path, runs, target);\n if (runs.length === 0) {\n console.log('\\n⏭️ Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\n✅ All code validations passed\\n'\n : '\\n❌ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
|