@webpieces/code-rules 0.4.847 → 0.4.849
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 +8 -7
- package/src/code-policy-composition.d.ts +9 -0
- package/src/code-policy-composition.js +39 -0
- package/src/code-policy-composition.js.map +1 -0
- package/src/code-policy-registry.d.ts +12 -0
- package/src/code-policy-registry.js +95 -0
- package/src/code-policy-registry.js.map +1 -0
- package/src/code-rules-bootstrap.js +30 -22
- package/src/code-rules-bootstrap.js.map +1 -1
- package/src/code-rules-engine.d.ts +8 -65
- package/src/code-rules-engine.js +15 -155
- package/src/code-rules-engine.js.map +1 -1
- package/src/code-validator.d.ts +1 -1
- package/src/code-validator.js +1 -1
- package/src/code-validator.js.map +1 -1
- package/src/prune-unknown-config.js +5 -15
- package/src/prune-unknown-config.js.map +1 -1
- package/src/rule-help.d.ts +3 -0
- package/src/rule-help.js +36 -0
- package/src/rule-help.js.map +1 -0
- package/src/rule-pack.js +3 -2
- package/src/rule-pack.js.map +1 -1
- package/src/rule-runtime.d.ts +10 -0
- package/src/rule-runtime.js +50 -0
- package/src/rule-runtime.js.map +1 -0
- package/src/validate-required-type-suffix.d.ts +2 -2
- package/src/validate-required-type-suffix.js +45 -22
- package/src/validate-required-type-suffix.js.map +1 -1
- package/src/wp-ci.d.ts +20 -1
- package/src/wp-ci.js +7 -19
- package/src/wp-ci.js.map +1 -1
- package/src/code-rules-config-table.d.ts +0 -11
- package/src/code-rules-config-table.js +0 -53
- package/src/code-rules-config-table.js.map +0 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequiredTypeSuffixValidator = exports.ExportedTypeScanner = exports.SuffixRename = exports.SuffixEntryPicker = exports.GoverningGlob = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
2
6
|
/**
|
|
3
7
|
* `required-type-suffix` (#1037) — a type's name says which layer it belongs to.
|
|
4
8
|
*
|
|
@@ -23,10 +27,7 @@
|
|
|
23
27
|
* Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type
|
|
24
28
|
* or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.
|
|
25
29
|
*/
|
|
26
|
-
|
|
27
|
-
exports.RequiredTypeSuffixValidator = exports.ExportedTypeScanner = exports.SuffixRename = exports.SuffixEntryPicker = exports.GoverningGlob = void 0;
|
|
28
|
-
const tslib_1 = require("tslib");
|
|
29
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
30
|
+
const rules_config_2 = require("@webpieces/rules-config");
|
|
30
31
|
const required_type_suffix_config_1 = require("./configs/required-type-suffix-config");
|
|
31
32
|
const inversify_1 = require("inversify");
|
|
32
33
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
@@ -54,12 +55,8 @@ class SuffixEntryPicker {
|
|
|
54
55
|
}
|
|
55
56
|
/** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */
|
|
56
57
|
winner(relFile, entries) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (glob !== undefined)
|
|
60
|
-
return new GoverningGlob(entry, glob);
|
|
61
|
-
}
|
|
62
|
-
return undefined;
|
|
58
|
+
const match = new rules_config_1.FirstPathMatch().winner(relFile, entries.map((entry) => new rules_config_1.PathMatchCandidate(entry.paths, entry)));
|
|
59
|
+
return match === undefined ? undefined : new GoverningGlob(match.entry, match.glob);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
62
|
exports.SuffixEntryPicker = SuffixEntryPicker;
|
|
@@ -70,8 +67,25 @@ class SuffixRename {
|
|
|
70
67
|
* `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.
|
|
71
68
|
*/
|
|
72
69
|
static LAYERLESS_TAILS = [
|
|
73
|
-
'Interface',
|
|
74
|
-
'
|
|
70
|
+
'Interface',
|
|
71
|
+
'Payload',
|
|
72
|
+
'Options',
|
|
73
|
+
'Object',
|
|
74
|
+
'Params',
|
|
75
|
+
'Output',
|
|
76
|
+
'Option',
|
|
77
|
+
'Record',
|
|
78
|
+
'Input',
|
|
79
|
+
'Model',
|
|
80
|
+
'Entry',
|
|
81
|
+
'Shape',
|
|
82
|
+
'Data',
|
|
83
|
+
'Info',
|
|
84
|
+
'Item',
|
|
85
|
+
'Type',
|
|
86
|
+
'Body',
|
|
87
|
+
'Row',
|
|
88
|
+
'Obj',
|
|
75
89
|
];
|
|
76
90
|
/** Candidate names, one per allowed suffix, in the configured order. */
|
|
77
91
|
candidates(name, suffixes) {
|
|
@@ -133,14 +147,16 @@ class ExportedTypeScanner {
|
|
|
133
147
|
return sites;
|
|
134
148
|
}
|
|
135
149
|
typeDeclaration(statement) {
|
|
136
|
-
if (ts.isInterfaceDeclaration(statement) ||
|
|
137
|
-
ts.
|
|
150
|
+
if (ts.isInterfaceDeclaration(statement) ||
|
|
151
|
+
ts.isTypeAliasDeclaration(statement) ||
|
|
152
|
+
ts.isEnumDeclaration(statement) ||
|
|
153
|
+
ts.isClassDeclaration(statement)) {
|
|
138
154
|
return statement;
|
|
139
155
|
}
|
|
140
156
|
return undefined;
|
|
141
157
|
}
|
|
142
158
|
isExported(statement) {
|
|
143
|
-
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
159
|
+
const modifiers = ts.canHaveModifiers(statement) ? (ts.getModifiers(statement) ?? []) : [];
|
|
144
160
|
return modifiers.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
145
161
|
}
|
|
146
162
|
judge(file, declared, at, name, entry, glob) {
|
|
@@ -152,12 +168,19 @@ class ExportedTypeScanner {
|
|
|
152
168
|
const kind = this.kindOf(declared);
|
|
153
169
|
const allowed = entry.suffixes.join(' | ');
|
|
154
170
|
const line = file.lineOf(at);
|
|
155
|
-
const snippet = (file.source.text.split('\n')[line - 1] ?? name)
|
|
171
|
+
const snippet = (file.source.text.split('\n')[line - 1] ?? name)
|
|
172
|
+
.replace(/\s+/g, ' ')
|
|
173
|
+
.trim();
|
|
156
174
|
const what = `exported ${kind} \`${name}\` does not end in a suffix allowed under ${glob} (${allowed})`;
|
|
157
175
|
const candidates = this.rename.candidates(name, entry.suffixes);
|
|
158
|
-
const others = candidates
|
|
176
|
+
const others = candidates
|
|
177
|
+
.slice(1)
|
|
178
|
+
.map((c) => `\`${c}\``)
|
|
179
|
+
.join(' / ');
|
|
159
180
|
const cure = `rename ${kind} \`${name}\` → \`${candidates[0]}\`` +
|
|
160
|
-
(others === ''
|
|
181
|
+
(others === ''
|
|
182
|
+
? ''
|
|
183
|
+
: ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +
|
|
161
184
|
` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +
|
|
162
185
|
`which layer the type belongs to.`;
|
|
163
186
|
return new api_lib_source_rule_1.ApiLibSite(line, snippet, what, cure);
|
|
@@ -177,7 +200,7 @@ let RequiredTypeSuffixValidator = class RequiredTypeSuffixValidator extends api_
|
|
|
177
200
|
picker = new SuffixEntryPicker();
|
|
178
201
|
scanner = new ExportedTypeScanner();
|
|
179
202
|
constructor(config, roleResolver, diffScope, scanScope) {
|
|
180
|
-
super(config,
|
|
203
|
+
super(config, 'required-type-suffix', roleResolver, diffScope, scanScope);
|
|
181
204
|
}
|
|
182
205
|
sitesIn(file) {
|
|
183
206
|
const winner = this.picker.winner(file.relFile, this.config.entries);
|
|
@@ -194,9 +217,9 @@ let RequiredTypeSuffixValidator = class RequiredTypeSuffixValidator extends api_
|
|
|
194
217
|
return `a directory required-type-suffix governs (${paths.join(', ')})`;
|
|
195
218
|
}
|
|
196
219
|
why() {
|
|
197
|
-
return
|
|
220
|
+
return ("every exported interface / class / enum / type there must end in one of its path's allowed suffixes — " +
|
|
198
221
|
'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +
|
|
199
|
-
'document), where an unsuffixed name reads the same as a server-internal or vendor type.';
|
|
222
|
+
'document), where an unsuffixed name reads the same as a server-internal or vendor type.');
|
|
200
223
|
}
|
|
201
224
|
};
|
|
202
225
|
exports.RequiredTypeSuffixValidator = RequiredTypeSuffixValidator;
|
|
@@ -204,7 +227,7 @@ exports.RequiredTypeSuffixValidator = RequiredTypeSuffixValidator = tslib_1.__de
|
|
|
204
227
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
205
228
|
tslib_1.__metadata("design:paramtypes", [required_type_suffix_config_1.RequiredTypeSuffixConfig,
|
|
206
229
|
project_role_resolver_1.ProjectRoleResolver,
|
|
207
|
-
|
|
230
|
+
rules_config_2.DiffScope,
|
|
208
231
|
scan_scope_1.ScanScope])
|
|
209
232
|
], RequiredTypeSuffixValidator);
|
|
210
233
|
//# sourceMappingURL=validate-required-type-suffix.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;AAEH,0DAAoE;AACpE,uFAA0G;AAC1G,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAC9D,6CAAyC;AAEzC,0GAA0G;AAC1G,MAAa,aAAa;IAET;IACA;IAFb,YACa,KAA8B,EAC9B,IAAY;QADZ,UAAK,GAAL,KAAK,CAAyB;QAC9B,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AALD,sCAKC;AAED;;;;GAIG;AACH,MAAa,iBAAiB;IAC1B,QAAQ,CAAC,OAAe,EAAE,OAA2C;QACjE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC;IAChD,CAAC;IAED,4GAA4G;IAC5G,MAAM,CAAC,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CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3F,OAAO,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,GAAG;QACT,OAAO,yGAAyG;YAC5G,uGAAuG;YACvG,yFAAyF,CAAC;IAClG,CAAC;CACJ,CAAA;AAlCY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAMzB,sDAAwB;QAClB,2CAAmB;QACtB,wBAAS;QACT,sBAAS;GARf,2BAA2B,CAkCvC","sourcesContent":["/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with the suffixes allowed there:\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"] }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"] }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the FIRST entry in config order whose paths match governs a file\n * ({@link SuffixEntryPicker}), so a narrower entry must be listed before a broader one; suffixes are never\n * unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport { DiffScope, matchesAnyGlob } from \"@webpieces/rules-config\";\nimport { RequiredTypeSuffixConfig, RequiredTypeSuffixEntry } from \"./configs/required-type-suffix-config\";\nimport { injectable, bindingScopeValues } from 'inversify';\nimport * as ts from 'typescript';\nimport { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The entry that governs a file, and the glob of it that matched — named in every failure. Data-only. */\nexport class GoverningGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file: the FIRST entry, in config order, with a glob matching the\n * file. Order matters — to give a narrower directory stricter suffixes, list its entry ABOVE the broader\n * one; listed below, it never applies to the files the broader entry already covers.\n */\nexport class SuffixEntryPicker {\n entryFor(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */\n winner(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): GoverningGlob | undefined {\n for (const entry of entries) {\n const glob = entry.paths.find((g: string) => matchesAnyGlob(relFile, [g]));\n if (glob !== undefined) return new GoverningGlob(entry, glob);\n }\n return undefined;\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface', 'Payload', 'Options', 'Object', 'Params', 'Output', 'Option', 'Record', 'Input', 'Model',\n 'Entry', 'Shape', 'Data', 'Info', 'Item', 'Type', 'Body', 'Row', 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find((s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()));\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find((t: string) => name.length > t.length && name.endsWith(t));\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(file, declared, declared.name, declared.name?.getText(file.source) ?? '', entry, glob);\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined) continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause)) continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get((element.propertyName ?? element.name).getText(file.source));\n if (local === undefined) continue;\n const site = this.judge(file, local, element.name, element.name.getText(file.source), entry, glob);\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) || ts.isClassDeclaration(statement)) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (entry.suffixes.some((suffix: string) => name.length > suffix.length && name.endsWith(suffix))) return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name).replace(/\\s+/g, ' ').trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates.slice(1).map((c: string) => `\\`${c}\\``).join(' / ');\n const cure = `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === '' ? '' : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(\n config: RequiredTypeSuffixConfig,\n roleResolver: ProjectRoleResolver,\n diffScope: DiffScope,\n scanScope: ScanScope,\n ) {\n super(config, \"required-type-suffix\", roleResolver, diffScope, scanScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return 'every exported interface / class / enum / type there must end in one of its path\\'s allowed suffixes — ' +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";;;;AAAA,0DAA6E;AAC7E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,0DAAoE;AACpE,uFAG+C;AAC/C,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAC9D,6CAAyC;AAEzC,0GAA0G;AAC1G,MAAa,aAAa;IAET;IACA;IAFb,YACa,KAA8B,EAC9B,IAAY;QADZ,UAAK,GAAL,KAAK,CAAyB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IAC9D,CAAC;IAED,yEAAyE;IACtD,kBAAkB,CAAC,cAAsB,EAAE,OAAe;QACzE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;IAC5E,CAAC;IAEkB,UAAU;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3F,OAAO,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,GAAG;QACT,OAAO,CACH,wGAAwG;YACxG,uGAAuG;YACvG,yFAAyF,CAC5F,CAAC;IACN,CAAC;CACJ,CAAA;AApCY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAMzB,sDAAwB;QAClB,2CAAmB;QACtB,wBAAS;QACT,sBAAS;GARf,2BAA2B,CAoCvC","sourcesContent":["import { FirstPathMatch, PathMatchCandidate } from '@webpieces/rules-config';\n/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with the suffixes allowed there:\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"] }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"] }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the FIRST entry in config order whose paths match governs a file\n * ({@link SuffixEntryPicker}), so a narrower entry must be listed before a broader one; suffixes are never\n * unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport { DiffScope, matchesAnyGlob } from '@webpieces/rules-config';\nimport {\n RequiredTypeSuffixConfig,\n RequiredTypeSuffixEntry,\n} from './configs/required-type-suffix-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport * as ts from 'typescript';\nimport { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The entry that governs a file, and the glob of it that matched — named in every failure. Data-only. */\nexport class GoverningGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file: the FIRST entry, in config order, with a glob matching the\n * file. Order matters — to give a narrower directory stricter suffixes, list its entry ABOVE the broader\n * one; listed below, it never applies to the files the broader entry already covers.\n */\nexport class SuffixEntryPicker {\n entryFor(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */\n winner(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): GoverningGlob | undefined {\n const match = new FirstPathMatch().winner(\n relFile,\n entries.map(\n (entry: RequiredTypeSuffixEntry) => new PathMatchCandidate(entry.paths, entry),\n ),\n );\n return match === undefined ? undefined : new GoverningGlob(match.entry, match.glob);\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface',\n 'Payload',\n 'Options',\n 'Object',\n 'Params',\n 'Output',\n 'Option',\n 'Record',\n 'Input',\n 'Model',\n 'Entry',\n 'Shape',\n 'Data',\n 'Info',\n 'Item',\n 'Type',\n 'Body',\n 'Row',\n 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find(\n (s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()),\n );\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find(\n (t: string) => name.length > t.length && name.endsWith(t),\n );\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(\n file,\n declared,\n declared.name,\n declared.name?.getText(file.source) ?? '',\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined)\n continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause))\n continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get(\n (element.propertyName ?? element.name).getText(file.source),\n );\n if (local === undefined) continue;\n const site = this.judge(\n file,\n local,\n element.name,\n element.name.getText(file.source),\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (\n ts.isInterfaceDeclaration(statement) ||\n ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) ||\n ts.isClassDeclaration(statement)\n ) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? (ts.getModifiers(statement) ?? []) : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (\n entry.suffixes.some(\n (suffix: string) => name.length > suffix.length && name.endsWith(suffix),\n )\n )\n return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name)\n .replace(/\\s+/g, ' ')\n .trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates\n .slice(1)\n .map((c: string) => `\\`${c}\\``)\n .join(' / ');\n const cure =\n `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === ''\n ? ''\n : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(\n config: RequiredTypeSuffixConfig,\n roleResolver: ProjectRoleResolver,\n diffScope: DiffScope,\n scanScope: ScanScope,\n ) {\n super(config, 'required-type-suffix', roleResolver, diffScope, scanScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return (\n \"every exported interface / class / enum / type there must end in one of its path's allowed suffixes — \" +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.'\n );\n }\n}\n"]}
|
package/src/wp-ci.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* wp-ci — the universal webpieces CI entrypoint.
|
|
4
|
+
*
|
|
5
|
+
* Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of
|
|
6
|
+
* "are we even in Nx?" cannot live inside an Nx executor (by the time an executor runs,
|
|
7
|
+
* Nx is already running). Dispatch:
|
|
8
|
+
*
|
|
9
|
+
* - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.
|
|
10
|
+
* - nx.json present, plugin NOT in it -> fail with the exact install command.
|
|
11
|
+
* - nx.json present, plugin registered -> normal branch: validators + affected `ci`;
|
|
12
|
+
* `/hotfix/` branch: affected `hotfix-ci` (build + test only).
|
|
13
|
+
*
|
|
14
|
+
* Repos reference this as a bin (`"webpieces:ci": "wp-ci"`) so the logic is versioned in
|
|
15
|
+
* the npm package instead of copy-pasted into each repo's package.json (which drifts).
|
|
16
|
+
*
|
|
17
|
+
* Every nx step goes through NxStepRunner, which spawns it into its own process group and refuses
|
|
18
|
+
* to return until that group has drained — a step whose workers outlive it holds the CI step's
|
|
19
|
+
* stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
package/src/wp-ci.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
3
|
/**
|
|
6
4
|
* wp-ci — the universal webpieces CI entrypoint.
|
|
7
5
|
*
|
|
@@ -21,17 +19,16 @@ const tslib_1 = require("tslib");
|
|
|
21
19
|
* to return until that group has drained — a step whose workers outlive it holds the CI step's
|
|
22
20
|
* stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.
|
|
23
21
|
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const tslib_1 = require("tslib");
|
|
24
24
|
const fs = tslib_1.__importStar(require("fs"));
|
|
25
25
|
const path = tslib_1.__importStar(require("path"));
|
|
26
|
-
require("reflect-metadata");
|
|
27
|
-
const inversify_1 = require("inversify");
|
|
28
26
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
29
27
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
30
28
|
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
31
29
|
const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const code_rules_config_table_1 = require("./code-rules-config-table");
|
|
30
|
+
const code_rules_bootstrap_1 = require("./code-rules-bootstrap");
|
|
31
|
+
const code_rules_run_request_1 = require("./code-rules-run-request");
|
|
35
32
|
const wp_ci_nx_runner_1 = require("./wp-ci-nx-runner");
|
|
36
33
|
const wp_ci_survivors_1 = require("./wp-ci-survivors");
|
|
37
34
|
/** How often the watchdog re-runs `ps` while waiting for a finished step's process group to drain. */
|
|
@@ -61,6 +58,7 @@ function isPluginRegistered(nxJsonPath) {
|
|
|
61
58
|
const parsed = JSON.parse(raw);
|
|
62
59
|
const plugins = parsed.plugins ?? [];
|
|
63
60
|
return plugins.some((entry) => pluginEntryMatches(entry));
|
|
61
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
64
62
|
}
|
|
65
63
|
catch (err) {
|
|
66
64
|
const error = (0, to_error_1.toError)(err);
|
|
@@ -75,18 +73,7 @@ async function runStandalone(cwd) {
|
|
|
75
73
|
return 0;
|
|
76
74
|
}
|
|
77
75
|
console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\n');
|
|
78
|
-
|
|
79
|
-
// autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
|
|
80
|
-
const container = new inversify_1.Container({ autobind: true });
|
|
81
|
-
container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
|
|
82
|
-
container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(loaded.matchRules));
|
|
83
|
-
for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
|
|
84
|
-
const ConfigClass = binding.configClass;
|
|
85
|
-
const configured = loaded.rulesConfig[binding.ruleId];
|
|
86
|
-
container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());
|
|
87
|
-
}
|
|
88
|
-
const app = container.get(code_rules_app_1.CodeRulesApp);
|
|
89
|
-
const result = await app.run();
|
|
76
|
+
const result = await new code_rules_bootstrap_1.CodeRulesBootstrap().run(workspaceRoot, new code_rules_run_request_1.CodeRulesRunRequest(undefined, undefined, undefined));
|
|
90
77
|
return result.success ? 0 : 1;
|
|
91
78
|
}
|
|
92
79
|
function reportPluginMissing() {
|
|
@@ -135,6 +122,7 @@ async function main() {
|
|
|
135
122
|
const ciCode = await runner.run(['affected', `--target=${target}`, ...passthrough], `nx affected --target=${target}`);
|
|
136
123
|
// webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary
|
|
137
124
|
process.exit(ciCode);
|
|
125
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
138
126
|
}
|
|
139
127
|
catch (err) {
|
|
140
128
|
const error = (0, to_error_1.toError)(err);
|
package/src/wp-ci.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wp-ci.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/wp-ci.ts"],"names":[],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,4BAA0B;AAC1B,yC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,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,8BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,iGAAiG;QACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { BaseRuleConfig } from '@webpieces/rules-sdk';\n/**\n * wp-ci — the universal webpieces CI entrypoint.\n *\n * Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of\n * \"are we even in Nx?\" cannot live inside an Nx executor (by the time an executor runs,\n * Nx is already running). Dispatch:\n *\n * - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.\n * - nx.json present, plugin NOT in it -> fail with the exact install command.\n * - nx.json present, plugin registered -> normal branch: validators + affected `ci`;\n * `/hotfix/` branch: affected `hotfix-ci` (build + test only).\n *\n * Repos reference this as a bin (`\"webpieces:ci\": \"wp-ci\"`) so the logic is versioned in\n * the npm package instead of copy-pasted into each repo's package.json (which drifts).\n *\n * Every nx step goes through NxStepRunner, which spawns it into its own process group and refuses\n * to return until that group has drained — a step whose workers outlive it holds the CI step's\n * stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { loadAndValidate, RuleFailError, renderRuleFailForHuman, RepoRootFinder } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CodeRulesApp } from './code-rules-app';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport { GracePeriodResolver, ProcessGroupKiller, ProcessGroupScanner, SurvivorReporter, SurvivorWatchdog } from './wp-ci-survivors';\n\n/** How often the watchdog re-runs `ps` while waiting for a finished step's process group to drain. */\nconst SURVIVOR_POLL_INTERVAL_MILLIS = 1000;\n\nconst NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';\n\ninterface NxPluginObject {\n plugin?: string;\n}\n\ntype NxPluginEntry = string | NxPluginObject;\n\ninterface RawNxJson {\n plugins?: NxPluginEntry[];\n}\n\nfunction findUp(filename: string, startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const candidate = path.join(dir, filename);\n if (fs.existsSync(candidate)) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nfunction pluginEntryMatches(entry: NxPluginEntry): boolean {\n if (typeof entry === 'string') return entry === NX_PLUGIN_NAME;\n return entry.plugin === NX_PLUGIN_NAME;\n}\n\nfunction isPluginRegistered(nxJsonPath: string): boolean {\n const raw = fs.readFileSync(nxJsonPath, 'utf8');\n // webpieces-disable no-unmanaged-exceptions -- rethrow as InformAiError so global catch surfaces readable message to AI\n try {\n const parsed = JSON.parse(raw) as RawNxJson;\n const plugins = parsed.plugins ?? [];\n return plugins.some((entry: NxPluginEntry) => pluginEntryMatches(entry));\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`);\n }\n}\n\nasync function runStandalone(cwd: string): Promise<number> {\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(cwd);\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');\n return 0;\n }\n console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\\n');\n\n // Composition root: bind runtime values, then resolve the app so inversify builds the whole DAG.\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(loaded.matchRules));\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding.configClass;\n const configured = loaded.rulesConfig[binding.ruleId] as BaseRuleConfig | undefined;\n container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());\n }\n\n const app = container.get(CodeRulesApp);\n const result = await app.run();\n return result.success ? 0 : 1;\n}\n\nfunction reportPluginMissing(): void {\n console.error('\\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\\n');\n console.error(' Install it so the validators run during CI:\\n');\n console.error(` nx add ${NX_PLUGIN_NAME}\\n`);\n console.error(' (or add it manually to the \"plugins\" array in nx.json).\\n');\n}\n\n// webpieces-disable no-unmanaged-exceptions -- global entry point for wp-ci CLI\nasync function main(): Promise<void> {\n try {\n const cwd = process.cwd();\n const passthrough = process.argv.slice(2);\n\n const nxJsonPath = findUp('nx.json', cwd);\n if (!nxJsonPath) {\n const code = await runStandalone(cwd);\n process.exit(code);\n }\n\n const root = path.dirname(nxJsonPath);\n if (!isPluginRegistered(nxJsonPath)) {\n reportPluginMissing();\n process.exit(1);\n }\n\n const gracePeriod = new GracePeriodResolver().resolve(process.env);\n const runner = new NxStepRunner(root, gracePeriod, new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS), new SurvivorReporter(), new ProcessGroupKiller());\n const hotfix = new BranchIdentity().isHotfix();\n\n // Validate the root policy exactly once. webpieces.config.json is deliberately NOT a\n // sharedGlobal Nx input: making every project hash depend on it turned a policy-only edit into\n // a workspace-wide compile/lint/test. The scoped rules project preserves the gate without that\n // fan-out.\n const rules = await runner.run(['run', 'rules:check'], 'rules:check');\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (rules !== 0) process.exit(rules);\n\n // Run the architecture + code validators next (this also runs the wiring guard,\n // which fails loudly if nx.json no longer wires validators into the build).\n if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {\n const validateCode = await runner.run(['run', 'architecture:validate-complete'], 'architecture:validate-complete');\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (validateCode !== 0) process.exit(validateCode);\n }\n\n // Hotfix deliberately schedules only compile/typecheck + tests. The shared branch resolver makes\n // this the same decision the local PR gate makes, including detached GitHub checkouts.\n const target = hotfix ? 'hotfix-ci' : 'ci';\n const ciCode = await runner.run(['affected', `--target=${target}`, ...passthrough], `nx affected --target=${target}`);\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\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(`[wp-ci] unexpected error: ${error.message}`);\n }\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(1);\n }\n}\n\nvoid main();\n"]}
|
|
1
|
+
{"version":3,"file":"wp-ci.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/wp-ci.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,0DAKiC;AACjC,8DAA0D;AAC1D,iEAA6D;AAC7D,sEAA+D;AAC/D,iEAA4D;AAC5D,qEAA+D;AAC/D,uDAAiD;AACjD,uDAM2B;AAE3B,sGAAsG;AACtG,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAE3C,MAAM,cAAc,GAAG,+BAA+B,CAAC;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ACjG,uFAAuF;QACvF,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAC3B,CAAC,UAAU,EAAE,YAAY,MAAM,EAAE,EAAE,GAAG,WAAW,CAAC,EAClD,wBAAwB,MAAM,EAAE,CACnC,CAAC;QACF,iGAAiG;QACjG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,6GAA6G;IAC7G,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,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,8BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,iGAAiG;QACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * wp-ci — the universal webpieces CI entrypoint.\n *\n * Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of\n * \"are we even in Nx?\" cannot live inside an Nx executor (by the time an executor runs,\n * Nx is already running). Dispatch:\n *\n * - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.\n * - nx.json present, plugin NOT in it -> fail with the exact install command.\n * - nx.json present, plugin registered -> normal branch: validators + affected `ci`;\n * `/hotfix/` branch: affected `hotfix-ci` (build + test only).\n *\n * Repos reference this as a bin (`\"webpieces:ci\": \"wp-ci\"`) so the logic is versioned in\n * the npm package instead of copy-pasted into each repo's package.json (which drifts).\n *\n * Every nx step goes through NxStepRunner, which spawns it into its own process group and refuses\n * to return until that group has drained — a step whose workers outlive it holds the CI step's\n * stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport {\n loadAndValidate,\n RuleFailError,\n renderRuleFailForHuman,\n RepoRootFinder,\n} from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport {\n GracePeriodResolver,\n ProcessGroupKiller,\n ProcessGroupScanner,\n SurvivorReporter,\n SurvivorWatchdog,\n} from './wp-ci-survivors';\n\n/** How often the watchdog re-runs `ps` while waiting for a finished step's process group to drain. */\nconst SURVIVOR_POLL_INTERVAL_MILLIS = 1000;\n\nconst NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';\n\ninterface NxPluginObject {\n plugin?: string;\n}\n\ntype NxPluginEntry = string | NxPluginObject;\n\ninterface RawNxJson {\n plugins?: NxPluginEntry[];\n}\n\nfunction findUp(filename: string, startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const candidate = path.join(dir, filename);\n if (fs.existsSync(candidate)) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nfunction pluginEntryMatches(entry: NxPluginEntry): boolean {\n if (typeof entry === 'string') return entry === NX_PLUGIN_NAME;\n return entry.plugin === NX_PLUGIN_NAME;\n}\n\nfunction isPluginRegistered(nxJsonPath: string): boolean {\n const raw = fs.readFileSync(nxJsonPath, 'utf8');\n // webpieces-disable no-unmanaged-exceptions -- rethrow as InformAiError so global catch surfaces readable message to AI\n try {\n const parsed = JSON.parse(raw) as RawNxJson;\n const plugins = parsed.plugins ?? [];\n return plugins.some((entry: NxPluginEntry) => pluginEntryMatches(entry));\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`,\n );\n }\n}\n\nasync function runStandalone(cwd: string): Promise<number> {\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(cwd);\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');\n return 0;\n }\n console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\\n');\n\n const result = await new CodeRulesBootstrap().run(\n workspaceRoot,\n new CodeRulesRunRequest(undefined, undefined, undefined),\n );\n return result.success ? 0 : 1;\n}\n\nfunction reportPluginMissing(): void {\n console.error('\\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\\n');\n console.error(' Install it so the validators run during CI:\\n');\n console.error(` nx add ${NX_PLUGIN_NAME}\\n`);\n console.error(' (or add it manually to the \"plugins\" array in nx.json).\\n');\n}\n\n// webpieces-disable no-unmanaged-exceptions -- global entry point for wp-ci CLI\nasync function main(): Promise<void> {\n try {\n const cwd = process.cwd();\n const passthrough = process.argv.slice(2);\n\n const nxJsonPath = findUp('nx.json', cwd);\n if (!nxJsonPath) {\n const code = await runStandalone(cwd);\n process.exit(code);\n }\n\n const root = path.dirname(nxJsonPath);\n if (!isPluginRegistered(nxJsonPath)) {\n reportPluginMissing();\n process.exit(1);\n }\n\n const gracePeriod = new GracePeriodResolver().resolve(process.env);\n const runner = new NxStepRunner(\n root,\n gracePeriod,\n new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS),\n new SurvivorReporter(),\n new ProcessGroupKiller(),\n );\n const hotfix = new BranchIdentity().isHotfix();\n\n // Validate the root policy exactly once. webpieces.config.json is deliberately NOT a\n // sharedGlobal Nx input: making every project hash depend on it turned a policy-only edit into\n // a workspace-wide compile/lint/test. The scoped rules project preserves the gate without that\n // fan-out.\n const rules = await runner.run(['run', 'rules:check'], 'rules:check');\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (rules !== 0) process.exit(rules);\n\n // Run the architecture + code validators next (this also runs the wiring guard,\n // which fails loudly if nx.json no longer wires validators into the build).\n if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {\n const validateCode = await runner.run(\n ['run', 'architecture:validate-complete'],\n 'architecture:validate-complete',\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (validateCode !== 0) process.exit(validateCode);\n }\n\n // Hotfix deliberately schedules only compile/typecheck + tests. The shared branch resolver makes\n // this the same decision the local PR gate makes, including detached GitHub checkouts.\n const target = hotfix ? 'hotfix-ci' : 'ci';\n const ciCode = await runner.run(\n ['affected', `--target=${target}`, ...passthrough],\n `nx affected --target=${target}`,\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\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(`[wp-ci] unexpected error: ${error.message}`);\n }\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(1);\n }\n}\n\nvoid main();\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseRuleConfig, FieldDef } from '@webpieces/rules-sdk';
|
|
2
|
-
/** A concrete configuration data constructor used as the owner DI token. */
|
|
3
|
-
export type ConfigCtor = new () => BaseRuleConfig;
|
|
4
|
-
/** An owner-local configuration binding and its canonical schema. */
|
|
5
|
-
export declare class ConfigBinding {
|
|
6
|
-
readonly configClass: ConfigCtor;
|
|
7
|
-
readonly ruleId: string;
|
|
8
|
-
readonly schema: Readonly<Record<string, FieldDef>>;
|
|
9
|
-
constructor(configClass: ConfigCtor, ruleId: string, schema: Readonly<Record<string, FieldDef>>);
|
|
10
|
-
}
|
|
11
|
-
export declare const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONFIG_BINDINGS = exports.ConfigBinding = void 0;
|
|
4
|
-
const rule_configs_1 = require("./configs/rule-configs");
|
|
5
|
-
const no_client_creation_config_1 = require("./configs/no-client-creation-config");
|
|
6
|
-
const no_state_paths_config_1 = require("./configs/no-state-paths-config");
|
|
7
|
-
const api_lib_spelling_configs_1 = require("./configs/api-lib-spelling-configs");
|
|
8
|
-
const no_utility_types_config_1 = require("./configs/no-utility-types-config");
|
|
9
|
-
const required_type_suffix_config_1 = require("./configs/required-type-suffix-config");
|
|
10
|
-
const tag_truth_configs_1 = require("./configs/tag-truth-configs");
|
|
11
|
-
/** An owner-local configuration binding and its canonical schema. */
|
|
12
|
-
class ConfigBinding {
|
|
13
|
-
configClass;
|
|
14
|
-
ruleId;
|
|
15
|
-
schema;
|
|
16
|
-
constructor(configClass, ruleId, schema) {
|
|
17
|
-
this.configClass = configClass;
|
|
18
|
-
this.ruleId = ruleId;
|
|
19
|
-
this.schema = schema;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.ConfigBinding = ConfigBinding;
|
|
23
|
-
exports.CONFIG_BINDINGS = [
|
|
24
|
-
new ConfigBinding(rule_configs_1.MaxMethodLinesConfig, 'max-method-lines', rule_configs_1.MaxMethodLinesConfig.SCHEMA),
|
|
25
|
-
new ConfigBinding(rule_configs_1.MaxFileLinesConfig, 'max-file-lines', rule_configs_1.MaxFileLinesConfig.SCHEMA),
|
|
26
|
-
new ConfigBinding(rule_configs_1.RequireReturnTypeConfig, 'require-return-type', rule_configs_1.RequireReturnTypeConfig.SCHEMA),
|
|
27
|
-
new ConfigBinding(rule_configs_1.NoInlineTypeLiteralsConfig, 'no-inline-type-literals', rule_configs_1.NoInlineTypeLiteralsConfig.SCHEMA),
|
|
28
|
-
new ConfigBinding(rule_configs_1.NoAnyUnknownConfig, 'no-any-unknown', rule_configs_1.NoAnyUnknownConfig.SCHEMA),
|
|
29
|
-
new ConfigBinding(rule_configs_1.NoImplicitAnyConfig, 'no-implicit-any', rule_configs_1.NoImplicitAnyConfig.SCHEMA),
|
|
30
|
-
new ConfigBinding(rule_configs_1.PrismaValidateDtosConfig, 'prisma-validate-dtos', rule_configs_1.PrismaValidateDtosConfig.SCHEMA),
|
|
31
|
-
new ConfigBinding(rule_configs_1.PrismaConverterConfig, 'prisma-converter', rule_configs_1.PrismaConverterConfig.SCHEMA),
|
|
32
|
-
new ConfigBinding(rule_configs_1.NoDestructureConfig, 'no-destructure', rule_configs_1.NoDestructureConfig.SCHEMA),
|
|
33
|
-
new ConfigBinding(rule_configs_1.CatchErrorPatternConfig, 'catch-error-pattern', rule_configs_1.CatchErrorPatternConfig.SCHEMA),
|
|
34
|
-
new ConfigBinding(rule_configs_1.NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions', rule_configs_1.NoUnmanagedExceptionsConfig.SCHEMA),
|
|
35
|
-
new ConfigBinding(rule_configs_1.AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver', rule_configs_1.AngularNoDirectApiInResolverConfig.SCHEMA),
|
|
36
|
-
new ConfigBinding(rule_configs_1.NoSymbolDiTokensConfig, 'no-symbol-di-tokens', rule_configs_1.NoSymbolDiTokensConfig.SCHEMA),
|
|
37
|
-
new ConfigBinding(no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client', no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig.SCHEMA),
|
|
38
|
-
new ConfigBinding(rule_configs_1.NoCustomCssConfig, 'no-custom-css', rule_configs_1.NoCustomCssConfig.SCHEMA),
|
|
39
|
-
new ConfigBinding(no_state_paths_config_1.NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates', no_state_paths_config_1.NoStatePathsInTemplatesConfig.SCHEMA),
|
|
40
|
-
new ConfigBinding(rule_configs_1.NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main', rule_configs_1.NoProcessExitOutsideMainConfig.SCHEMA),
|
|
41
|
-
new ConfigBinding(rule_configs_1.NoFunctionOutsideClassConfig, 'no-function-outside-class', rule_configs_1.NoFunctionOutsideClassConfig.SCHEMA),
|
|
42
|
-
new ConfigBinding(rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig, 'inject-annotation-not-needed-for-concrete-class', rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA),
|
|
43
|
-
new ConfigBinding(rule_configs_1.FrameworkTagConfig, 'framework-tag', rule_configs_1.FrameworkTagConfig.SCHEMA),
|
|
44
|
-
new ConfigBinding(rule_configs_1.RoleTagConfig, 'role-tag', rule_configs_1.RoleTagConfig.SCHEMA),
|
|
45
|
-
new ConfigBinding(rule_configs_1.EnsureWeAreSecureConfig, 'ensure-we-are-secure', rule_configs_1.EnsureWeAreSecureConfig.SCHEMA),
|
|
46
|
-
new ConfigBinding(api_lib_spelling_configs_1.NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib', api_lib_spelling_configs_1.NoInlineImportInApiLibConfig.SCHEMA),
|
|
47
|
-
new ConfigBinding(api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib', api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig.SCHEMA),
|
|
48
|
-
new ConfigBinding(no_utility_types_config_1.NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib', no_utility_types_config_1.NoUtilityTypesInApiLibConfig.SCHEMA),
|
|
49
|
-
new ConfigBinding(required_type_suffix_config_1.RequiredTypeSuffixConfig, 'required-type-suffix', required_type_suffix_config_1.RequiredTypeSuffixConfig.SCHEMA),
|
|
50
|
-
new ConfigBinding(tag_truth_configs_1.FrameworkTsconfigConfig, 'framework-tsconfig', tag_truth_configs_1.FrameworkTsconfigConfig.SCHEMA),
|
|
51
|
-
new ConfigBinding(tag_truth_configs_1.FrameworkPackagesConfig, 'framework-packages', tag_truth_configs_1.FrameworkPackagesConfig.SCHEMA),
|
|
52
|
-
];
|
|
53
|
-
//# sourceMappingURL=code-rules-config-table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AACA,yDAAsiB;AACtiB,mFAAkG;AAClG,2EAAgF;AAChF,iFAAiH;AACjH,+EAAiF;AACjF,uFAAiF;AACjF,mEAA+F;AAK/F,qEAAqE;AACrE,MAAa,aAAa;IAET;IACA;IACA;IAHb,YACa,WAAuB,EACvB,MAAc,EACd,MAA0C;QAF1C,gBAAW,GAAX,WAAW,CAAY;QACvB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAoC;IACpD,CAAC;CACP;AAND,sCAMC;AAEY,QAAA,eAAe,GAAiC;IACzD,IAAI,aAAa,CAAC,mCAAoB,EAAE,kBAAkB,EAAE,mCAAoB,CAAC,MAAM,CAAC;IACxF,IAAI,aAAa,CAAC,iCAAkB,EAAE,gBAAgB,EAAE,iCAAkB,CAAC,MAAM,CAAC;IAClF,IAAI,aAAa,CAAC,sCAAuB,EAAE,qBAAqB,EAAE,sCAAuB,CAAC,MAAM,CAAC;IACjG,IAAI,aAAa,CAAC,yCAA0B,EAAE,yBAAyB,EAAE,yCAA0B,CAAC,MAAM,CAAC;IAC3G,IAAI,aAAa,CAAC,iCAAkB,EAAE,gBAAgB,EAAE,iCAAkB,CAAC,MAAM,CAAC;IAClF,IAAI,aAAa,CAAC,kCAAmB,EAAE,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E,IAAI,aAAa,CAAC,sCAAuB,EAAE,sBAAsB,EAAE,sCAAuB,CAAC,MAAM,CAAC;IAClG,IAAI,aAAa,CAAC,uDAA4B,EAAE,6BAA6B,EAAE,uDAA4B,CAAC,MAAM,CAAC;IACnH,IAAI,aAAa,CAAC,wDAA6B,EAAE,8BAA8B,EAAE,wDAA6B,CAAC,MAAM,CAAC;IACtH,IAAI,aAAa,CAAC,sDAA4B,EAAE,6BAA6B,EAAE,sDAA4B,CAAC,MAAM,CAAC;IACnH,IAAI,aAAa,CAAC,sDAAwB,EAAE,sBAAsB,EAAE,sDAAwB,CAAC,MAAM,CAAC;IACpG,IAAI,aAAa,CAAC,2CAAuB,EAAE,oBAAoB,EAAE,2CAAuB,CAAC,MAAM,CAAC;IAChG,IAAI,aAAa,CAAC,2CAAuB,EAAE,oBAAoB,EAAE,2CAAuB,CAAC,MAAM,CAAC;CACnG,CAAC","sourcesContent":["import { BaseRuleConfig, FieldDef } from '@webpieces/rules-sdk';\nimport { MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, CatchErrorPatternConfig, NoUnmanagedExceptionsConfig, AngularNoDirectApiInResolverConfig, NoSymbolDiTokensConfig, NoCustomCssConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig } from \"./configs/rule-configs\";\nimport { NoClientCreationOutsideServerOrClientConfig } from \"./configs/no-client-creation-config\";\nimport { NoStatePathsInTemplatesConfig } from \"./configs/no-state-paths-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 { FrameworkTsconfigConfig, FrameworkPackagesConfig } from \"./configs/tag-truth-configs\";\n\n/** A concrete configuration data constructor used as the owner DI token. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\n/** An owner-local configuration binding and its canonical schema. */\nexport class ConfigBinding {\n constructor(\n readonly configClass: ConfigCtor,\n readonly ruleId: string,\n readonly schema: Readonly<Record<string, FieldDef>>,\n ) {}\n}\n\nexport const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding> = [\n new ConfigBinding(MaxMethodLinesConfig, 'max-method-lines', MaxMethodLinesConfig.SCHEMA),\n new ConfigBinding(MaxFileLinesConfig, 'max-file-lines', MaxFileLinesConfig.SCHEMA),\n new ConfigBinding(RequireReturnTypeConfig, 'require-return-type', RequireReturnTypeConfig.SCHEMA),\n new ConfigBinding(NoInlineTypeLiteralsConfig, 'no-inline-type-literals', NoInlineTypeLiteralsConfig.SCHEMA),\n new ConfigBinding(NoAnyUnknownConfig, 'no-any-unknown', NoAnyUnknownConfig.SCHEMA),\n new ConfigBinding(NoImplicitAnyConfig, 'no-implicit-any', NoImplicitAnyConfig.SCHEMA),\n new ConfigBinding(PrismaValidateDtosConfig, 'prisma-validate-dtos', PrismaValidateDtosConfig.SCHEMA),\n new ConfigBinding(PrismaConverterConfig, 'prisma-converter', PrismaConverterConfig.SCHEMA),\n new ConfigBinding(NoDestructureConfig, 'no-destructure', NoDestructureConfig.SCHEMA),\n new ConfigBinding(CatchErrorPatternConfig, 'catch-error-pattern', CatchErrorPatternConfig.SCHEMA),\n new ConfigBinding(NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions', NoUnmanagedExceptionsConfig.SCHEMA),\n new ConfigBinding(AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver', AngularNoDirectApiInResolverConfig.SCHEMA),\n new ConfigBinding(NoSymbolDiTokensConfig, 'no-symbol-di-tokens', NoSymbolDiTokensConfig.SCHEMA),\n new ConfigBinding(NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client', NoClientCreationOutsideServerOrClientConfig.SCHEMA),\n new ConfigBinding(NoCustomCssConfig, 'no-custom-css', NoCustomCssConfig.SCHEMA),\n new ConfigBinding(NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates', NoStatePathsInTemplatesConfig.SCHEMA),\n new ConfigBinding(NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main', NoProcessExitOutsideMainConfig.SCHEMA),\n new ConfigBinding(NoFunctionOutsideClassConfig, 'no-function-outside-class', NoFunctionOutsideClassConfig.SCHEMA),\n new ConfigBinding(InjectAnnotationNotNeededForConcreteClassConfig, 'inject-annotation-not-needed-for-concrete-class', InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA),\n new ConfigBinding(FrameworkTagConfig, 'framework-tag', FrameworkTagConfig.SCHEMA),\n new ConfigBinding(RoleTagConfig, 'role-tag', RoleTagConfig.SCHEMA),\n new ConfigBinding(EnsureWeAreSecureConfig, 'ensure-we-are-secure', EnsureWeAreSecureConfig.SCHEMA),\n new ConfigBinding(NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib', NoInlineImportInApiLibConfig.SCHEMA),\n new ConfigBinding(OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib', OneEnumSpellingInApiLibConfig.SCHEMA),\n new ConfigBinding(NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib', NoUtilityTypesInApiLibConfig.SCHEMA),\n new ConfigBinding(RequiredTypeSuffixConfig, 'required-type-suffix', RequiredTypeSuffixConfig.SCHEMA),\n new ConfigBinding(FrameworkTsconfigConfig, 'framework-tsconfig', FrameworkTsconfigConfig.SCHEMA),\n new ConfigBinding(FrameworkPackagesConfig, 'framework-packages', FrameworkPackagesConfig.SCHEMA),\n];\n"]}
|