@webpieces/code-rules 0.4.846 โ†’ 0.4.848

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/code-rules",
3
- "version": "0.4.846",
3
+ "version": "0.4.848",
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,23 +16,24 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.846",
19
+ "@webpieces/rules-config": "0.4.848",
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.846",
24
- "@webpieces/repo-workflow-core": "0.4.846",
25
- "@webpieces/rules-sdk": "0.4.846"
23
+ "@webpieces/tooling-common": "0.4.848",
24
+ "@webpieces/repo-workflow-core": "0.4.848",
25
+ "@webpieces/rules-sdk": "0.4.848"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "devDependencies": {
31
- "@webpieces/tooling-testkit": "0.4.846"
31
+ "@webpieces/tooling-testkit": "0.4.848"
32
32
  },
33
33
  "exports": {
34
34
  ".": "./src/index.js",
35
- "./rule-pack": "./src/rule-pack.js"
35
+ "./rule-pack": "./src/rule-pack.js",
36
+ "./rule-runtime": "./src/rule-runtime.js"
36
37
  },
37
38
  "types": "./src/index.d.ts",
38
39
  "bin": {
@@ -0,0 +1,9 @@
1
+ import 'reflect-metadata';
2
+ import { Container } from 'inversify';
3
+ import { BuildPolicy, BuildRuleRuntime, PolicyRuntimeRequest } from '@webpieces/rules-sdk';
4
+ /** Composition stays with the code owner; the public manifest never imports validators. */
5
+ export declare class CodeRuleRuntime implements BuildRuleRuntime {
6
+ create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]>;
7
+ compose(request: PolicyRuntimeRequest, projects: readonly string[] | undefined): Promise<Container>;
8
+ private entry;
9
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeRuleRuntime = void 0;
4
+ require("reflect-metadata");
5
+ const inversify_1 = require("inversify");
6
+ const tooling_common_1 = require("@webpieces/tooling-common");
7
+ const code_policy_registry_1 = require("./code-policy-registry");
8
+ const code_rules_context_1 = require("./code-rules-context");
9
+ const scan_scope_1 = require("./scan-scope");
10
+ const code_rules_engine_1 = require("./code-rules-engine");
11
+ /** Composition stays with the code owner; the public manifest never imports validators. */
12
+ class CodeRuleRuntime {
13
+ async create(request) {
14
+ return (await this.compose(request, undefined)).get(code_rules_engine_1.BuildPolicySet).policies;
15
+ }
16
+ async compose(request, projects) {
17
+ const container = new inversify_1.Container({ autobind: true });
18
+ container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(request.workspaceRoot));
19
+ container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(projects));
20
+ const policies = request.ruleIds.map((id) => this.entry(id));
21
+ for (const policy of policies) {
22
+ const config = request.configs[policy.ruleId];
23
+ if (!config)
24
+ throw new tooling_common_1.InformAiError(`Missing explicit config for ${policy.ruleId}. Repair its declared owner file.`);
25
+ container.bind(policy.configClass).toConstantValue(config);
26
+ }
27
+ const checks = await Promise.all(policies.map(async (policy) => container.get(await policy.loadValidator())));
28
+ container.bind(code_rules_engine_1.BuildPolicySet).toConstantValue(new code_rules_engine_1.BuildPolicySet(checks));
29
+ return container;
30
+ }
31
+ entry(id) {
32
+ const entry = code_policy_registry_1.CODE_POLICIES.find((policy) => policy.ruleId === id);
33
+ if (!entry)
34
+ throw new tooling_common_1.InformAiError(`Code runtime has no implementation of ${id}. Repair the owner's contribution.`);
35
+ return entry;
36
+ }
37
+ }
38
+ exports.CodeRuleRuntime = CodeRuleRuntime;
39
+ //# sourceMappingURL=code-policy-composition.js.map
@@ -0,0 +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;AAStC,8DAA0D;AAC1D,iEAAmE;AACnE,6DAAqD;AACrD,6CAA+C;AAC/C,2DAAqD;AAErD,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,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,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM;gBACP,MAAM,IAAI,8BAAa,CACnB,+BAA+B,MAAM,CAAC,MAAM,mCAAmC,CAClF,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC5B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAkB,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAC1F,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,kCAAc,CAAC,CAAC,eAAe,CAAC,IAAI,kCAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3E,OAAO,SAAS,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,EAAU;QACpB,MAAM,KAAK,GAAG,oCAAa,CAAC,IAAI,CAAC,CAAC,MAAkB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK;YACN,MAAM,IAAI,8BAAa,CACnB,yCAAyC,EAAE,oCAAoC,CAClF,CAAC;QACN,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AApCD,0CAoCC","sourcesContent":["import 'reflect-metadata';\nimport { Container } from 'inversify';\nimport {\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';\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 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 const checks = await Promise.all(\n policies.map(async (policy: CodePolicy) => container.get(await policy.loadValidator())),\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"]}
@@ -0,0 +1,12 @@
1
+ import { BaseRuleConfig, FieldDef, BuildPolicy } from '@webpieces/rules-sdk';
2
+ /** The owner entry declares both its schema token and executable validator. */
3
+ export type ConfigCtor = new () => BaseRuleConfig;
4
+ export type ValidatorCtor = new (...args: never[]) => BuildPolicy;
5
+ export declare class CodePolicy {
6
+ readonly configClass: ConfigCtor;
7
+ readonly ruleId: string;
8
+ readonly loadValidator: () => Promise<ValidatorCtor>;
9
+ readonly schema: Readonly<Record<string, FieldDef>>;
10
+ constructor(configClass: ConfigCtor, ruleId: string, loadValidator: () => Promise<ValidatorCtor>, schema: Readonly<Record<string, FieldDef>>);
11
+ }
12
+ export declare const CODE_POLICIES: readonly CodePolicy[];
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CODE_POLICIES = exports.CodePolicy = void 0;
37
+ const rule_configs_1 = require("./configs/rule-configs");
38
+ const no_client_creation_config_1 = require("./configs/no-client-creation-config");
39
+ const no_state_paths_config_1 = require("./configs/no-state-paths-config");
40
+ const api_lib_spelling_configs_1 = require("./configs/api-lib-spelling-configs");
41
+ const no_utility_types_config_1 = require("./configs/no-utility-types-config");
42
+ const required_type_suffix_config_1 = require("./configs/required-type-suffix-config");
43
+ const tag_truth_configs_1 = require("./configs/tag-truth-configs");
44
+ class CodePolicy {
45
+ configClass;
46
+ ruleId;
47
+ loadValidator;
48
+ schema;
49
+ // eslint-disable-next-line @typescript-eslint/max-params
50
+ constructor(configClass, ruleId, loadValidator, schema) {
51
+ this.configClass = configClass;
52
+ this.ruleId = ruleId;
53
+ this.loadValidator = loadValidator;
54
+ this.schema = schema;
55
+ }
56
+ }
57
+ exports.CodePolicy = CodePolicy;
58
+ exports.CODE_POLICIES = [
59
+ new CodePolicy(rule_configs_1.MaxMethodLinesConfig, 'max-method-lines', async () => (await Promise.resolve().then(() => __importStar(require('./validate-modified-methods')))).MaxMethodLinesValidator, rule_configs_1.MaxMethodLinesConfig.SCHEMA),
60
+ new CodePolicy(rule_configs_1.MaxFileLinesConfig, 'max-file-lines', async () => (await Promise.resolve().then(() => __importStar(require('./validate-modified-files')))).MaxFileLinesValidator, rule_configs_1.MaxFileLinesConfig.SCHEMA),
61
+ new CodePolicy(rule_configs_1.RequireReturnTypeConfig, 'require-return-type', async () => (await Promise.resolve().then(() => __importStar(require('./validate-return-types')))).RequireReturnTypeValidator, rule_configs_1.RequireReturnTypeConfig.SCHEMA),
62
+ new CodePolicy(rule_configs_1.NoInlineTypeLiteralsConfig, 'no-inline-type-literals', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-inline-types')))).NoInlineTypeLiteralsValidator, rule_configs_1.NoInlineTypeLiteralsConfig.SCHEMA),
63
+ new CodePolicy(rule_configs_1.NoAnyUnknownConfig, 'no-any-unknown', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-any-unknown')))).NoAnyUnknownValidator, rule_configs_1.NoAnyUnknownConfig.SCHEMA),
64
+ new CodePolicy(rule_configs_1.NoImplicitAnyConfig, 'no-implicit-any', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-implicit-any')))).NoImplicitAnyValidator, rule_configs_1.NoImplicitAnyConfig.SCHEMA),
65
+ new CodePolicy(rule_configs_1.PrismaValidateDtosConfig, 'prisma-validate-dtos', async () => (await Promise.resolve().then(() => __importStar(require('./validate-dtos')))).PrismaValidateDtosValidator, rule_configs_1.PrismaValidateDtosConfig.SCHEMA),
66
+ new CodePolicy(rule_configs_1.PrismaConverterConfig, 'prisma-converter', async () => (await Promise.resolve().then(() => __importStar(require('./validate-prisma-converters')))).PrismaConverterValidator, rule_configs_1.PrismaConverterConfig.SCHEMA),
67
+ new CodePolicy(rule_configs_1.NoDestructureConfig, 'no-destructure', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-destructure')))).NoDestructureValidator, rule_configs_1.NoDestructureConfig.SCHEMA),
68
+ new CodePolicy(rule_configs_1.CatchErrorPatternConfig, 'catch-error-pattern', async () => (await Promise.resolve().then(() => __importStar(require('./validate-catch-error-pattern')))).CatchErrorPatternValidator, rule_configs_1.CatchErrorPatternConfig.SCHEMA),
69
+ new CodePolicy(rule_configs_1.NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-unmanaged-exceptions')))).NoUnmanagedExceptionsValidator, rule_configs_1.NoUnmanagedExceptionsConfig.SCHEMA),
70
+ new CodePolicy(rule_configs_1.AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-direct-api-resolver')))).NoDirectApiResolverValidator, rule_configs_1.AngularNoDirectApiInResolverConfig.SCHEMA),
71
+ new CodePolicy(rule_configs_1.NoSymbolDiTokensConfig, 'no-symbol-di-tokens', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-symbol-di-tokens')))).NoSymbolDiTokensValidator, rule_configs_1.NoSymbolDiTokensConfig.SCHEMA),
72
+ new CodePolicy(no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-client-creation-outside-server-or-client'))))
73
+ .NoClientCreationOutsideServerOrClientValidator, no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig.SCHEMA),
74
+ new CodePolicy(rule_configs_1.NoCustomCssConfig, 'no-custom-css', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-custom-css')))).NoCustomCssValidator, rule_configs_1.NoCustomCssConfig.SCHEMA),
75
+ new CodePolicy(no_state_paths_config_1.NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-state-paths-in-templates'))))
76
+ .NoStatePathsInTemplatesValidator, no_state_paths_config_1.NoStatePathsInTemplatesConfig.SCHEMA),
77
+ new CodePolicy(rule_configs_1.NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-process-exit-outside-main'))))
78
+ .NoProcessExitOutsideMainValidator, rule_configs_1.NoProcessExitOutsideMainConfig.SCHEMA),
79
+ new CodePolicy(rule_configs_1.NoFunctionOutsideClassConfig, 'no-function-outside-class', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-function-outside-class')))).NoFunctionOutsideClassValidator, rule_configs_1.NoFunctionOutsideClassConfig.SCHEMA),
80
+ new CodePolicy(rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig, 'inject-annotation-not-needed-for-concrete-class', async () => (await Promise.resolve().then(() => __importStar(require('./validate-inject-annotation-not-needed-for-concrete-class'))))
81
+ .InjectAnnotationNotNeededForConcreteClassValidator, rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA),
82
+ new CodePolicy(rule_configs_1.FrameworkTagConfig, 'framework-tag', async () => (await Promise.resolve().then(() => __importStar(require('./validate-framework-tag')))).FrameworkTagValidator, rule_configs_1.FrameworkTagConfig.SCHEMA),
83
+ new CodePolicy(rule_configs_1.RoleTagConfig, 'role-tag', async () => (await Promise.resolve().then(() => __importStar(require('./validate-role-tag')))).RoleTagValidator, rule_configs_1.RoleTagConfig.SCHEMA),
84
+ new CodePolicy(rule_configs_1.EnsureWeAreSecureConfig, 'ensure-we-are-secure', async () => (await Promise.resolve().then(() => __importStar(require('./validate-ensure-we-are-secure')))).EnsureWeAreSecureValidator, rule_configs_1.EnsureWeAreSecureConfig.SCHEMA),
85
+ new CodePolicy(api_lib_spelling_configs_1.NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-inline-import-in-api-lib'))))
86
+ .NoInlineImportInApiLibValidator, api_lib_spelling_configs_1.NoInlineImportInApiLibConfig.SCHEMA),
87
+ new CodePolicy(api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib', async () => (await Promise.resolve().then(() => __importStar(require('./validate-one-enum-spelling-in-api-lib'))))
88
+ .OneEnumSpellingInApiLibValidator, api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig.SCHEMA),
89
+ new CodePolicy(no_utility_types_config_1.NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib', async () => (await Promise.resolve().then(() => __importStar(require('./validate-no-utility-types-in-api-lib'))))
90
+ .NoUtilityTypesInApiLibValidator, no_utility_types_config_1.NoUtilityTypesInApiLibConfig.SCHEMA),
91
+ new CodePolicy(required_type_suffix_config_1.RequiredTypeSuffixConfig, 'required-type-suffix', async () => (await Promise.resolve().then(() => __importStar(require('./validate-required-type-suffix')))).RequiredTypeSuffixValidator, required_type_suffix_config_1.RequiredTypeSuffixConfig.SCHEMA),
92
+ new CodePolicy(tag_truth_configs_1.FrameworkTsconfigConfig, 'framework-tsconfig', async () => (await Promise.resolve().then(() => __importStar(require('./validate-framework-tsconfig')))).FrameworkTsconfigValidator, tag_truth_configs_1.FrameworkTsconfigConfig.SCHEMA),
93
+ new CodePolicy(tag_truth_configs_1.FrameworkPackagesConfig, 'framework-packages', async () => (await Promise.resolve().then(() => __importStar(require('./validate-framework-packages')))).FrameworkPackagesValidator, tag_truth_configs_1.FrameworkPackagesConfig.SCHEMA),
94
+ ];
95
+ //# sourceMappingURL=code-policy-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-policy-registry.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-policy-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yDAqBgC;AAChC,mFAAkG;AAClG,2EAAgF;AAChF,iFAG4C;AAC5C,+EAAiF;AACjF,uFAAiF;AACjF,mEAA+F;AAO/F,MAAa,UAAU;IAGN;IACA;IACA;IACA;I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ACV,uDAA4B,EAC5B,6BAA6B,EAC7B,KAAK,IAAI,EAAE,CACP,CAAC,wDAAa,wCAAwC,GAAC,CAAC;SACnD,+BAA+B,EACxC,uDAA4B,CAAC,MAAM,CACtC;IACD,IAAI,UAAU,CACV,wDAA6B,EAC7B,8BAA8B,EAC9B,KAAK,IAAI,EAAE,CACP,CAAC,wDAAa,yCAAyC,GAAC,CAAC;SACpD,gCAAgC,EACzC,wDAA6B,CAAC,MAAM,CACvC;IACD,IAAI,UAAU,CACV,sDAA4B,EAC5B,6BAA6B,EAC7B,KAAK,IAAI,EAAE,CACP,CAAC,wDAAa,wCAAwC,GAAC,CAAC;SACnD,+BAA+B,EACxC,sDAA4B,CAAC,MAAM,CACtC;IACD,IAAI,UAAU,CACV,sDAAwB,EACxB,sBAAsB,EACtB,KAAK,IAAI,EAAE,CAAC,CAAC,wDAAa,iCAAiC,GAAC,CAAC,CAAC,2BAA2B,EACzF,sDAAwB,CAAC,MAAM,CAClC;IACD,IAAI,UAAU,CACV,2CAAuB,EACvB,oBAAoB,EACpB,KAAK,IAAI,EAAE,CAAC,CAAC,wDAAa,+BAA+B,GAAC,CAAC,CAAC,0BAA0B,EACtF,2CAAuB,CAAC,MAAM,CACjC;IACD,IAAI,UAAU,CACV,2CAAuB,EACvB,oBAAoB,EACpB,KAAK,IAAI,EAAE,CAAC,CAAC,wDAAa,+BAA+B,GAAC,CAAC,CAAC,0BAA0B,EACtF,2CAAuB,CAAC,MAAM,CACjC;CACJ,CAAC","sourcesContent":["import { BaseRuleConfig, FieldDef, BuildPolicy } from '@webpieces/rules-sdk';\nimport {\n MaxMethodLinesConfig,\n MaxFileLinesConfig,\n RequireReturnTypeConfig,\n NoInlineTypeLiteralsConfig,\n NoAnyUnknownConfig,\n NoImplicitAnyConfig,\n PrismaValidateDtosConfig,\n PrismaConverterConfig,\n NoDestructureConfig,\n CatchErrorPatternConfig,\n NoUnmanagedExceptionsConfig,\n AngularNoDirectApiInResolverConfig,\n NoSymbolDiTokensConfig,\n NoCustomCssConfig,\n NoProcessExitOutsideMainConfig,\n NoFunctionOutsideClassConfig,\n InjectAnnotationNotNeededForConcreteClassConfig,\n FrameworkTagConfig,\n RoleTagConfig,\n EnsureWeAreSecureConfig,\n} from './configs/rule-configs';\nimport { NoClientCreationOutsideServerOrClientConfig } from './configs/no-client-creation-config';\nimport { NoStatePathsInTemplatesConfig } from './configs/no-state-paths-config';\nimport {\n NoInlineImportInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n} 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/** The owner entry declares both its schema token and executable validator. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\nexport type ValidatorCtor = new (...args: never[]) => BuildPolicy;\n\nexport class CodePolicy {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n readonly configClass: ConfigCtor,\n readonly ruleId: string,\n readonly loadValidator: () => Promise<ValidatorCtor>,\n readonly schema: Readonly<Record<string, FieldDef>>,\n ) {}\n}\n\nexport const CODE_POLICIES: readonly CodePolicy[] = [\n new CodePolicy(\n MaxMethodLinesConfig,\n 'max-method-lines',\n async () => (await import('./validate-modified-methods')).MaxMethodLinesValidator,\n MaxMethodLinesConfig.SCHEMA,\n ),\n new CodePolicy(\n MaxFileLinesConfig,\n 'max-file-lines',\n async () => (await import('./validate-modified-files')).MaxFileLinesValidator,\n MaxFileLinesConfig.SCHEMA,\n ),\n new CodePolicy(\n RequireReturnTypeConfig,\n 'require-return-type',\n async () => (await import('./validate-return-types')).RequireReturnTypeValidator,\n RequireReturnTypeConfig.SCHEMA,\n ),\n new CodePolicy(\n NoInlineTypeLiteralsConfig,\n 'no-inline-type-literals',\n async () => (await import('./validate-no-inline-types')).NoInlineTypeLiteralsValidator,\n NoInlineTypeLiteralsConfig.SCHEMA,\n ),\n new CodePolicy(\n NoAnyUnknownConfig,\n 'no-any-unknown',\n async () => (await import('./validate-no-any-unknown')).NoAnyUnknownValidator,\n NoAnyUnknownConfig.SCHEMA,\n ),\n new CodePolicy(\n NoImplicitAnyConfig,\n 'no-implicit-any',\n async () => (await import('./validate-no-implicit-any')).NoImplicitAnyValidator,\n NoImplicitAnyConfig.SCHEMA,\n ),\n new CodePolicy(\n PrismaValidateDtosConfig,\n 'prisma-validate-dtos',\n async () => (await import('./validate-dtos')).PrismaValidateDtosValidator,\n PrismaValidateDtosConfig.SCHEMA,\n ),\n new CodePolicy(\n PrismaConverterConfig,\n 'prisma-converter',\n async () => (await import('./validate-prisma-converters')).PrismaConverterValidator,\n PrismaConverterConfig.SCHEMA,\n ),\n new CodePolicy(\n NoDestructureConfig,\n 'no-destructure',\n async () => (await import('./validate-no-destructure')).NoDestructureValidator,\n NoDestructureConfig.SCHEMA,\n ),\n new CodePolicy(\n CatchErrorPatternConfig,\n 'catch-error-pattern',\n async () => (await import('./validate-catch-error-pattern')).CatchErrorPatternValidator,\n CatchErrorPatternConfig.SCHEMA,\n ),\n new CodePolicy(\n NoUnmanagedExceptionsConfig,\n 'no-unmanaged-exceptions',\n async () =>\n (await import('./validate-no-unmanaged-exceptions')).NoUnmanagedExceptionsValidator,\n NoUnmanagedExceptionsConfig.SCHEMA,\n ),\n new CodePolicy(\n AngularNoDirectApiInResolverConfig,\n 'angular-no-direct-api-in-resolver',\n async () =>\n (await import('./validate-no-direct-api-resolver')).NoDirectApiResolverValidator,\n AngularNoDirectApiInResolverConfig.SCHEMA,\n ),\n new CodePolicy(\n NoSymbolDiTokensConfig,\n 'no-symbol-di-tokens',\n async () => (await import('./validate-no-symbol-di-tokens')).NoSymbolDiTokensValidator,\n NoSymbolDiTokensConfig.SCHEMA,\n ),\n new CodePolicy(\n NoClientCreationOutsideServerOrClientConfig,\n 'no-client-creation-outside-server-or-client',\n async () =>\n (await import('./validate-no-client-creation-outside-server-or-client'))\n .NoClientCreationOutsideServerOrClientValidator,\n NoClientCreationOutsideServerOrClientConfig.SCHEMA,\n ),\n new CodePolicy(\n NoCustomCssConfig,\n 'no-custom-css',\n async () => (await import('./validate-no-custom-css')).NoCustomCssValidator,\n NoCustomCssConfig.SCHEMA,\n ),\n new CodePolicy(\n NoStatePathsInTemplatesConfig,\n 'no-state-paths-in-templates',\n async () =>\n (await import('./validate-no-state-paths-in-templates'))\n .NoStatePathsInTemplatesValidator,\n NoStatePathsInTemplatesConfig.SCHEMA,\n ),\n new CodePolicy(\n NoProcessExitOutsideMainConfig,\n 'no-process-exit-outside-main',\n async () =>\n (await import('./validate-no-process-exit-outside-main'))\n .NoProcessExitOutsideMainValidator,\n NoProcessExitOutsideMainConfig.SCHEMA,\n ),\n new CodePolicy(\n NoFunctionOutsideClassConfig,\n 'no-function-outside-class',\n async () =>\n (await import('./validate-no-function-outside-class')).NoFunctionOutsideClassValidator,\n NoFunctionOutsideClassConfig.SCHEMA,\n ),\n new CodePolicy(\n InjectAnnotationNotNeededForConcreteClassConfig,\n 'inject-annotation-not-needed-for-concrete-class',\n async () =>\n (await import('./validate-inject-annotation-not-needed-for-concrete-class'))\n .InjectAnnotationNotNeededForConcreteClassValidator,\n InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA,\n ),\n new CodePolicy(\n FrameworkTagConfig,\n 'framework-tag',\n async () => (await import('./validate-framework-tag')).FrameworkTagValidator,\n FrameworkTagConfig.SCHEMA,\n ),\n new CodePolicy(\n RoleTagConfig,\n 'role-tag',\n async () => (await import('./validate-role-tag')).RoleTagValidator,\n RoleTagConfig.SCHEMA,\n ),\n new CodePolicy(\n EnsureWeAreSecureConfig,\n 'ensure-we-are-secure',\n async () => (await import('./validate-ensure-we-are-secure')).EnsureWeAreSecureValidator,\n EnsureWeAreSecureConfig.SCHEMA,\n ),\n new CodePolicy(\n NoInlineImportInApiLibConfig,\n 'no-inline-import-in-api-lib',\n async () =>\n (await import('./validate-no-inline-import-in-api-lib'))\n .NoInlineImportInApiLibValidator,\n NoInlineImportInApiLibConfig.SCHEMA,\n ),\n new CodePolicy(\n OneEnumSpellingInApiLibConfig,\n 'one-enum-spelling-in-api-lib',\n async () =>\n (await import('./validate-one-enum-spelling-in-api-lib'))\n .OneEnumSpellingInApiLibValidator,\n OneEnumSpellingInApiLibConfig.SCHEMA,\n ),\n new CodePolicy(\n NoUtilityTypesInApiLibConfig,\n 'no-utility-types-in-api-lib',\n async () =>\n (await import('./validate-no-utility-types-in-api-lib'))\n .NoUtilityTypesInApiLibValidator,\n NoUtilityTypesInApiLibConfig.SCHEMA,\n ),\n new CodePolicy(\n RequiredTypeSuffixConfig,\n 'required-type-suffix',\n async () => (await import('./validate-required-type-suffix')).RequiredTypeSuffixValidator,\n RequiredTypeSuffixConfig.SCHEMA,\n ),\n new CodePolicy(\n FrameworkTsconfigConfig,\n 'framework-tsconfig',\n async () => (await import('./validate-framework-tsconfig')).FrameworkTsconfigValidator,\n FrameworkTsconfigConfig.SCHEMA,\n ),\n new CodePolicy(\n FrameworkPackagesConfig,\n 'framework-packages',\n async () => (await import('./validate-framework-packages')).FrameworkPackagesValidator,\n FrameworkPackagesConfig.SCHEMA,\n ),\n];\n"]}
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CodeRulesBootstrap = void 0;
4
+ const rules_sdk_1 = require("@webpieces/rules-sdk");
4
5
  require("reflect-metadata");
5
- const inversify_1 = require("inversify");
6
+ const code_policy_composition_1 = require("./code-policy-composition");
6
7
  const rules_config_1 = require("@webpieces/rules-config");
7
- const rules_sdk_1 = require("@webpieces/rules-sdk");
8
+ const rules_sdk_2 = require("@webpieces/rules-sdk");
8
9
  const tooling_common_1 = require("@webpieces/tooling-common");
9
10
  const code_rules_app_1 = require("./code-rules-app");
10
11
  const code_rules_context_1 = require("./code-rules-context");
11
- const code_rules_config_table_1 = require("./code-rules-config-table");
12
+ const code_policy_registry_1 = require("./code-policy-registry");
12
13
  const code_rules_run_request_1 = require("./code-rules-run-request");
13
14
  const scan_scope_1 = require("./scan-scope");
14
15
  /** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */
@@ -49,18 +50,17 @@ class CodeRulesBootstrap {
49
50
  const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;
50
51
  if (plan !== undefined)
51
52
  this.printBanner(plan);
52
- // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
53
- const container = new inversify_1.Container({ autobind: true });
54
- container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
55
- container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(this.matchRules(loaded, plan)));
56
- container.bind(code_rules_run_request_1.RuleSelection).toConstantValue(new code_rules_run_request_1.RuleSelection(plan?.rule));
57
- container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(plan?.projects));
58
- for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
59
- const ConfigClass = binding.configClass;
60
- const configured = loaded.rulesConfig[binding.ruleId];
61
- const config = configured ?? new ConfigClass();
62
- container.bind(ConfigClass).toConstantValue(plan?.rule === binding.ruleId ? this.overridden(config, plan) : config);
53
+ const configs = {};
54
+ for (const policy of code_policy_registry_1.CODE_POLICIES) {
55
+ const config = loaded.rulesConfig[policy.ruleId];
56
+ configs[policy.ruleId] = (plan?.rule === policy.ruleId ? this.overridden(config, plan) : config);
63
57
  }
58
+ const runtimeRequest = new rules_sdk_1.PolicyRuntimeRequest(workspaceRoot, configs, code_policy_registry_1.CODE_POLICIES.map((policy) => policy.ruleId));
59
+ const container = await new code_policy_composition_1.CodeRuleRuntime().compose(runtimeRequest, plan?.projects);
60
+ container
61
+ .bind(code_rules_context_1.MatchRulesHolder)
62
+ .toConstantValue(new code_rules_context_1.MatchRulesHolder(this.matchRules(loaded, plan)));
63
+ container.bind(code_rules_run_request_1.RuleSelection).toConstantValue(new code_rules_run_request_1.RuleSelection(plan?.rule));
64
64
  const result = await container.get(code_rules_app_1.CodeRulesApp).run();
65
65
  if (plan === undefined)
66
66
  return result;
@@ -82,7 +82,9 @@ class CodeRulesBootstrap {
82
82
  const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';
83
83
  const mode = request.mode ?? committedMode;
84
84
  if (!modes.includes(mode) || mode === 'OFF') {
85
- const why = request.mode === undefined ? `its committed mode is ${committedMode}` : `--mode=${mode} is not one of its modes`;
85
+ const why = request.mode === undefined
86
+ ? `its committed mode is ${committedMode}`
87
+ : `--mode=${mode} is not one of its modes`;
86
88
  throw this.refusal(`${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m) => m !== 'OFF').join(', ')}>.`);
87
89
  }
88
90
  const unknown = (request.projects ?? []).filter((name) => !this.projectNames(workspaceRoot).includes(name));
@@ -98,14 +100,17 @@ class CodeRulesBootstrap {
98
100
  /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
99
101
  wholeScopeModesOf(rule, loaded) {
100
102
  if (loaded.matchRules.some((mr) => mr.name === rule))
101
- return rules_sdk_1.MODIFIED_CODE_MODES;
102
- if (!code_rules_config_table_1.CONFIG_BINDINGS.some((binding) => binding.ruleId === rule))
103
+ return rules_sdk_2.MODIFIED_CODE_MODES;
104
+ if (!code_policy_registry_1.CODE_POLICIES.some((binding) => binding.ruleId === rule))
103
105
  return undefined;
104
- const modes = code_rules_config_table_1.CONFIG_BINDINGS.find(binding => binding.ruleId === rule)?.schema['mode']?.enumValues ?? [];
105
- return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME') ? modes : undefined;
106
+ const modes = code_policy_registry_1.CODE_POLICIES.find((binding) => binding.ruleId === rule)?.schema['mode']
107
+ ?.enumValues ?? [];
108
+ return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME')
109
+ ? modes
110
+ : undefined;
106
111
  }
107
112
  debuggableRules(loaded) {
108
- const builtIns = code_rules_config_table_1.CONFIG_BINDINGS.map((binding) => binding.ruleId);
113
+ const builtIns = code_policy_registry_1.CODE_POLICIES.map((binding) => binding.ruleId);
109
114
  const names = [...builtIns, ...loaded.matchRules.map((mr) => mr.name)];
110
115
  return names.filter((name) => this.wholeScopeModesOf(name, loaded) !== undefined);
111
116
  }
@@ -117,11 +122,14 @@ class CodeRulesBootstrap {
117
122
  return configured?.mode;
118
123
  }
119
124
  projectNames(workspaceRoot) {
120
- return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope()).all(workspaceRoot).map((p) => p.name).sort();
125
+ return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope())
126
+ .all(workspaceRoot)
127
+ .map((p) => p.name)
128
+ .sort();
121
129
  }
122
130
  /** The match-rules, with the debugged one (if it is a match rule) overridden. */
123
131
  matchRules(loaded, plan) {
124
- return loaded.matchRules.map((mr) => (plan?.rule === mr.name ? this.overridden(mr, plan) : mr));
132
+ return loaded.matchRules.map((mr) => plan?.rule === mr.name ? this.overridden(mr, plan) : mr);
125
133
  }
126
134
  /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
127
135
  overridden(config, plan) {
@@ -1 +1 @@
1
- {"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,yCAAsC;AACtC,0DAAoG;AACpG,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAuE;AACvE,uEAA2E;AAC3E,qEAA8E;AAC9E,6CAAwF;AAExF,0GAA0G;AAC1G,MAAM,SAAS;IAEE;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;Q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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;AAxHD,gDAwHC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\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 { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS, ConfigBinding } from './code-rules-config-table';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ProjectCatalog, ProjectEntry, ScanRestriction, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nclass DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 โ€” any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written โ€” webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError('No webpieces.config.json found at workspace root (or any ancestor).');\n }\n console.log(`\\n๐Ÿ“„ Loaded config: ${loaded.configPath}`);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.printBanner(plan);\n\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n container.bind(ScanRestriction).toConstantValue(new ScanRestriction(plan?.projects));\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding.configClass;\n const configured = loaded.rulesConfig[binding.ruleId] as BaseRuleConfig | undefined;\n const config = configured ?? new ConfigClass();\n container.bind(ConfigClass).toConstantValue(plan?.rule === binding.ruleId ? this.overridden(config, plan) : config);\n }\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists โ€” including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") โ€” so it can gate a loop.\n const sites = this.printCounts(workspaceRoot, plan, container.get(ScanScope), result);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): DebugPlan {\n const rule = request.rule;\n if (rule === undefined) throw this.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.refusal(`--rule=${rule} is not a code rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`);\n }\n const committedMode = this.committedModeOf(rule, loaded) ?? 'OFF';\n const mode = request.mode ?? committedMode;\n if (!modes.includes(mode) || mode === 'OFF') {\n const why = request.mode === undefined ? `its committed mode is ${committedMode}` : `--mode=${mode} is not one of its modes`;\n throw this.refusal(`${rule} cannot run: ${why}. Pass --mode=<one of ${modes.filter((m: string) => m !== 'OFF').join(', ')}>.`);\n }\n const unknown = (request.projects ?? []).filter((name: string) => !this.projectNames(workspaceRoot).includes(name));\n if (unknown.length > 0) {\n throw this.refusal(`--projects names no such nx project: ${unknown.join(', ')}. Known projects: ` +\n `${this.projectNames(workspaceRoot).join(', ')}.`);\n }\n return new DebugPlan(rule, mode, committedMode, request.projects);\n }\n\n private refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule)) return MODIFIED_CODE_MODES;\n if (!CONFIG_BINDINGS.some((binding: ConfigBinding) => binding.ruleId === rule)) return undefined;\n const modes = CONFIG_BINDINGS.find(binding => binding.ruleId === rule)?.schema['mode']?.enumValues ?? [];\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME') ? modes : undefined;\n }\n\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CONFIG_BINDINGS.map((binding: ConfigBinding) => binding.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 BaseRuleConfig | undefined;\n return configured?.mode;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope()).all(workspaceRoot).map((p: ProjectEntry) => p.name).sort();\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) => (plan?.rule === mr.name ? this.overridden(mr, plan) : mr));\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n private overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(Object.create(Object.getPrototypeOf(config) as object) as C, config);\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n private printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(`๐Ÿ” DEBUG RUN of ${plan.rule} โ€” NOT the gate. webpieces.config.json is unchanged and nothing is written.`);\n console.log(` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` ยท Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' ยท escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run');\n }\n\n /** Print one count per project and return the total. */\n private printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, result: ExecutorResult): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`๐Ÿ” ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!result.success && total === 0) {\n console.log(' (the rule failed without reporting sites โ€” read its output above)');\n }\n console.log('');\n return total;\n }\n}\n"]}
1
+ {"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAA0F;AAC1F,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAAoG;AACpG,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAM,SAAS;IAEE;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,kBAAkB;IAC3B,KAAK,CAAC,GAAG,CAAC,aAAqB,EAAE,OAA4B;QACzD,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,8BAAa,CACnB,qEAAqE,CACxE,CAAC;QACN,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvF,IAAI,IAAI,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAE/C,MAAM,OAAO,GAAiC,EAAE,CAAC;QACjD,KAAK,MAAM,MAAM,IAAI,oCAAa,EAAE,CAAC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AAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC;QACtE,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;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,79 +1,22 @@
1
+ import { BuildPolicy } from '@webpieces/rules-sdk';
1
2
  import { ExecutorResult } from './code-validator';
2
3
  import { RuleReporter } from './rule-reporter';
3
4
  import { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';
4
5
  import { RuleSelection } from './code-rules-run-request';
5
6
  import { MatchRulesChecker } from './validate-match-rules';
6
- import { MaxMethodLinesValidator } from './validate-modified-methods';
7
- import { MaxFileLinesValidator } from './validate-modified-files';
8
- import { RequireReturnTypeValidator } from './validate-return-types';
9
- import { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';
10
- import { NoAnyUnknownValidator } from './validate-no-any-unknown';
11
- import { NoImplicitAnyValidator } from './validate-no-implicit-any';
12
- import { PrismaValidateDtosValidator } from './validate-dtos';
13
- import { PrismaConverterValidator } from './validate-prisma-converters';
14
- import { NoDestructureValidator } from './validate-no-destructure';
15
- import { CatchErrorPatternValidator } from './validate-catch-error-pattern';
16
- import { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';
17
- import { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';
18
- import { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';
19
- import { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';
20
- import { NoCustomCssValidator } from './validate-no-custom-css';
21
- import { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';
22
- import { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';
23
- import { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';
24
- import { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';
25
- import { FrameworkTagValidator } from './validate-framework-tag';
26
- import { RoleTagValidator } from './validate-role-tag';
27
- import { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';
28
- import { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';
29
- import { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';
30
- import { NoUtilityTypesInApiLibValidator } from './validate-no-utility-types-in-api-lib';
31
- import { RequiredTypeSuffixValidator } from './validate-required-type-suffix';
32
- import { FrameworkTsconfigValidator } from './validate-framework-tsconfig';
33
- import { FrameworkPackagesValidator } from './validate-framework-packages';
34
- /**
35
- * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config
36
- * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph
37
- * draws. The per-entry match-rules validators are the one exception โ€” they are config-per-instance,
38
- * so they are built from the injected {@link MatchRulesHolder}.
39
- */
7
+ /** Runtime checks are composed from the owner's policy entries, rather than injected individually. */
8
+ export declare class BuildPolicySet {
9
+ readonly policies: readonly BuildPolicy[];
10
+ constructor(policies: readonly BuildPolicy[]);
11
+ }
40
12
  export declare class CodeRulesEngine {
41
13
  private readonly workspace;
42
14
  private readonly reporter;
43
15
  private readonly matchRules;
44
16
  private readonly matchChecker;
45
17
  private readonly selection;
46
- private readonly maxMethodLines;
47
- private readonly maxFileLines;
48
- private readonly requireReturnType;
49
- private readonly noInlineTypeLiterals;
50
- private readonly noAnyUnknown;
51
- private readonly noImplicitAny;
52
- private readonly prismaValidateDtos;
53
- private readonly prismaConverter;
54
- private readonly noDestructure;
55
- private readonly catchErrorPattern;
56
- private readonly noUnmanagedExceptions;
57
- private readonly noDirectApiResolver;
58
- private readonly noSymbolDiTokens;
59
- private readonly noClientCreationOutsideServerOrClient;
60
- private readonly noCustomCss;
61
- private readonly noStatePathsInTemplates;
62
- private readonly noProcessExitOutsideMain;
63
- private readonly noFunctionOutsideClass;
64
- private readonly injectAnnotationNotNeeded;
65
- private readonly frameworkTag;
66
- private readonly roleTag;
67
- private readonly ensureWeAreSecure;
68
- private readonly noInlineImportInApiLib;
69
- private readonly oneEnumSpellingInApiLib;
70
- private readonly noUtilityTypesInApiLib;
71
- private readonly requiredTypeSuffix;
72
- private readonly frameworkTsconfig;
73
- private readonly frameworkPackages;
74
- constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, selection: RuleSelection, maxMethodLines: MaxMethodLinesValidator, maxFileLines: MaxFileLinesValidator, requireReturnType: RequireReturnTypeValidator, noInlineTypeLiterals: NoInlineTypeLiteralsValidator, noAnyUnknown: NoAnyUnknownValidator, noImplicitAny: NoImplicitAnyValidator, prismaValidateDtos: PrismaValidateDtosValidator, prismaConverter: PrismaConverterValidator, noDestructure: NoDestructureValidator, catchErrorPattern: CatchErrorPatternValidator, noUnmanagedExceptions: NoUnmanagedExceptionsValidator, noDirectApiResolver: NoDirectApiResolverValidator, noSymbolDiTokens: NoSymbolDiTokensValidator, noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator, noCustomCss: NoCustomCssValidator, noStatePathsInTemplates: NoStatePathsInTemplatesValidator, noProcessExitOutsideMain: NoProcessExitOutsideMainValidator, noFunctionOutsideClass: NoFunctionOutsideClassValidator, injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator, frameworkTag: FrameworkTagValidator, roleTag: RoleTagValidator, ensureWeAreSecure: EnsureWeAreSecureValidator, noInlineImportInApiLib: NoInlineImportInApiLibValidator, oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator, noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator, requiredTypeSuffix: RequiredTypeSuffixValidator, frameworkTsconfig: FrameworkTsconfigValidator, frameworkPackages: FrameworkPackagesValidator);
75
- /** The injected built-in validators, in run order. */
76
- private builtIns;
18
+ private readonly checks;
19
+ constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, selection: RuleSelection, checks: BuildPolicySet);
77
20
  /**
78
21
  * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected
79
22
  * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects