@webpieces/code-rules 0.4.814 → 0.4.816

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.814",
3
+ "version": "0.4.816",
4
4
  "description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,7 +16,7 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.814",
19
+ "@webpieces/rules-config": "0.4.816",
20
20
  "@inversifyjs/binding-decorators": "1.1.5",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2"
package/src/cli.js CHANGED
@@ -2,11 +2,10 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  require("reflect-metadata");
5
- const inversify_1 = require("inversify");
6
5
  const rules_config_1 = require("@webpieces/rules-config");
7
6
  const code_rules_app_1 = require("./code-rules-app");
8
- const code_rules_context_1 = require("./code-rules-context");
9
- const code_rules_config_table_1 = require("./code-rules-config-table");
7
+ const code_rules_bootstrap_1 = require("./code-rules-bootstrap");
8
+ const code_rules_run_request_1 = require("./code-rules-run-request");
10
9
  async function main() {
11
10
  // webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI
12
11
  try {
@@ -19,17 +18,10 @@ async function main() {
19
18
  process.exit(1);
20
19
  }
21
20
  console.log(`\nšŸ“„ Loaded config: ${loaded.configPath}`);
22
- // Composition root: bind the runtime values (workspace root, each rule's config), then let
23
- // inversify build the ENTIRE validator DAG when we resolve the app.
24
- // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
25
- const container = new inversify_1.Container({ autobind: true });
26
- container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
27
- container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(loaded.matchRules));
28
- for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
29
- const ConfigClass = binding[0];
30
- const configured = loaded.rulesConfig[binding[1]];
31
- container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());
32
- }
21
+ // Composition root: the shared bootstrap binds the runtime values (workspace root, the run
22
+ // request, each rule's planned config) and inversify builds the ENTIRE validator DAG.
23
+ const request = new code_rules_run_request_1.CodeRulesRunRequestParser().fromArgv(process.argv.slice(2));
24
+ const container = new code_rules_bootstrap_1.CodeRulesBootstrap().container(workspaceRoot, loaded, request);
33
25
  const app = container.get(code_rules_app_1.CodeRulesApp);
34
26
  const result = await app.run();
35
27
  process.exit(result.success ? 0 : 1);
