@webpieces/code-rules 0.4.926 → 0.4.928
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/api-lib-source-rule.d.ts +1 -1
- package/src/api-lib-source-rule.js +1 -3
- package/src/api-lib-source-rule.js.map +1 -1
- package/src/code-policy-composition.js +10 -1
- package/src/code-policy-composition.js.map +1 -1
- package/src/code-rules-bootstrap.js +1 -1
- package/src/code-rules-bootstrap.js.map +1 -1
- package/src/code-rules-engine.d.ts +3 -1
- package/src/code-rules-engine.js +13 -4
- package/src/code-rules-engine.js.map +1 -1
- package/src/configs/api-lib-spelling-configs.d.ts +2 -4
- package/src/configs/api-lib-spelling-configs.js +2 -8
- package/src/configs/api-lib-spelling-configs.js.map +1 -1
- package/src/configs/no-client-creation-config.d.ts +0 -1
- package/src/configs/no-client-creation-config.js +1 -4
- package/src/configs/no-client-creation-config.js.map +1 -1
- package/src/configs/no-state-paths-config.js +0 -1
- package/src/configs/no-state-paths-config.js.map +1 -1
- package/src/configs/no-utility-types-config.d.ts +1 -2
- package/src/configs/no-utility-types-config.js +1 -4
- package/src/configs/no-utility-types-config.js.map +1 -1
- package/src/configs/required-type-suffix-config.d.ts +1 -2
- package/src/configs/required-type-suffix-config.js +1 -4
- package/src/configs/required-type-suffix-config.js.map +1 -1
- package/src/configs/rule-configs.d.ts +0 -5
- package/src/configs/rule-configs.js +13 -44
- package/src/configs/rule-configs.js.map +1 -1
- package/src/configs/tag-truth-configs.d.ts +4 -2
- package/src/configs/tag-truth-configs.js +4 -4
- package/src/configs/tag-truth-configs.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +7 -2
- package/src/index.js.map +1 -1
- package/src/rule-dispatch.d.ts +30 -0
- package/src/rule-dispatch.js +49 -0
- package/src/rule-dispatch.js.map +1 -0
- package/src/rule-migrations.d.ts +17 -0
- package/src/rule-migrations.js +40 -0
- package/src/rule-migrations.js.map +1 -0
- package/src/rule-pack.js +2 -1
- package/src/rule-pack.js.map +1 -1
- package/src/scan-scope.js +4 -1
- package/src/scan-scope.js.map +1 -1
- package/src/tag-rule.js +1 -14
- package/src/tag-rule.js.map +1 -1
- package/src/validate-catch-error-pattern.js +1 -17
- package/src/validate-catch-error-pattern.js.map +1 -1
- package/src/validate-dtos.js +1 -18
- package/src/validate-dtos.js.map +1 -1
- package/src/validate-ensure-we-are-secure.js +3 -0
- package/src/validate-ensure-we-are-secure.js.map +1 -1
- package/src/validate-framework-packages.js +3 -1
- package/src/validate-framework-packages.js.map +1 -1
- package/src/validate-inject-annotation-not-needed-for-concrete-class.d.ts +1 -1
- package/src/validate-inject-annotation-not-needed-for-concrete-class.js +10 -25
- package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
- package/src/validate-match-rules.d.ts +0 -1
- package/src/validate-match-rules.js +1 -12
- package/src/validate-match-rules.js.map +1 -1
- package/src/validate-modified-files.d.ts +0 -7
- package/src/validate-modified-files.js +8 -22
- package/src/validate-modified-files.js.map +1 -1
- package/src/validate-modified-methods.js +2 -6
- package/src/validate-modified-methods.js.map +1 -1
- package/src/validate-new-methods.js +2 -6
- package/src/validate-new-methods.js.map +1 -1
- package/src/validate-no-any-unknown.js +1 -18
- package/src/validate-no-any-unknown.js.map +1 -1
- package/src/validate-no-client-creation-outside-server-or-client.d.ts +2 -3
- package/src/validate-no-client-creation-outside-server-or-client.js +4 -18
- package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
- package/src/validate-no-custom-css.d.ts +0 -1
- package/src/validate-no-custom-css.js +1 -12
- package/src/validate-no-custom-css.js.map +1 -1
- package/src/validate-no-destructure.d.ts +3 -3
- package/src/validate-no-destructure.js +11 -31
- package/src/validate-no-destructure.js.map +1 -1
- package/src/validate-no-direct-api-resolver.js +1 -18
- package/src/validate-no-direct-api-resolver.js.map +1 -1
- package/src/validate-no-function-outside-class.d.ts +3 -3
- package/src/validate-no-function-outside-class.js +11 -25
- package/src/validate-no-function-outside-class.js.map +1 -1
- package/src/validate-no-implicit-any.js +1 -14
- package/src/validate-no-implicit-any.js.map +1 -1
- package/src/validate-no-inline-types.js +1 -18
- package/src/validate-no-inline-types.js.map +1 -1
- package/src/validate-no-process-exit-outside-main.js +1 -12
- package/src/validate-no-process-exit-outside-main.js.map +1 -1
- package/src/validate-no-state-paths-in-templates.d.ts +0 -1
- package/src/validate-no-state-paths-in-templates.js +1 -12
- package/src/validate-no-state-paths-in-templates.js.map +1 -1
- package/src/validate-no-symbol-di-tokens.d.ts +2 -2
- package/src/validate-no-symbol-di-tokens.js +9 -65
- package/src/validate-no-symbol-di-tokens.js.map +1 -1
- package/src/validate-no-unmanaged-exceptions.js +1 -17
- package/src/validate-no-unmanaged-exceptions.js.map +1 -1
- package/src/validate-prisma-converters.js +1 -18
- package/src/validate-prisma-converters.js.map +1 -1
- package/src/validate-return-types.js +1 -18
- package/src/validate-return-types.js.map +1 -1
- package/src/resolve-mode.d.ts +0 -2
- package/src/resolve-mode.js +0 -11
- package/src/resolve-mode.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.928",
|
|
4
4
|
"description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
"directory": "packages/tooling/code-rules"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/rules-config": "0.4.928",
|
|
20
20
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
25
|
-
"@webpieces/rules-sdk": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.928",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.928",
|
|
25
|
+
"@webpieces/rules-sdk": "0.4.928"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
31
|
+
"@webpieces/tooling-testkit": "0.4.928"
|
|
32
32
|
},
|
|
33
33
|
"exports": {
|
|
34
34
|
".": "./src/index.js",
|
|
@@ -67,7 +67,7 @@ export declare abstract class ApiLibSourceRule<C extends ApiLibConfig> extends C
|
|
|
67
67
|
run(workspaceRoot: string): Promise<ExecutorResult>;
|
|
68
68
|
/** The unexempt, in-scope violating sites of one changed file. */
|
|
69
69
|
private judge;
|
|
70
|
-
/** A non-test `.ts` file
|
|
70
|
+
/** A non-test `.ts` file that {@link isApiLibrarySource} claims (`excludePaths` is applied upstream). */
|
|
71
71
|
private inScope;
|
|
72
72
|
/** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */
|
|
73
73
|
protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean;
|
|
@@ -127,14 +127,12 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
|
|
|
127
127
|
.filter((site) => !this.disabled(lines, site.line))
|
|
128
128
|
.map((site) => new FoundSite(relFile, site));
|
|
129
129
|
}
|
|
130
|
-
/** A non-test `.ts` file
|
|
130
|
+
/** A non-test `.ts` file that {@link isApiLibrarySource} claims (`excludePaths` is applied upstream). */
|
|
131
131
|
inScope(workspaceRoot, relFile) {
|
|
132
132
|
if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts'))
|
|
133
133
|
return false;
|
|
134
134
|
if (/\.(spec|test)\.ts$/.test(relFile) || relFile.includes('__tests__/'))
|
|
135
135
|
return false;
|
|
136
|
-
if ((0, rules_config_1.isPathExcluded)(relFile, this.config.allowedPaths ?? []))
|
|
137
|
-
return false;
|
|
138
136
|
if (!fs.existsSync(path.join(workspaceRoot, relFile)))
|
|
139
137
|
return false;
|
|
140
138
|
return this.isApiLibrarySource(workspaceRoot, relFile);
|
|
@@ -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;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuG;AAKvG,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,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,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AAC,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;AA1GD,4CA0GC","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, 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 { DiffScope, Option, RuleFailError, hasDisable, isPathExcluded } from \"@webpieces/rules-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\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"]}
|
|
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,0DAAuF;AAKvF,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,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,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C,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;AAzGD,4CAyGC","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, 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 { DiffScope, Option, RuleFailError, hasDisable } from \"@webpieces/rules-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\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 that {@link isApiLibrarySource} claims (`excludePaths` is applied upstream). */\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 (!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"]}
|
|
@@ -8,6 +8,7 @@ const code_policy_registry_1 = require("./code-policy-registry");
|
|
|
8
8
|
const code_rules_context_1 = require("./code-rules-context");
|
|
9
9
|
const scan_scope_1 = require("./scan-scope");
|
|
10
10
|
const code_rules_engine_1 = require("./code-rules-engine");
|
|
11
|
+
const rule_dispatch_1 = require("./rule-dispatch");
|
|
11
12
|
/** Composition stays with the code owner; the public manifest never imports validators. */
|
|
12
13
|
class CodeRuleRuntime {
|
|
13
14
|
async create(request) {
|
|
@@ -17,6 +18,8 @@ class CodeRuleRuntime {
|
|
|
17
18
|
const container = new inversify_1.Container({ autobind: true });
|
|
18
19
|
container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(request.workspaceRoot));
|
|
19
20
|
container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(projects));
|
|
21
|
+
const global = new rule_dispatch_1.GlobalExcludePaths(request.excludePaths);
|
|
22
|
+
container.bind(rule_dispatch_1.GlobalExcludePaths).toConstantValue(global);
|
|
20
23
|
const policies = request.ruleIds.map((id) => this.entry(id));
|
|
21
24
|
for (const policy of policies) {
|
|
22
25
|
const config = request.configs[policy.ruleId];
|
|
@@ -24,7 +27,13 @@ class CodeRuleRuntime {
|
|
|
24
27
|
throw new tooling_common_1.InformAiError(`Missing explicit config for ${policy.ruleId}. Repair its declared owner file.`);
|
|
25
28
|
container.bind(policy.configClass).toConstantValue(config);
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
// Every validator runs inside its framework-owned path exclusions (#1253) — see ExclusionScopedPolicy.
|
|
31
|
+
const exclusions = new rule_dispatch_1.RuleExclusionsFactory();
|
|
32
|
+
const checks = await Promise.all(policies.map(async (policy) => {
|
|
33
|
+
const check = container.get(await policy.loadValidator());
|
|
34
|
+
const config = request.configs[policy.ruleId];
|
|
35
|
+
return new rule_dispatch_1.ExclusionScopedPolicy(check, exclusions.forRule(check.name, global, config));
|
|
36
|
+
}));
|
|
28
37
|
container.bind(code_rules_engine_1.BuildPolicySet).toConstantValue(new code_rules_engine_1.BuildPolicySet(checks));
|
|
29
38
|
return container;
|
|
30
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-policy-composition.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-policy-composition.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yCAAsC;
|
|
1
|
+
{"version":3,"file":"code-policy-composition.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-policy-composition.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yCAAsC;AAUtC,8DAA0D;AAC1D,iEAAmE;AACnE,6DAAqD;AACrD,6CAA+C;AAC/C,2DAAqD;AACrD,mDAAmG;AAEnG,2FAA2F;AAC3F,MAAa,eAAe;IACxB,KAAK,CAAC,MAAM,CAAC,OAA6B;QACtC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,kCAAc,CAAC,CAAC,QAAQ,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,OAAO,CACT,OAA6B,EAC7B,QAAuC;QAEvC,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,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACxF,SAAS,CAAC,IAAI,CAAC,4BAAe,CAAC,CAAC,eAAe,CAAC,IAAI,4BAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,IAAI,kCAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5D,SAAS,CAAC,IAAI,CAAC,kCAAkB,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,KAAK,MAAM,MAAM,IAAI,QAAQ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CA4CC","sourcesContent":["import 'reflect-metadata';\nimport { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n BuildPolicy,\n BuildRuleRuntime,\n PolicyRuntimeRequest,\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicyResult,\n} from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { WorkspaceRoot } from './code-rules-context';\nimport { ScanRestriction } from './scan-scope';\nimport { BuildPolicySet } from './code-rules-engine';\nimport { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';\n\n/** Composition stays with the code owner; the public manifest never imports validators. */\nexport class CodeRuleRuntime implements BuildRuleRuntime {\n async create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]> {\n return (await this.compose(request, undefined)).get(BuildPolicySet).policies;\n }\n\n async compose(\n request: PolicyRuntimeRequest,\n projects: readonly string[] | undefined,\n ): Promise<Container> {\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(request.workspaceRoot));\n container.bind(ScanRestriction).toConstantValue(new ScanRestriction(projects));\n const global = new GlobalExcludePaths(request.excludePaths);\n container.bind(GlobalExcludePaths).toConstantValue(global);\n const policies = request.ruleIds.map((id: string) => this.entry(id));\n for (const policy of policies) {\n const config = request.configs[policy.ruleId];\n if (!config)\n throw new InformAiError(\n `Missing explicit config for ${policy.ruleId}. Repair its declared owner file.`,\n );\n container.bind(policy.configClass).toConstantValue(config);\n }\n // Every validator runs inside its framework-owned path exclusions (#1253) — see ExclusionScopedPolicy.\n const exclusions = new RuleExclusionsFactory();\n const checks = await Promise.all(\n policies.map(async (policy: CodePolicy) => {\n const check = container.get(await policy.loadValidator());\n const config = request.configs[policy.ruleId] as BaseRuleConfig;\n return new ExclusionScopedPolicy(check, exclusions.forRule(check.name, global, config));\n }),\n );\n container.bind(BuildPolicySet).toConstantValue(new BuildPolicySet(checks));\n return container;\n }\n\n private entry(id: string): CodePolicy {\n const entry = CODE_POLICIES.find((policy: CodePolicy) => policy.ruleId === id);\n if (!entry)\n throw new InformAiError(\n `Code runtime has no implementation of ${id}. Repair the owner's contribution.`,\n );\n return entry;\n }\n}\n\n"]}
|
|
@@ -55,7 +55,7 @@ class CodeRulesBootstrap {
|
|
|
55
55
|
const config = loaded.rulesConfig[policy.ruleId];
|
|
56
56
|
configs[policy.ruleId] = (plan?.rule === policy.ruleId ? this.overridden(config, plan) : config);
|
|
57
57
|
}
|
|
58
|
-
const runtimeRequest = new rules_sdk_1.PolicyRuntimeRequest(workspaceRoot, configs, code_policy_registry_1.CODE_POLICIES.map((policy) => policy.ruleId));
|
|
58
|
+
const runtimeRequest = new rules_sdk_1.PolicyRuntimeRequest(workspaceRoot, configs, code_policy_registry_1.CODE_POLICIES.map((policy) => policy.ruleId), loaded.excludePaths.paths);
|
|
59
59
|
const container = await new code_policy_composition_1.CodeRuleRuntime().compose(runtimeRequest, plan?.projects);
|
|
60
60
|
container
|
|
61
61
|
.bind(code_rules_context_1.MatchRulesHolder)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAA0F;AAC1F,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAAoG;AACpG,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAM,SAAS;IAEE;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP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B,CAAC;CACJ;AAzKD,gDAyKC","sourcesContent":["import { BaseRuleConfig, ConfigObject, PolicyRuntimeRequest } from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport { DiffScope, LoadedConfig, MatchRuleConfig, loadAndValidate } from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nclass DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = this.printCounts(workspaceRoot, plan, container.get(ScanScope), result);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): DebugPlan {\n const rule = request.rule;\n if (rule === undefined)\n throw this.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.refusal(\n `--rule=${rule} is not a code rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';\n const mode = request.mode ?? committedMode;\n if (!modes.includes(mode) || mode === 'OFF') {\n const why =\n request.mode === undefined\n ? `its committed mode is ${committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const unknown = (request.projects ?? []).filter(\n (name: string) => !this.projectNames(workspaceRoot).includes(name),\n );\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +\n `${this.projectNames(workspaceRoot).join(', ')}.`,\n );\n }\n return new DebugPlan(rule, mode, committedMode, request.projects);\n }\n\n private refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n if (!CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule)) return undefined;\n const modes =\n CODE_POLICIES.find((binding: CodePolicy) => binding.ruleId === rule)?.schema['mode']\n ?.enumValues ?? [];\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME')\n ? modes\n : undefined;\n }\n\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n return names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope())\n .all(workspaceRoot)\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.overridden(mr, plan) : mr,\n );\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n private overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n private printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project and return the total. */\n private printCounts(\n workspaceRoot: string,\n plan: DebugPlan,\n scan: ScanScope,\n result: ExecutorResult,\n ): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!result.success && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDA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GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC;QACtE,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA1KD,gDA0KC","sourcesContent":["import { BaseRuleConfig, ConfigObject, PolicyRuntimeRequest } from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport { DiffScope, LoadedConfig, MatchRuleConfig, loadAndValidate } from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nclass DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n loaded.excludePaths.paths,\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = this.printCounts(workspaceRoot, plan, container.get(ScanScope), result);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): DebugPlan {\n const rule = request.rule;\n if (rule === undefined)\n throw this.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.refusal(\n `--rule=${rule} is not a code rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';\n const mode = request.mode ?? committedMode;\n if (!modes.includes(mode) || mode === 'OFF') {\n const why =\n request.mode === undefined\n ? `its committed mode is ${committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const unknown = (request.projects ?? []).filter(\n (name: string) => !this.projectNames(workspaceRoot).includes(name),\n );\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +\n `${this.projectNames(workspaceRoot).join(', ')}.`,\n );\n }\n return new DebugPlan(rule, mode, committedMode, request.projects);\n }\n\n private refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n if (!CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule)) return undefined;\n const modes =\n CODE_POLICIES.find((binding: CodePolicy) => binding.ruleId === rule)?.schema['mode']\n ?.enumValues ?? [];\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME')\n ? modes\n : undefined;\n }\n\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n return names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope())\n .all(workspaceRoot)\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.overridden(mr, plan) : mr,\n );\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n private overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n private printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project and return the total. */\n private printCounts(\n workspaceRoot: string,\n plan: DebugPlan,\n scan: ScanScope,\n result: ExecutorResult,\n ): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!result.success && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { RuleReporter } from './rule-reporter';
|
|
|
4
4
|
import { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';
|
|
5
5
|
import { RuleSelection } from './code-rules-run-request';
|
|
6
6
|
import { MatchRulesChecker } from './validate-match-rules';
|
|
7
|
+
import { GlobalExcludePaths } from './rule-dispatch';
|
|
7
8
|
/** Runtime checks are composed from the owner's policy entries, rather than injected individually. */
|
|
8
9
|
export declare class BuildPolicySet {
|
|
9
10
|
readonly policies: readonly BuildPolicy[];
|
|
@@ -16,7 +17,8 @@ export declare class CodeRulesEngine {
|
|
|
16
17
|
private readonly matchChecker;
|
|
17
18
|
private readonly selection;
|
|
18
19
|
private readonly checks;
|
|
19
|
-
|
|
20
|
+
private readonly globalExcludes;
|
|
21
|
+
constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, selection: RuleSelection, checks: BuildPolicySet, globalExcludes: GlobalExcludePaths);
|
|
20
22
|
/**
|
|
21
23
|
* Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected
|
|
22
24
|
* match-rule check per configured entry that is active. Built as {@link RuleRun} value objects
|
package/src/code-rules-engine.js
CHANGED
|
@@ -8,6 +8,8 @@ const rule_reporter_1 = require("./rule-reporter");
|
|
|
8
8
|
const code_rules_context_1 = require("./code-rules-context");
|
|
9
9
|
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
10
10
|
const validate_match_rules_1 = require("./validate-match-rules");
|
|
11
|
+
const rule_dispatch_1 = require("./rule-dispatch");
|
|
12
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
11
13
|
/** Runtime checks are composed from the owner's policy entries, rather than injected individually. */
|
|
12
14
|
class BuildPolicySet {
|
|
13
15
|
policies;
|
|
@@ -23,14 +25,16 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
23
25
|
matchChecker;
|
|
24
26
|
selection;
|
|
25
27
|
checks;
|
|
28
|
+
globalExcludes;
|
|
26
29
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
27
|
-
constructor(workspace, reporter, matchRules, matchChecker, selection, checks) {
|
|
30
|
+
constructor(workspace, reporter, matchRules, matchChecker, selection, checks, globalExcludes) {
|
|
28
31
|
this.workspace = workspace;
|
|
29
32
|
this.reporter = reporter;
|
|
30
33
|
this.matchRules = matchRules;
|
|
31
34
|
this.matchChecker = matchChecker;
|
|
32
35
|
this.selection = selection;
|
|
33
36
|
this.checks = checks;
|
|
37
|
+
this.globalExcludes = globalExcludes;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected
|
|
@@ -45,8 +49,12 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
45
49
|
runs.push(new code_validator_1.RuleRun(v.name, () => v.run(root)));
|
|
46
50
|
}
|
|
47
51
|
for (const mr of this.matchRules.rules) {
|
|
48
|
-
if (this.selection.includes(mr.name) && this.matchChecker.shouldRun(mr))
|
|
49
|
-
|
|
52
|
+
if (this.selection.includes(mr.name) && this.matchChecker.shouldRun(mr)) {
|
|
53
|
+
// A client-authored match rule has no owner schema, but the repo's top-level
|
|
54
|
+
// `excludePaths` still binds it (#1253): no rule judges those paths.
|
|
55
|
+
const exclusions = new rules_config_1.RuleFileExclusions(mr.name, this.globalExcludes.paths, []);
|
|
56
|
+
runs.push(new code_validator_1.RuleRun(mr.name, () => new rules_config_1.RuleFileScope().runWithin(exclusions, () => this.matchChecker.runForConfig(mr, root))));
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
59
|
return runs;
|
|
52
60
|
}
|
|
@@ -79,6 +87,7 @@ exports.CodeRulesEngine = CodeRulesEngine = tslib_1.__decorate([
|
|
|
79
87
|
code_rules_context_1.MatchRulesHolder,
|
|
80
88
|
validate_match_rules_1.MatchRulesChecker,
|
|
81
89
|
code_rules_run_request_1.RuleSelection,
|
|
82
|
-
BuildPolicySet
|
|
90
|
+
BuildPolicySet,
|
|
91
|
+
rule_dispatch_1.GlobalExcludePaths])
|
|
83
92
|
], CodeRulesEngine);
|
|
84
93
|
//# 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":";;;;AAEA,yCAA2D;AAE3D,qDAA2D;AAC3D,mDAA+C;AAC/C,6DAAuE;AACvE,qEAAyD;AACzD,iEAA2D;
|
|
1
|
+
{"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AAEA,yCAA2D;AAE3D,qDAA2D;AAC3D,mDAA+C;AAC/C,6DAAuE;AACvE,qEAAyD;AACzD,iEAA2D;AAC3D,mDAAqD;AACrD,0DAA4E;AAE5E,sGAAsG;AACtG,MAAa,cAAc;IACF;IAArB,YAAqB,QAAgC;QAAhC,aAAQ,GAAR,QAAQ,CAAwB;IAAG,CAAC;CAC5D;AAFD,wCAEC;AAGM,IAAM,eAAe,GAArB,MAAM,eAAe;IAGH;IACA;IACA;IACA;IACA;IACA;IACA;IARrB,yDAAyD;IACzD,YACqB,SAAwB,EACxB,QAAsB,EACtB,UAA4B,EAC5B,YAA+B,EAC/B,SAAwB,EACxB,MAAsB,EACtB,cAAkC;QANlC,cAAS,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,CAAC,CAAC,CAAC;YACpG,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAG;QACL,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;YACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAU,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;AA5DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIL,kCAAa;QACd,4BAAY;QACV,qCAAgB;QACd,wCAAiB;QACpB,sCAAa;QAChB,cAAc;QACN,kCAAkB;GAT9C,eAAe,CA4D3B","sourcesContent":["import { BuildPolicy } from '@webpieces/rules-sdk';\n\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { RuleSelection } from './code-rules-run-request';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { GlobalExcludePaths } from './rule-dispatch';\nimport { RuleFileExclusions, RuleFileScope } from '@webpieces/rules-config';\n\n/** Runtime checks are composed from the owner's policy entries, rather than injected individually. */\nexport class BuildPolicySet {\n constructor(readonly policies: readonly BuildPolicy[]) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // eslint-disable-next-line @typescript-eslint/max-params\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 selection: RuleSelection,\n private readonly checks: BuildPolicySet,\n private readonly globalExcludes: GlobalExcludePaths,\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 * A debug run (#1027) narrows the set to the one rule its {@link RuleSelection} names.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.checks.policies) {\n if (this.selection.includes(v.name) && v.shouldRun())\n runs.push(new RuleRun(v.name, () => v.run(root)));\n }\n for (const mr of this.matchRules.rules) {\n if (this.selection.includes(mr.name) && this.matchChecker.shouldRun(mr)) {\n // A client-authored match rule has no owner schema, but the repo's top-level\n // `excludePaths` still binds it (#1253): no rule judges those paths.\n const exclusions = new RuleFileExclusions(mr.name, this.globalExcludes.paths, []);\n runs.push(new RuleRun(mr.name, () =>\n new RuleFileScope().runWithin(exclusions, () => this.matchChecker.runForConfig(mr, root))));\n }\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"]}
|
|
@@ -9,12 +9,11 @@ import { ModifiedCodeMode } from "@webpieces/rules-sdk";
|
|
|
9
9
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
|
|
10
10
|
* NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
|
|
11
11
|
* occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched
|
|
12
|
-
* project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). `
|
|
12
|
+
* project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). The framework-owned `excludePaths` exempts whole trees. The per-site escape hatch is
|
|
13
13
|
* `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
|
|
14
14
|
*/
|
|
15
15
|
export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
|
|
16
16
|
mode?: ModifiedCodeMode;
|
|
17
|
-
allowedPaths?: string[];
|
|
18
17
|
static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig>;
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
@@ -31,10 +30,9 @@ export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
|
|
|
31
30
|
* mode grandfathers. This rule is what forbids NEW ones in an api library.
|
|
32
31
|
*
|
|
33
32
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
|
|
34
|
-
* values as above; `
|
|
33
|
+
* values as above; `excludePaths` and the per-site disable work the same way.
|
|
35
34
|
*/
|
|
36
35
|
export declare class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {
|
|
37
36
|
mode?: ModifiedCodeMode;
|
|
38
|
-
allowedPaths?: string[];
|
|
39
37
|
static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig>;
|
|
40
38
|
}
|
|
@@ -12,15 +12,12 @@ const rules_sdk_2 = require("@webpieces/rules-sdk");
|
|
|
12
12
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
|
|
13
13
|
* NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
|
|
14
14
|
* occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched
|
|
15
|
-
* project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). `
|
|
15
|
+
* project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). The framework-owned `excludePaths` exempts whole trees. The per-site escape hatch is
|
|
16
16
|
* `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
|
|
17
17
|
*/
|
|
18
18
|
class NoInlineImportInApiLibConfig extends rules_sdk_1.BaseRuleConfig {
|
|
19
|
-
allowedPaths;
|
|
20
19
|
static SCHEMA = {
|
|
21
20
|
mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
|
|
22
|
-
allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
|
|
23
|
-
...rules_sdk_1.BASE_RULE_SCHEMA,
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
exports.NoInlineImportInApiLibConfig = NoInlineImportInApiLibConfig;
|
|
@@ -38,14 +35,11 @@ exports.NoInlineImportInApiLibConfig = NoInlineImportInApiLibConfig;
|
|
|
38
35
|
* mode grandfathers. This rule is what forbids NEW ones in an api library.
|
|
39
36
|
*
|
|
40
37
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
|
|
41
|
-
* values as above; `
|
|
38
|
+
* values as above; `excludePaths` and the per-site disable work the same way.
|
|
42
39
|
*/
|
|
43
40
|
class OneEnumSpellingInApiLibConfig extends rules_sdk_1.BaseRuleConfig {
|
|
44
|
-
allowedPaths;
|
|
45
41
|
static SCHEMA = {
|
|
46
42
|
mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
|
|
47
|
-
allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
|
|
48
|
-
...rules_sdk_1.BASE_RULE_SCHEMA,
|
|
49
43
|
};
|
|
50
44
|
}
|
|
51
45
|
exports.OneEnumSpellingInApiLibConfig = OneEnumSpellingInApiLibConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,oDAA6E;AAC7E,oDAA6E;AAC7E;;;;;;;;;;;GAWG;AACH,MAAa,4BAA6B,SAAQ,0BAAc;IAG5D,MAAM,CAAU,MAAM,GAA8C;QAChE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;KACpD,CAAC;;AALN,oEAMC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,6BAA8B,SAAQ,0BAAc;IAG7D,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;KACpD,CAAC;;AALN,sEAMC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig } from \"@webpieces/rules-sdk\";\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from \"@webpieces/rules-sdk\";\n/**\n * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`\n * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`\n * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library\n * dependency from every reader of the contract and from the tools that read its imports.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |\n * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every\n * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched\n * project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). The framework-owned `excludePaths` exempts whole trees. The per-site escape hatch is\n * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.\n */\nexport class NoInlineImportInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n\n static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n };\n}\n\n/**\n * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string\n * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string\n * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one\n * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:\n * a string-literal union of two or more members (in a type alias, a field or a parameter),\n * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,\n * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the\n * wire).\n *\n * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's\n * mode grandfathers. This rule is what forbids NEW ones in an api library.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three\n * values as above; `excludePaths` and the per-site disable work the same way.\n */\nexport class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n\n static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n };\n}\n"]}
|
|
@@ -7,6 +7,5 @@ export declare class NoClientCreationOutsideServerOrClientConfig extends BaseRul
|
|
|
7
7
|
severity?: ClientCreationSeverity;
|
|
8
8
|
disableAllowed?: boolean;
|
|
9
9
|
allowedRoles?: string[];
|
|
10
|
-
allowedPaths?: string[];
|
|
11
10
|
static readonly SCHEMA: SchemaShape<NoClientCreationOutsideServerOrClientConfig>;
|
|
12
11
|
}
|
|
@@ -19,21 +19,18 @@ exports.CLIENT_CREATION_SEVERITIES = ['warn', 'error'];
|
|
|
19
19
|
//
|
|
20
20
|
// `severity` ships "warn" (report + migration, build passes) so an upgrade can't break an un-migrated
|
|
21
21
|
// Angular repo; flip to "error" once libraries are migrated. `allowedRoles` defaults to the runnable
|
|
22
|
-
// roles; `
|
|
22
|
+
// roles; the framework-owned `excludePaths` exempts whole file trees. Standard rollout knobs via
|
|
23
23
|
// the base: mode (OFF | NEW_AND_MODIFIED_CODE | NEW_AND_MODIFIED_FILES), turnOffRuleUntilEpoch,
|
|
24
24
|
// branch, and disableAllowed for the inline `// webpieces-disable` escape.
|
|
25
25
|
class NoClientCreationOutsideServerOrClientConfig extends rules_sdk_1.BaseRuleConfig {
|
|
26
26
|
severity;
|
|
27
27
|
disableAllowed;
|
|
28
28
|
allowedRoles;
|
|
29
|
-
allowedPaths;
|
|
30
29
|
static SCHEMA = {
|
|
31
30
|
mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
|
|
32
31
|
severity: rules_sdk_1.FieldDef.optional('string', exports.CLIENT_CREATION_SEVERITIES),
|
|
33
32
|
disableAllowed: rules_sdk_1.FieldDef.optional('boolean'),
|
|
34
33
|
allowedRoles: rules_sdk_1.FieldDef.optional('string[]'),
|
|
35
|
-
allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
|
|
36
|
-
...rules_sdk_1.BASE_RULE_SCHEMA,
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
exports.NoClientCreationOutsideServerOrClientConfig = NoClientCreationOutsideServerOrClientConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-client-creation-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/no-client-creation-config.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"no-client-creation-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/no-client-creation-config.ts"],"names":[],"mappings":";;;AAAA,oDAA6E;AAC7E,oDAA6E;AAC7E,iGAAiG;AACjG,kGAAkG;AAClG,kGAAkG;AAClG,6EAA6E;AAChE,QAAA,0BAA0B,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAIrE,qGAAqG;AACrG,sGAAsG;AACtG,sGAAsG;AACtG,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,mGAAmG;AACnG,8DAA8D;AAC9D,EAAE;AACF,sGAAsG;AACtG,qGAAqG;AACrG,iGAAiG;AACjG,gGAAgG;AAChG,2EAA2E;AAC3E,MAAa,2CAA4C,SAAQ,0BAAc;IAE3E,QAAQ,CAA0B;IAClC,cAAc,CAAW;IACzB,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA6D;QAC/E,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,QAAQ,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,kCAA0B,CAAC;QACjE,cAAc,EAAE,oBAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC5C,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;KAC9C,CAAC;;AAXN,kGAYC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig } from \"@webpieces/rules-sdk\";\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from \"@webpieces/rules-sdk\";\n// no-client-creation-outside-server-or-client severity. Landed as a hard failure this rule would\n// break every existing Angular repo on upgrade (provideCoreClient-style helpers create the client\n// inside a role:lib on purpose), so it ships WARN — reports + prints the migration but passes the\n// build — and a repo flips it to `error` once it has migrated its libraries.\nexport const CLIENT_CREATION_SEVERITIES = ['warn', 'error'] as const;\n\nexport type ClientCreationSeverity = typeof CLIENT_CREATION_SEVERITIES[number];\n\n// no-client-creation-outside-server-or-client — flags a project that CONSTRUCTS an rpc/pubsub client\n// (`factory.createRpcClient(...)` / `factory.createPubSubClient(...)`) when the project's `role:` tag\n// is not one of `allowedRoles`. Only a runnable entrypoint (server / client app / app) has a declared\n// identity (`serviceName`) or target (`callsService`), so a client built there is attributable in the\n// runtime graph; a client built inside a `role:lib` reaches the fan-out fallback (one `uses` edge to\n// EVERY implementer of the api) and draws calls that cannot happen. A reusable library takes the api\n// INJECTED — the server/app module binds it to a client. Importing the api type or its DI token is\n// FINE and never flagged; only constructing the transport is.\n//\n// `severity` ships \"warn\" (report + migration, build passes) so an upgrade can't break an un-migrated\n// Angular repo; flip to \"error\" once libraries are migrated. `allowedRoles` defaults to the runnable\n// roles; the framework-owned `excludePaths` exempts whole file trees. Standard rollout knobs via\n// the base: mode (OFF | NEW_AND_MODIFIED_CODE | NEW_AND_MODIFIED_FILES), turnOffRuleUntilEpoch,\n// branch, and disableAllowed for the inline `// webpieces-disable` escape.\nexport class NoClientCreationOutsideServerOrClientConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n severity?: ClientCreationSeverity;\n disableAllowed?: boolean;\n allowedRoles?: string[];\n\n static readonly SCHEMA: SchemaShape<NoClientCreationOutsideServerOrClientConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n severity: FieldDef.optional('string', CLIENT_CREATION_SEVERITIES),\n disableAllowed: FieldDef.optional('boolean'),\n allowedRoles: FieldDef.optional('string[]'),\n };\n}\n"]}
|
|
@@ -44,7 +44,6 @@ class NoStatePathsInTemplatesConfig extends rules_sdk_1.BaseRuleConfig {
|
|
|
44
44
|
disableAllowed: rules_sdk_1.FieldDef.optional('boolean'),
|
|
45
45
|
templateDirs: rules_sdk_1.FieldDef.optional('string[]'),
|
|
46
46
|
bannedPathPrefixes: rules_sdk_1.FieldDef.optional('string[]'),
|
|
47
|
-
...rules_sdk_1.BASE_RULE_SCHEMA,
|
|
48
47
|
};
|
|
49
48
|
}
|
|
50
49
|
exports.NoStatePathsInTemplatesConfig = NoStatePathsInTemplatesConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-state-paths-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/no-state-paths-config.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"no-state-paths-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/no-state-paths-config.ts"],"names":[],"mappings":";;;AAAA,oDAA6E;AAC7E,oDAA6E;AAC7E;;;;;;;GAOG;AACU,QAAA,qBAAqB,GAAsB,CAAC,yCAAyC,CAAC,CAAC;AAEpG;;;;;;GAMG;AACU,QAAA,kCAAkC,GAAsB,CAAC,aAAa,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,MAAa,6BAA8B,SAAQ,0BAAc;IAE7D,cAAc,CAAW;IACzB,YAAY,CAAY;IACxB,kBAAkB,CAAY;IAE9B,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,cAAc,EAAE,oBAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC5C,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,kBAAkB,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;KACpD,CAAC;;AAXN,sEAYC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig } from \"@webpieces/rules-sdk\";\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from \"@webpieces/rules-sdk\";\n/**\n * The template dirs `no-state-paths-in-templates` looks at when a repo has not said otherwise:\n * webpieces' own instruct-ai templates, which are the generated docs the rule was written for.\n *\n * A consumer repo that generates AI-facing docs from its own templates points `templateDirs` at them;\n * a repo that generates none matches no files and the rule is a no-op. Seeded rather than left empty\n * so the rule arrives doing the job it exists for instead of waiting to be discovered.\n */\nexport const DEFAULT_TEMPLATE_DIRS: readonly string[] = ['packages/tooling/rules-config/templates'];\n\n/**\n * The path prefixes that must never be RESTATED in a generated doc, only computed.\n *\n * `.webpieces/` is the whole webpieces state tree, and every path under it is per-tree: a linked\n * worktree's state lives at `<primary>/.webpieces/worktrees/<name>/…`, so the relative spelling names\n * a file that does not exist there.\n */\nexport const DEFAULT_BANNED_STATE_PATH_PREFIXES: readonly string[] = ['.webpieces/'];\n\n/**\n * Bans a hard-coded state path inside a GENERATED-doc template.\n *\n * The incident: `webpieces.git-workflow.md` restated `.webpieces/logs/branch-mutations.log`. That log\n * is per-worktree, so the doc — regenerated into every governed repo and handed to an agent by\n * absolute path as instruction — named a file that does not exist in half the trees that read it.\n * Every one of these paths already has a resolver; the template engine already substitutes. The rule\n * makes \"restate it\" the thing that fails and \"render `{{PLACEHOLDER}}` from the resolver\" the thing\n * that passes.\n *\n * Diff-scoped like every other code rule, so the docs whose SUBJECT is the layout (they explain both\n * rows on purpose) are not retroactively flooded — the rule bites when a template is next edited.\n * A doc that genuinely has to print the literal says so out loud:\n * `<!-- webpieces-disable no-state-paths-in-templates -- this table IS the layout -->`.\n */\nexport class NoStatePathsInTemplatesConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n disableAllowed?: boolean;\n templateDirs?: string[];\n bannedPathPrefixes?: string[];\n\n static readonly SCHEMA: SchemaShape<NoStatePathsInTemplatesConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n disableAllowed: FieldDef.optional('boolean'),\n templateDirs: FieldDef.optional('string[]'),\n bannedPathPrefixes: FieldDef.optional('string[]'),\n };\n}\n"]}
|
|
@@ -19,12 +19,11 @@ import { ModifiedCodeMode } from "@webpieces/rules-sdk";
|
|
|
19
19
|
* - `paths` — the globs of the API contract libraries this rule judges, e.g. `["libraries/apis/**"]`.
|
|
20
20
|
* An empty list judges nothing.
|
|
21
21
|
*
|
|
22
|
-
* `
|
|
22
|
+
* The framework-owned `excludePaths` exempts whole trees inside `paths`. The per-site escape hatch is
|
|
23
23
|
* `// webpieces-disable no-utility-types-in-api-lib -- <reason>` on the line or the line above.
|
|
24
24
|
*/
|
|
25
25
|
export declare class NoUtilityTypesInApiLibConfig extends BaseRuleConfig {
|
|
26
26
|
mode?: ModifiedCodeMode;
|
|
27
27
|
paths: string[];
|
|
28
|
-
allowedPaths?: string[];
|
|
29
28
|
static readonly SCHEMA: SchemaShape<NoUtilityTypesInApiLibConfig>;
|
|
30
29
|
}
|
|
@@ -22,17 +22,14 @@ const rules_sdk_2 = require("@webpieces/rules-sdk");
|
|
|
22
22
|
* - `paths` — the globs of the API contract libraries this rule judges, e.g. `["libraries/apis/**"]`.
|
|
23
23
|
* An empty list judges nothing.
|
|
24
24
|
*
|
|
25
|
-
* `
|
|
25
|
+
* The framework-owned `excludePaths` exempts whole trees inside `paths`. The per-site escape hatch is
|
|
26
26
|
* `// webpieces-disable no-utility-types-in-api-lib -- <reason>` on the line or the line above.
|
|
27
27
|
*/
|
|
28
28
|
class NoUtilityTypesInApiLibConfig extends rules_sdk_1.BaseRuleConfig {
|
|
29
29
|
paths;
|
|
30
|
-
allowedPaths;
|
|
31
30
|
static SCHEMA = {
|
|
32
31
|
mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
|
|
33
32
|
paths: new rules_sdk_1.FieldDef('string[]'),
|
|
34
|
-
allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
|
|
35
|
-
...rules_sdk_1.BASE_RULE_SCHEMA,
|
|
36
33
|
};
|
|
37
34
|
}
|
|
38
35
|
exports.NoUtilityTypesInApiLibConfig = NoUtilityTypesInApiLibConfig;
|