package/src/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,yCAAsC;AACtC,0DAAyJ;AAEzJ,qDAAgD;AAChD,6DAAuE;AACvE,uEAA4D;AAE5D,KAAK,UAAU,IAAI;IACf,qFAAqF;IACrF,IAAI,CAAC;QACD,8FAA8F;QAC9F,6CAA6C;QAC7C,MAAM,aAAa,GAAG,IAAI,6BAAc,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;YAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,2FAA2F;QAC3F,o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AC;YACJ,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { InformAiError, RuleFailError, renderRuleFailForHuman, toError, loadAndValidate, RepoRootFinder, BaseRuleConfig } from '@webpieces/rules-config';\n\nimport { CodeRulesApp } from './code-rules-app';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\n\nasync function main(): Promise<void> {\n // webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI\n try {\n // Anchor at the repo root so `.webpieces/instruct-ai` docs land there, not in whatever subdir\n // this CLI ran from; load config from there.\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(process.cwd());\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.error('\\nāŒ No webpieces.config.json found at workspace root (or any ancestor).\\n');\n process.exit(1);\n }\n console.log(`\\nšŸ“„ Loaded config: ${loaded.configPath}`);\n\n // Composition root: bind the runtime values (workspace root, each rule's config), then let\n // inversify build the ENTIRE validator DAG when we resolve the app.\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[0];\n const configured = loaded.rulesConfig[binding[1]] 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 process.exit(result.success ? 0 : 1);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n console.error(renderRuleFailForHuman(error));\n } else if (err instanceof InformAiError) {\n console.error(error.message);\n } else {\n console.error(`[code-rules] unexpected error: ${error.message}`);\n }\n process.exit(1);\n }\n}\n\nmain();\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/cli.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAyI;AAEzI,qDAAgD;AAChD,iEAA4D;AAC5D,qEAAqE;AAErE,KAAK,UAAU,IAAI;IACf,qFAAqF;IACrF,IAAI,CAAC;QACD,8FAA8F;QAC9F,6CAA6C;QAC7C,MAAM,aAAa,GAAG,IAAI,6BAAc,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;YAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,2FAA2F;QAC3F,sFAAsF;QACtF,MAAM,OAAO,GAAG,IAAI,kDAAyB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAChF,MAAM,SAAS,GAAG,IAAI,yCAAkB,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACrF,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,6BAAY,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,sBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,YAAY,4BAAa,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,GAAG,YAAY,4BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { InformAiError, RuleFailError, renderRuleFailForHuman, toError, loadAndValidate, RepoRootFinder } from '@webpieces/rules-config';\n\nimport { CodeRulesApp } from './code-rules-app';\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { CodeRulesRunRequestParser } from './code-rules-run-request';\n\nasync function main(): Promise<void> {\n // webpieces-disable no-unmanaged-exceptions -- global entry point for code-rules CLI\n try {\n // Anchor at the repo root so `.webpieces/instruct-ai` docs land there, not in whatever subdir\n // this CLI ran from; load config from there.\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(process.cwd());\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.error('\\nāŒ No webpieces.config.json found at workspace root (or any ancestor).\\n');\n process.exit(1);\n }\n console.log(`\\nšŸ“„ Loaded config: ${loaded.configPath}`);\n\n // Composition root: the shared bootstrap binds the runtime values (workspace root, the run\n // request, each rule's planned config) and inversify builds the ENTIRE validator DAG.\n const request = new CodeRulesRunRequestParser().fromArgv(process.argv.slice(2));\n const container = new CodeRulesBootstrap().container(workspaceRoot, loaded, request);\n const app = container.get(CodeRulesApp);\n const result = await app.run();\n process.exit(result.success ? 0 : 1);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n console.error(renderRuleFailForHuman(error));\n } else if (err instanceof InformAiError) {\n console.error(error.message);\n } else {\n console.error(`[code-rules] unexpected error: ${error.message}`);\n }\n process.exit(1);\n }\n}\n\nmain();\n"]}
@@ -0,0 +1,13 @@
1
+ import { Container } from 'inversify';
2
+ import { LoadedConfig } from '@webpieces/rules-config';
3
+ import { CodeRulesRunRequest } from './code-rules-run-request';
4
+ /**
5
+ * The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx
6
+ * `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace
7
+ * root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's
8
+ * `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then
9
+ * resolves `CodeRulesApp`, and inversify builds the entire validator DAG.
10
+ */
11
+ export declare class CodeRulesBootstrap {
12
+ container(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): Container;
13
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeRulesBootstrap = void 0;
4
+ const inversify_1 = require("inversify");
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const code_rules_run_request_1 = require("./code-rules-run-request");
7
+ const code_rules_context_1 = require("./code-rules-context");
8
+ const code_rules_config_table_1 = require("./code-rules-config-table");
9
+ const rule_scope_plan_1 = require("./rule-scope-plan");
10
+ /**
11
+ * The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx
12
+ * `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace
13
+ * root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's
14
+ * `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then
15
+ * resolves `CodeRulesApp`, and inversify builds the entire validator DAG.
16
+ */
17
+ class CodeRulesBootstrap {
18
+ container(workspaceRoot, loaded, request) {
19
+ const roots = request.projects === null ? null : new rules_config_1.ProjectIndex(workspaceRoot).rootsFor(request.projects);
20
+ const planner = new rule_scope_plan_1.RuleScopePlanner(request, roots);
21
+ // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
22
+ const container = new inversify_1.Container({ autobind: true });
23
+ container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(workspaceRoot));
24
+ container.bind(code_rules_run_request_1.CodeRulesRunRequest).toConstantValue(request);
25
+ for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
26
+ const ConfigClass = binding[0];
27
+ const configured = loaded.rulesConfig[binding[1]] ?? new ConfigClass();
28
+ const planned = planner.plan(binding[1], configured, (0, rules_config_1.schemaModeValues)(binding[1]) ?? []);
29
+ container.bind(ConfigClass).toConstantValue(planned);
30
+ }
31
+ const matchRules = loaded.matchRules.map((mr) => planner.plan(mr.name, mr, rules_config_1.MODIFIED_CODE_MODES));
32
+ container.bind(code_rules_context_1.MatchRulesHolder).toConstantValue(new code_rules_context_1.MatchRulesHolder(matchRules));
33
+ container.bind(rule_scope_plan_1.RuleScopes).toConstantValue(planner.result());
34
+ return container;
35
+ }
36
+ }
37
+ exports.CodeRulesBootstrap = CodeRulesBootstrap;
38
+ //# sourceMappingURL=code-rules-bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,0DAOiC;AAEjC,qEAA+D;AAC/D,6DAAuE;AACvE,uEAA4D;AAC5D,uDAAiE;AAEjE;;;;;;GAMG;AACH,MAAa,kBA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AC,CAAC,CAAC;QAClH,SAAS,CAAC,IAAI,CAAC,qCAAgB,CAAC,CAAC,eAAe,CAAC,IAAI,qCAAgB,CAAC,UAAU,CAAC,CAAC,CAAC;QACnF,SAAS,CAAC,IAAI,CAAC,4BAAU,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AApBD,gDAoBC","sourcesContent":["import { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n LoadedConfig,\n MatchRuleConfig,\n MODIFIED_CODE_MODES,\n ProjectIndex,\n schemaModeValues,\n} from '@webpieces/rules-config';\n\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\nimport { RuleScopePlanner, RuleScopes } from './rule-scope-plan';\n\n/**\n * The ONE code-rules composition root, shared by the `wp-validate-code` bin (cli.ts) and the nx\n * `validate-code` executor (validate-code.ts) so the two entry points cannot drift: bind the workspace\n * root, the run request, each rule's config AS PLANNED (whole-scope modes applied, a debug run's\n * `--mode` applied — see {@link RuleScopePlanner}) and the resulting {@link RuleScopes}. The caller then\n * resolves `CodeRulesApp`, and inversify builds the entire validator DAG.\n */\nexport class CodeRulesBootstrap {\n container(workspaceRoot: string, loaded: LoadedConfig, request: CodeRulesRunRequest): Container {\n const roots = request.projects === null ? null : new ProjectIndex(workspaceRoot).rootsFor(request.projects);\n const planner = new RuleScopePlanner(request, roots);\n\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(CodeRulesRunRequest).toConstantValue(request);\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding[0];\n const configured = (loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined) ?? new ConfigClass();\n const planned = planner.plan(binding[1], configured, schemaModeValues(binding[1]) ?? []);\n container.bind(ConfigClass).toConstantValue(planned);\n }\n const matchRules = loaded.matchRules.map((mr: MatchRuleConfig) => planner.plan(mr.name, mr, MODIFIED_CODE_MODES));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(matchRules));\n container.bind(RuleScopes).toConstantValue(planner.result());\n return container;\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
+ import { DiffScope } from '@webpieces/rules-config';
1
2
  import { ExecutorResult } from './code-validator';
2
3
  import { RuleReporter } from './rule-reporter';
3
4
  import { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';
5
+ import { CodeRulesRunRequest } from './code-rules-run-request';
6
+ import { DebugRunReport } from './debug-run-report';
7
+ import { RuleScopes } from './rule-scope-plan';
4
8
  import { MatchRulesChecker } from './validate-match-rules';
5
9
  import { MaxMethodLinesValidator } from './validate-modified-methods';
6
10
  import { MaxFileLinesValidator } from './validate-modified-files';
@@ -38,6 +42,10 @@ export declare class CodeRulesEngine {
38
42
  private readonly reporter;
39
43
  private readonly matchRules;
40
44
  private readonly matchChecker;
45
+ private readonly request;
46
+ private readonly scopes;
47
+ private readonly debugReport;
48
+ private readonly diffScope;
41
49
  private readonly maxMethodLines;
42
50
  private readonly maxFileLines;
43
51
  private readonly requireReturnType;
@@ -63,7 +71,7 @@ export declare class CodeRulesEngine {
63
71
  private readonly noInlineImportInApiLib;
64
72
  private readonly oneEnumSpellingInApiLib;
65
73
  private readonly noUtilityTypesInApiLib;
66
- constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, 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);
74
+ constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, request: CodeRulesRunRequest, scopes: RuleScopes, debugReport: DebugRunReport, diffScope: DiffScope, maxMethodLines: MaxMethodLinesValidator, maxFileLines: MaxFileLinesValidator, requireReturnType: RequireReturnTypeValidator, noInlineTypeLiterals: NoInlineTypeLiteralsValidator, noAnyUnknown: NoAnyUnknownValidator, noImplicitAny: NoImplicitAnyValidator, prismaValidateDtos: PrismaValidateDtosValidator, prismaConverter: PrismaConverterValidator, noDestructure: NoDestructureValidator, catchErrorPattern: CatchErrorPatternValidator, noUnmanagedExceptions: NoUnmanagedExceptionsValidator, noDirectApiResolver: NoDirectApiResolverValidator, noSymbolDiTokens: NoSymbolDiTokensValidator, noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator, noCustomCss: NoCustomCssValidator, noStatePathsInTemplates: NoStatePathsInTemplatesValidator, noProcessExitOutsideMain: NoProcessExitOutsideMainValidator, noFunctionOutsideClass: NoFunctionOutsideClassValidator, injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator, frameworkTag: FrameworkTagValidator, roleTag: RoleTagValidator, ensureWeAreSecure: EnsureWeAreSecureValidator, noInlineImportInApiLib: NoInlineImportInApiLibValidator, oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator, noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator);
67
75
  /** The injected built-in validators, in run order. */
68
76
  private builtIns;
69
77
  /**
@@ -72,6 +80,10 @@ export declare class CodeRulesEngine {
72
80
  * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.
73
81
  */
74
82
  private activeRuns;
83
+ /** The gate runs every rule; a debug run only the one it names. */
84
+ private selected;
85
+ /** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */
86
+ private scoped;
75
87
  /**
76
88
  * Run all configured code validators against the workspace. A validator runs only when
77
89
  * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CodeRulesEngine = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const rules_config_1 = require("@webpieces/rules-config");
5
6
  const inversify_1 = require("inversify");
6
7
  const code_validator_1 = require("./code-validator");
7
8
  const rule_reporter_1 = require("./rule-reporter");
8
9
  const code_rules_context_1 = require("./code-rules-context");
10
+ const code_rules_run_request_1 = require("./code-rules-run-request");
11
+ const debug_run_report_1 = require("./debug-run-report");
12
+ const rule_scope_plan_1 = require("./rule-scope-plan");
9
13
  const validate_match_rules_1 = require("./validate-match-rules");
10
14
  const validate_modified_methods_1 = require("./validate-modified-methods");
11
15
  const validate_modified_files_1 = require("./validate-modified-files");
@@ -43,6 +47,10 @@ let CodeRulesEngine = class CodeRulesEngine {
43
47
  reporter;
44
48
  matchRules;
45
49
  matchChecker;
50
+ request;
51
+ scopes;
52
+ debugReport;
53
+ diffScope;
46
54
  maxMethodLines;
47
55
  maxFileLines;
48
56
  requireReturnType;
@@ -69,11 +77,15 @@ let CodeRulesEngine = class CodeRulesEngine {
69
77
  oneEnumSpellingInApiLib;
70
78
  noUtilityTypesInApiLib;
71
79
  // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field
72
- constructor(workspace, reporter, matchRules, matchChecker, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure, noInlineImportInApiLib, oneEnumSpellingInApiLib, noUtilityTypesInApiLib) {
80
+ constructor(workspace, reporter, matchRules, matchChecker, request, scopes, debugReport, diffScope, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure, noInlineImportInApiLib, oneEnumSpellingInApiLib, noUtilityTypesInApiLib) {
73
81
  this.workspace = workspace;
74
82
  this.reporter = reporter;
75
83
  this.matchRules = matchRules;
76
84
  this.matchChecker = matchChecker;
85
+ this.request = request;
86
+ this.scopes = scopes;
87
+ this.debugReport = debugReport;
88
+ this.diffScope = diffScope;
77
89
  this.maxMethodLines = maxMethodLines;
78
90
  this.maxFileLines = maxFileLines;
79
91
  this.requireReturnType = requireReturnType;
@@ -138,15 +150,23 @@ let CodeRulesEngine = class CodeRulesEngine {
138
150
  activeRuns(root) {
139
151
  const runs = [];
140
152
  for (const v of this.builtIns()) {
141
- if (v.shouldRun())
142
- runs.push(new code_validator_1.RuleRun(v.name, () => v.run(root)));
153
+ if (this.selected(v.configKey) && v.shouldRun())
154
+ runs.push(new code_validator_1.RuleRun(v.name, () => this.scoped(this.scopes.of(v.configKey), () => v.run(root))));
143
155
  }
144
156
  for (const mr of this.matchRules.rules) {
145
- if (this.matchChecker.shouldRun(mr))
146
- runs.push(new code_validator_1.RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));
157
+ if (this.selected(mr.name) && this.matchChecker.shouldRun(mr))
158
+ runs.push(new code_validator_1.RuleRun(mr.name, () => this.scoped(this.scopes.of(mr.name), () => this.matchChecker.runForConfig(mr, root))));
147
159
  }
148
160
  return runs;
149
161
  }
162
+ /** The gate runs every rule; a debug run only the one it names. */
163
+ selected(key) {
164
+ return this.request.rule === null || this.request.rule === key;
165
+ }
166
+ /** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */
167
+ scoped(scope, work) {
168
+ return this.diffScope.within(scope, work);
169
+ }
150
170
  /**
151
171
  * Run all configured code validators against the workspace. A validator runs only when
152
172
  * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives
@@ -154,6 +174,9 @@ let CodeRulesEngine = class CodeRulesEngine {
154
174
  */
155
175
  async run() {
156
176
  const runs = this.activeRuns(this.workspace.path);
177
+ const target = this.scopes.debugTarget;
178
+ if (target !== null)
179
+ return this.debugReport.run(this.workspace.path, runs, target);
157
180
  if (runs.length === 0) {
158
181
  console.log('\nā­ļø Skipping all code validations (all modes: OFF)\n');
159
182
  return { success: true };
@@ -175,6 +198,10 @@ exports.CodeRulesEngine = CodeRulesEngine = tslib_1.__decorate([
175
198
  rule_reporter_1.RuleReporter,
176
199
  code_rules_context_1.MatchRulesHolder,
177
200
  validate_match_rules_1.MatchRulesChecker,
201
+ code_rules_run_request_1.CodeRulesRunRequest,
202
+ rule_scope_plan_1.RuleScopes,
203
+ debug_run_report_1.DebugRunReport,
204
+ rules_config_1.DiffScope,
178
205
  validate_modified_methods_1.MaxMethodLinesValidator,
179
206
  validate_modified_files_1.MaxFileLinesValidator,
180
207
  validate_return_types_1.RequireReturnTypeValidator,
@@ -1 +1 @@
1
- {"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AACA,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,uEAAkE;AAClE,yEAAoE;AACpE,mDAA8D;AAC9D,6EAAwE;AACxE,uEAAmE;AACnE,iFAA4E;AAC5E,yFAAoF;AACpF,uFAAiF;AACjF,iFAA2E;AAC3E,iIAAwH;AACxH,qEAAgE;AAChE,iGAA0F;AAC1F,mGAA4F;AAC5F,6FAAuF;AACvF,yIAAgI;AAChI,qEAAiE;AACjE,2DAAuD;AACvD,mFAA6E;AAC7E,iGAAyF;AACzF,mGAA2F;AAC3F,iGAAyF;AAEzF;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAGH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IA9BrB,4GAA4G;IAC5G,YACqB,SAAwB,EACxB,QAAsB,EACtB,UAA4B,EAC5B,YAA+B,EAC/B,cAAuC,EACvC,YAAmC,EACnC,iBAA6C,EAC7C,oBAAmD,EACnD,YAAmC,EACnC,aAAqC,EACrC,kBAA+C,EAC/C,eAAyC,EACzC,aAAqC,EACrC,iBAA6C,EAC7C,qBAAqD,EACrD,mBAAiD,EACjD,gBAA2C,EAC3C,qCAAqF,EACrF,WAAiC,EACjC,uBAAyD,EACzD,wBAA2D,EAC3D,sBAAuD,EACvD,yBAA6E,EAC7E,YAAmC,EACnC,OAAyB,EACzB,iBAA6C,EAC7C,sBAAuD,EACvD,uBAAyD,EACzD,sBAAuD;QA5BvD,cAAS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sEAA+B;QAC9B,wEAAgC;QACjC,sEAA+B;GA/BnE,eAAe,CA0G3B","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\nimport { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';\nimport { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';\nimport { NoUtilityTypesInApiLibValidator } from './validate-no-utility-types-in-api-lib';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n private readonly noInlineImportInApiLib: NoInlineImportInApiLibValidator,\n private readonly oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator,\n private readonly noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n this.noInlineImportInApiLib,\n this.oneEnumSpellingInApiLib,\n this.noUtilityTypesInApiLib,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (v.shouldRun()) runs.push(new RuleRun(v.name, () => v.run(root)));\n }\n for (const mr of this.matchRules.rules) {\n if (this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));\n }\n return runs;\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n if (runs.length === 0) {\n console.log('\\nā­ļø Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\nšŸ“ Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\nāœ… All code validations passed\\n'\n : '\\nāŒ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AAAA,0DAA+E;AAC/E,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,qEAA+D;AAC/D,yDAAoD;AACpD,uDAA+C;AAC/C,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,uEAAkE;AAClE,yEAAoE;AACpE,mDAA8D;AAC9D,6EAAwE;AACxE,uEAAmE;AACnE,iFAA4E;AAC5E,yFAAoF;AACpF,uFAAiF;AACjF,iFAA2E;AAC3E,iIAAwH;AACxH,qEAAgE;AAChE,iGAA0F;AAC1F,mGAA4F;AAC5F,6FAAuF;AACvF,yIAAgI;AAChI,qEAAiE;AACjE,2DAAuD;AACvD,mFAA6E;AAC7E,iGAAyF;AACzF,mGAA2F;AAC3F,iGAAyF;AAEzF;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAGH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAlCrB,4GAA4G;IAC5G,YACqB,SAAwB,EACxB,QAAsB,EACtB,UAA4B,EAC5B,YAA+B,EAC/B,OAA4B,EAC5B,MAAkB,EAClB,WAA2B,EAC3B,SAAoB,EACpB,cAAuC,EACvC,YAAmC,EACnC,iBAA6C,EAC7C,oBAAmD,EACnD,Y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uEAAgC;QAC/B,yEAAiC;QACnC,oEAA+B;QAC5B,6GAAkD;QAC/D,8CAAqB;QAC1B,oCAAgB;QACN,0DAA0B;QACrB,sEAA+B;QAC9B,wEAAgC;QACjC,sEAA+B;GAnCnE,eAAe,CA2H3B","sourcesContent":["import { BaseRuleConfig, DiffScope, FileScope } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { DebugRunReport } from './debug-run-report';\nimport { RuleScopes } from './rule-scope-plan';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\nimport { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';\nimport { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';\nimport { NoUtilityTypesInApiLibValidator } from './validate-no-utility-types-in-api-lib';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly request: CodeRulesRunRequest,\n private readonly scopes: RuleScopes,\n private readonly debugReport: DebugRunReport,\n private readonly diffScope: DiffScope,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n private readonly noInlineImportInApiLib: NoInlineImportInApiLibValidator,\n private readonly oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator,\n private readonly noUtilityTypesInApiLib: NoUtilityTypesInApiLibValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n this.noInlineImportInApiLib,\n this.oneEnumSpellingInApiLib,\n this.noUtilityTypesInApiLib,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (this.selected(v.configKey) && v.shouldRun())\n runs.push(new RuleRun(v.name, () => this.scoped(this.scopes.of(v.configKey), () => v.run(root))));\n }\n for (const mr of this.matchRules.rules) {\n if (this.selected(mr.name) && this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.scoped(this.scopes.of(mr.name), () => this.matchChecker.runForConfig(mr, root))));\n }\n return runs;\n }\n\n /** The gate runs every rule; a debug run only the one it names. */\n private selected(key: string): boolean {\n return this.request.rule === null || this.request.rule === key;\n }\n\n /** Run one rule inside its planned {@link FileScope} (whole-scope modes, `--projects`). */\n private scoped(scope: FileScope, work: () => Promise<ExecutorResult>): Promise<ExecutorResult> {\n return this.diffScope.within(scope, work);\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n const target = this.scopes.debugTarget;\n if (target !== null) return this.debugReport.run(this.workspace.path, runs, target);\n if (runs.length === 0) {\n console.log('\\nā­ļø Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\nšŸ“ Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\nāœ… All code validations passed\\n'\n : '\\nāŒ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * What one code-rules run was asked to do (#1027). Data-only, bound at the composition root.
3
+ *
4
+ * {@link GATE} is the build: every configured rule, at its COMMITTED mode, over the diff. Anything with a
5
+ * `rule` is a DEBUG run — that one rule, optionally at another mode (`mode`, no config edit), optionally
6
+ * restricted to named projects (`projects`). A debug run changes nothing in webpieces.config.json,
7
+ * labels itself as not the gate, prints the rule's own failure text plus a site count per project, and
8
+ * exits non-zero when there are sites. Build one with {@link CodeRulesRunRequestParser}, which refuses
9
+ * a `mode` or `projects` without a `rule`.
10
+ */
11
+ export declare class CodeRulesRunRequest {
12
+ /** The one rule a debug run judges; null = the gate (every rule, `mode`/`projects` unused). */
13
+ readonly rule: string | null;
14
+ /** A mode to judge `rule` at INSTEAD of its committed one; null = the committed mode. */
15
+ readonly mode: string | null;
16
+ /** nx project names to restrict the run to; null = every project. */
17
+ readonly projects: readonly string[] | null;
18
+ static readonly GATE: CodeRulesRunRequest;
19
+ constructor(
20
+ /** The one rule a debug run judges; null = the gate (every rule, `mode`/`projects` unused). */
21
+ rule: string | null,
22
+ /** A mode to judge `rule` at INSTEAD of its committed one; null = the committed mode. */
23
+ mode: string | null,
24
+ /** nx project names to restrict the run to; null = every project. */
25
+ projects: readonly string[] | null);
26
+ isDebug(): boolean;
27
+ }
28
+ /** Parses the debug flags from the `wp-validate-code` argv or the nx `validate-code` executor options. */
29
+ export declare class CodeRulesRunRequestParser {
30
+ /** From the bin's argv (process.argv.slice(2)). Unknown flags are refused. */
31
+ fromArgv(argv: readonly string[]): CodeRulesRunRequest;
32
+ /**
33
+ * From the nx `validate-code` executor's options, which is where
34
+ * `nx run architecture:validate-code --rule=… --mode=… --projects=…` lands. nx hands `projects` over
35
+ * as a string or, when it split the commas itself, as an array.
36
+ */
37
+ fromExecutorOptions(options: Record<string, unknown>): CodeRulesRunRequest;
38
+ private request;
39
+ private value;
40
+ private split;
41
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodeRulesRunRequestParser = exports.CodeRulesRunRequest = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const inversify_1 = require("inversify");
7
+ /** The three debug flags, spelled once for the parser and the usage text. */
8
+ const RULE_FLAG = '--rule=';
9
+ const MODE_FLAG = '--mode=';
10
+ const PROJECTS_FLAG = '--projects=';
11
+ const USAGE = `${RULE_FLAG}<rule> [${MODE_FLAG}<MODE>] [${PROJECTS_FLAG}<project>,<project>]`;
12
+ /**
13
+ * What one code-rules run was asked to do (#1027). Data-only, bound at the composition root.
14
+ *
15
+ * {@link GATE} is the build: every configured rule, at its COMMITTED mode, over the diff. Anything with a
16
+ * `rule` is a DEBUG run — that one rule, optionally at another mode (`mode`, no config edit), optionally
17
+ * restricted to named projects (`projects`). A debug run changes nothing in webpieces.config.json,
18
+ * labels itself as not the gate, prints the rule's own failure text plus a site count per project, and
19
+ * exits non-zero when there are sites. Build one with {@link CodeRulesRunRequestParser}, which refuses
20
+ * a `mode` or `projects` without a `rule`.
21
+ */
22
+ class CodeRulesRunRequest {
23
+ rule;
24
+ mode;
25
+ projects;
26
+ static GATE = new CodeRulesRunRequest(null, null, null);
27
+ constructor(
28
+ /** The one rule a debug run judges; null = the gate (every rule, `mode`/`projects` unused). */
29
+ rule,
30
+ /** A mode to judge `rule` at INSTEAD of its committed one; null = the committed mode. */
31
+ mode,
32
+ /** nx project names to restrict the run to; null = every project. */
33
+ projects) {
34
+ this.rule = rule;
35
+ this.mode = mode;
36
+ this.projects = projects;
37
+ }
38
+ isDebug() {
39
+ return this.rule !== null;
40
+ }
41
+ }
42
+ exports.CodeRulesRunRequest = CodeRulesRunRequest;
43
+ /** Parses the debug flags from the `wp-validate-code` argv or the nx `validate-code` executor options. */
44
+ let CodeRulesRunRequestParser = class CodeRulesRunRequestParser {
45
+ /** From the bin's argv (process.argv.slice(2)). Unknown flags are refused. */
46
+ fromArgv(argv) {
47
+ let rule = null;
48
+ let mode = null;
49
+ let projects = null;
50
+ for (const arg of argv) {
51
+ if (arg.startsWith(RULE_FLAG))
52
+ rule = this.value(arg, RULE_FLAG);
53
+ else if (arg.startsWith(MODE_FLAG))
54
+ mode = this.value(arg, MODE_FLAG);
55
+ else if (arg.startsWith(PROJECTS_FLAG))
56
+ projects = this.split(this.value(arg, PROJECTS_FLAG));
57
+ else
58
+ throw new rules_config_1.InformAiError(`Unknown argument '${arg}'. Usage: wp-validate-code ${USAGE}`);
59
+ }
60
+ return this.request(rule, mode, projects);
61
+ }
62
+ /**
63
+ * From the nx `validate-code` executor's options, which is where
64
+ * `nx run architecture:validate-code --rule=… --mode=… --projects=…` lands. nx hands `projects` over
65
+ * as a string or, when it split the commas itself, as an array.
66
+ */
67
+ // webpieces-disable no-any-unknown -- nx executor options arrive as an untyped record
68
+ fromExecutorOptions(options) {
69
+ const rule = typeof options['rule'] === 'string' ? options['rule'] : null;
70
+ const mode = typeof options['mode'] === 'string' ? options['mode'] : null;
71
+ const raw = options['projects'];
72
+ let projects = null;
73
+ if (typeof raw === 'string')
74
+ projects = this.split(raw);
75
+ else if (Array.isArray(raw))
76
+ projects = this.split(raw.map(String).join(','));
77
+ return this.request(rule, mode, projects);
78
+ }
79
+ request(rule, mode, projects) {
80
+ if (rule !== null)
81
+ return new CodeRulesRunRequest(rule, mode, projects);
82
+ if (mode === null && projects === null)
83
+ return CodeRulesRunRequest.GATE;
84
+ throw new rules_config_1.InformAiError(`${MODE_FLAG} and ${PROJECTS_FLAG} debug ONE rule, so they need ${RULE_FLAG}<rule> beside them. Usage: ${USAGE}`);
85
+ }
86
+ value(arg, flag) {
87
+ const value = arg.slice(flag.length).trim();
88
+ if (value.length === 0)
89
+ throw new rules_config_1.InformAiError(`${flag}<value> needs a value. Usage: ${USAGE}`);
90
+ return value;
91
+ }
92
+ split(list) {
93
+ const names = list.split(',').map((n) => n.trim()).filter((n) => n.length > 0);
94
+ if (names.length === 0)
95
+ throw new rules_config_1.InformAiError(`${PROJECTS_FLAG} names no project. Usage: ${USAGE}`);
96
+ return names;
97
+ }
98
+ };
99
+ exports.CodeRulesRunRequestParser = CodeRulesRunRequestParser;
100
+ exports.CodeRulesRunRequestParser = CodeRulesRunRequestParser = tslib_1.__decorate([
101
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
102
+ ], CodeRulesRunRequestParser);
103
+ //# sourceMappingURL=code-rules-run-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-rules-run-request.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-run-request.ts"],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EAAE,QAAQ,CAAC,CAAC;QACxE,IAAI,IAAI,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,mBAAmB,CAAC,IAAI,CAAC;QACxE,MAAM,IAAI,4BAAa,CACnB,GAAG,SAAS,QAAQ,aAAa,iCAAiC,SAAS,8BAA8B,KAAK,EAAE,CACnH,CAAC;IACN,CAAC;IAEO,KAAK,CAAC,GAAW,EAAE,IAAY;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,4BAAa,CAAC,GAAG,IAAI,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACjG,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/F,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,4BAAa,CAAC,GAAG,aAAa,6BAA6B,KAAK,EAAE,CAAC,CAAC;QACtG,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAA;AAlDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,yBAAyB,CAkDrC","sourcesContent":["import { InformAiError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** The three debug flags, spelled once for the parser and the usage text. */\nconst RULE_FLAG = '--rule=';\nconst MODE_FLAG = '--mode=';\nconst PROJECTS_FLAG = '--projects=';\nconst USAGE = `${RULE_FLAG}<rule> [${MODE_FLAG}<MODE>] [${PROJECTS_FLAG}<project>,<project>]`;\n\n/**\n * What one code-rules run was asked to do (#1027). Data-only, bound at the composition root.\n *\n * {@link GATE} is the build: every configured rule, at its COMMITTED mode, over the diff. Anything with a\n * `rule` is a DEBUG run — that one rule, optionally at another mode (`mode`, no config edit), optionally\n * restricted to named projects (`projects`). A debug run changes nothing in webpieces.config.json,\n * labels itself as not the gate, prints the rule's own failure text plus a site count per project, and\n * exits non-zero when there are sites. Build one with {@link CodeRulesRunRequestParser}, which refuses\n * a `mode` or `projects` without a `rule`.\n */\nexport class CodeRulesRunRequest {\n static readonly GATE = new CodeRulesRunRequest(null, null, null);\n\n constructor(\n /** The one rule a debug run judges; null = the gate (every rule, `mode`/`projects` unused). */\n readonly rule: string | null,\n /** A mode to judge `rule` at INSTEAD of its committed one; null = the committed mode. */\n readonly mode: string | null,\n /** nx project names to restrict the run to; null = every project. */\n readonly projects: readonly string[] | null,\n ) {}\n\n isDebug(): boolean {\n return this.rule !== null;\n }\n}\n\n/** Parses the debug flags from the `wp-validate-code` argv or the nx `validate-code` executor options. */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesRunRequestParser {\n /** From the bin's argv (process.argv.slice(2)). Unknown flags are refused. */\n fromArgv(argv: readonly string[]): CodeRulesRunRequest {\n let rule: string | null = null;\n let mode: string | null = null;\n let projects: string[] | null = null;\n for (const arg of argv) {\n if (arg.startsWith(RULE_FLAG)) rule = this.value(arg, RULE_FLAG);\n else if (arg.startsWith(MODE_FLAG)) mode = this.value(arg, MODE_FLAG);\n else if (arg.startsWith(PROJECTS_FLAG)) projects = this.split(this.value(arg, PROJECTS_FLAG));\n else throw new InformAiError(`Unknown argument '${arg}'. Usage: wp-validate-code ${USAGE}`);\n }\n return this.request(rule, mode, projects);\n }\n\n /**\n * From the nx `validate-code` executor's options, which is where\n * `nx run architecture:validate-code --rule=… --mode=… --projects=…` lands. nx hands `projects` over\n * as a string or, when it split the commas itself, as an array.\n */\n // webpieces-disable no-any-unknown -- nx executor options arrive as an untyped record\n fromExecutorOptions(options: Record<string, unknown>): CodeRulesRunRequest {\n const rule = typeof options['rule'] === 'string' ? options['rule'] : null;\n const mode = typeof options['mode'] === 'string' ? options['mode'] : null;\n const raw = options['projects'];\n let projects: string[] | null = null;\n if (typeof raw === 'string') projects = this.split(raw);\n else if (Array.isArray(raw)) projects = this.split(raw.map(String).join(','));\n return this.request(rule, mode, projects);\n }\n\n private request(rule: string | null, mode: string | null, projects: string[] | null): CodeRulesRunRequest {\n if (rule !== null) return new CodeRulesRunRequest(rule, mode, projects);\n if (mode === null && projects === null) return CodeRulesRunRequest.GATE;\n throw new InformAiError(\n `${MODE_FLAG} and ${PROJECTS_FLAG} debug ONE rule, so they need ${RULE_FLAG}<rule> beside them. Usage: ${USAGE}`,\n );\n }\n\n private value(arg: string, flag: string): string {\n const value = arg.slice(flag.length).trim();\n if (value.length === 0) throw new InformAiError(`${flag}<value> needs a value. Usage: ${USAGE}`);\n return value;\n }\n\n private split(list: string): string[] {\n const names = list.split(',').map((n: string) => n.trim()).filter((n: string) => n.length > 0);\n if (names.length === 0) throw new InformAiError(`${PROJECTS_FLAG} names no project. Usage: ${USAGE}`);\n return names;\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { ExecutorResult, RuleRun } from './code-validator';
2
+ import { DebugTarget } from './rule-scope-plan';
3
+ import { RuleReporter } from './rule-reporter';
4
+ /**
5
+ * Runs a DEBUG run (#1027): one rule, labelled as not the gate, its own failure text printed exactly as
6
+ * the build prints it, then a count of sites per project. Nothing is written to webpieces.config.json.
7
+ *
8
+ * The count is taken from what the rule PRINTED — every `path` / `path:line` it named that is a file in
9
+ * a project — rather than from each rule's internals, because the rules report through one renderer
10
+ * but hold their sites in thirty different shapes. A site named twice (in the message and in a cure)
11
+ * counts once. A passing run has no sites by definition, whatever file names it logged on the way.
12
+ */
13
+ export declare class DebugRunReport {
14
+ private readonly reporter;
15
+ constructor(reporter: RuleReporter);
16
+ run(workspaceRoot: string, runs: readonly RuleRun[], target: DebugTarget): Promise<ExecutorResult>;
17
+ private printBanner;
18
+ private capture;
19
+ private sitesIn;
20
+ private siteOf;
21
+ private printCounts;
22
+ }