@webpieces/code-rules 0.4.844 → 0.4.845

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.
Files changed (135) hide show
  1. package/package.json +6 -6
  2. package/src/api-lib-source-rule.d.ts +4 -1
  3. package/src/api-lib-source-rule.js.map +1 -1
  4. package/src/code-rules-bootstrap.js +8 -7
  5. package/src/code-rules-bootstrap.js.map +1 -1
  6. package/src/code-rules-config-table.d.ts +9 -11
  7. package/src/code-rules-config-table.js +48 -33
  8. package/src/code-rules-config-table.js.map +1 -1
  9. package/src/configs/api-lib-spelling-configs.d.ts +40 -0
  10. package/src/configs/api-lib-spelling-configs.js +52 -0
  11. package/src/configs/api-lib-spelling-configs.js.map +1 -0
  12. package/src/configs/no-client-creation-config.d.ts +12 -0
  13. package/src/configs/no-client-creation-config.js +40 -0
  14. package/src/configs/no-client-creation-config.js.map +1 -0
  15. package/src/configs/no-state-paths-config.d.ts +41 -0
  16. package/src/configs/no-state-paths-config.js +51 -0
  17. package/src/configs/no-state-paths-config.js.map +1 -0
  18. package/src/configs/no-utility-types-config.d.ts +30 -0
  19. package/src/configs/no-utility-types-config.js +39 -0
  20. package/src/configs/no-utility-types-config.js.map +1 -0
  21. package/src/configs/required-type-suffix-config.d.ts +49 -0
  22. package/src/configs/required-type-suffix-config.js +62 -0
  23. package/src/configs/required-type-suffix-config.js.map +1 -0
  24. package/src/configs/rule-configs.d.ts +131 -0
  25. package/src/configs/rule-configs.js +309 -0
  26. package/src/configs/rule-configs.js.map +1 -0
  27. package/src/configs/tag-truth-configs.d.ts +66 -0
  28. package/src/configs/tag-truth-configs.js +82 -0
  29. package/src/configs/tag-truth-configs.js.map +1 -0
  30. package/src/index.d.ts +10 -0
  31. package/src/index.js +50 -1
  32. package/src/index.js.map +1 -1
  33. package/src/project-scan-targets.d.ts +2 -1
  34. package/src/project-scan-targets.js.map +1 -1
  35. package/src/rule-pack.d.ts +1 -0
  36. package/src/rule-pack.js +4 -35
  37. package/src/rule-pack.js.map +1 -1
  38. package/src/rule-settings.d.ts +5 -0
  39. package/src/rule-settings.js +269 -0
  40. package/src/rule-settings.js.map +1 -0
  41. package/src/scan-scope.d.ts +2 -1
  42. package/src/scan-scope.js.map +1 -1
  43. package/src/tag-rule.d.ts +1 -1
  44. package/src/tag-rule.js.map +1 -1
  45. package/src/validate-catch-error-pattern.d.ts +1 -1
  46. package/src/validate-catch-error-pattern.js +4 -3
  47. package/src/validate-catch-error-pattern.js.map +1 -1
  48. package/src/validate-dtos.d.ts +1 -1
  49. package/src/validate-dtos.js +2 -1
  50. package/src/validate-dtos.js.map +1 -1
  51. package/src/validate-ensure-we-are-secure.d.ts +2 -1
  52. package/src/validate-ensure-we-are-secure.js +3 -2
  53. package/src/validate-ensure-we-are-secure.js.map +1 -1
  54. package/src/validate-framework-packages.d.ts +2 -1
  55. package/src/validate-framework-packages.js +7 -6
  56. package/src/validate-framework-packages.js.map +1 -1
  57. package/src/validate-framework-tag.d.ts +1 -1
  58. package/src/validate-framework-tag.js +2 -2
  59. package/src/validate-framework-tag.js.map +1 -1
  60. package/src/validate-framework-tsconfig.d.ts +2 -1
  61. package/src/validate-framework-tsconfig.js +5 -4
  62. package/src/validate-framework-tsconfig.js.map +1 -1
  63. package/src/validate-inject-annotation-not-needed-for-concrete-class.d.ts +1 -1
  64. package/src/validate-inject-annotation-not-needed-for-concrete-class.js +3 -2
  65. package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
  66. package/src/validate-match-rules.d.ts +1 -1
  67. package/src/validate-match-rules.js.map +1 -1
  68. package/src/validate-modified-files.d.ts +2 -1
  69. package/src/validate-modified-files.js +3 -2
  70. package/src/validate-modified-files.js.map +1 -1
  71. package/src/validate-modified-methods.d.ts +1 -1
  72. package/src/validate-modified-methods.js +4 -3
  73. package/src/validate-modified-methods.js.map +1 -1
  74. package/src/validate-new-methods.d.ts +1 -1
  75. package/src/validate-new-methods.js +1 -1
  76. package/src/validate-new-methods.js.map +1 -1
  77. package/src/validate-no-any-unknown.d.ts +1 -1
  78. package/src/validate-no-any-unknown.js +3 -2
  79. package/src/validate-no-any-unknown.js.map +1 -1
  80. package/src/validate-no-client-creation-outside-server-or-client.d.ts +1 -1
  81. package/src/validate-no-client-creation-outside-server-or-client.js +3 -2
  82. package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
  83. package/src/validate-no-custom-css.d.ts +1 -1
  84. package/src/validate-no-custom-css.js +3 -2
  85. package/src/validate-no-custom-css.js.map +1 -1
  86. package/src/validate-no-destructure.d.ts +1 -1
  87. package/src/validate-no-destructure.js +3 -2
  88. package/src/validate-no-destructure.js.map +1 -1
  89. package/src/validate-no-direct-api-resolver.d.ts +1 -1
  90. package/src/validate-no-direct-api-resolver.js +3 -2
  91. package/src/validate-no-direct-api-resolver.js.map +1 -1
  92. package/src/validate-no-function-outside-class.d.ts +1 -1
  93. package/src/validate-no-function-outside-class.js +4 -3
  94. package/src/validate-no-function-outside-class.js.map +1 -1
  95. package/src/validate-no-implicit-any.d.ts +1 -1
  96. package/src/validate-no-implicit-any.js +3 -2
  97. package/src/validate-no-implicit-any.js.map +1 -1
  98. package/src/validate-no-inline-import-in-api-lib.d.ts +2 -1
  99. package/src/validate-no-inline-import-in-api-lib.js +3 -2
  100. package/src/validate-no-inline-import-in-api-lib.js.map +1 -1
  101. package/src/validate-no-inline-types.d.ts +1 -1
  102. package/src/validate-no-inline-types.js +3 -2
  103. package/src/validate-no-inline-types.js.map +1 -1
  104. package/src/validate-no-process-exit-outside-main.d.ts +1 -1
  105. package/src/validate-no-process-exit-outside-main.js +3 -2
  106. package/src/validate-no-process-exit-outside-main.js.map +1 -1
  107. package/src/validate-no-state-paths-in-templates.d.ts +1 -1
  108. package/src/validate-no-state-paths-in-templates.js +7 -6
  109. package/src/validate-no-state-paths-in-templates.js.map +1 -1
  110. package/src/validate-no-symbol-di-tokens.d.ts +1 -1
  111. package/src/validate-no-symbol-di-tokens.js +3 -2
  112. package/src/validate-no-symbol-di-tokens.js.map +1 -1
  113. package/src/validate-no-unmanaged-exceptions.d.ts +1 -1
  114. package/src/validate-no-unmanaged-exceptions.js +3 -2
  115. package/src/validate-no-unmanaged-exceptions.js.map +1 -1
  116. package/src/validate-no-utility-types-in-api-lib.d.ts +2 -1
  117. package/src/validate-no-utility-types-in-api-lib.js +3 -2
  118. package/src/validate-no-utility-types-in-api-lib.js.map +1 -1
  119. package/src/validate-one-enum-spelling-in-api-lib.d.ts +2 -1
  120. package/src/validate-one-enum-spelling-in-api-lib.js +3 -2
  121. package/src/validate-one-enum-spelling-in-api-lib.js.map +1 -1
  122. package/src/validate-prisma-converters.d.ts +1 -1
  123. package/src/validate-prisma-converters.js +3 -2
  124. package/src/validate-prisma-converters.js.map +1 -1
  125. package/src/validate-required-type-suffix.d.ts +2 -1
  126. package/src/validate-required-type-suffix.js +3 -2
  127. package/src/validate-required-type-suffix.js.map +1 -1
  128. package/src/validate-return-types.d.ts +1 -1
  129. package/src/validate-return-types.js +3 -2
  130. package/src/validate-return-types.js.map +1 -1
  131. package/src/validate-role-tag.d.ts +1 -1
  132. package/src/validate-role-tag.js +2 -2
  133. package/src/validate-role-tag.js.map +1 -1
  134. package/src/wp-ci.js +2 -2
  135. package/src/wp-ci.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/code-rules",
3
- "version": "0.4.844",
3
+ "version": "0.4.845",
4
4
  "description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,19 +16,19 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.844",
19
+ "@webpieces/rules-config": "0.4.845",
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.844",
24
- "@webpieces/repo-workflow-core": "0.4.844",
25
- "@webpieces/rules-sdk": "0.4.844"
23
+ "@webpieces/tooling-common": "0.4.845",
24
+ "@webpieces/repo-workflow-core": "0.4.845",
25
+ "@webpieces/rules-sdk": "0.4.845"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "devDependencies": {
31
- "@webpieces/tooling-testkit": "0.4.844"
31
+ "@webpieces/tooling-testkit": "0.4.845"
32
32
  },
33
33
  "exports": {
34
34
  ".": "./src/index.js",
@@ -16,7 +16,10 @@
16
16
  * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.
17
17
  */
18
18
  import * as ts from 'typescript';
19
- import { DiffScope, NoInlineImportInApiLibConfig, NoUtilityTypesInApiLibConfig, OneEnumSpellingInApiLibConfig, RequiredTypeSuffixConfig } from '@webpieces/rules-config';
19
+ import { DiffScope } from "@webpieces/rules-config";
20
+ import { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from "./configs/api-lib-spelling-configs";
21
+ import { NoUtilityTypesInApiLibConfig } from "./configs/no-utility-types-config";
22
+ import { RequiredTypeSuffixConfig } from "./configs/required-type-suffix-config";
20
23
  import { CodeValidator, ExecutorResult } from './code-validator';
21
24
  import { ProjectRoleResolver } from './project-role-resolver';
22
25
  import { ScanScope } from './scan-scope';
@@ -1 +1 @@
1
- {"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAWiC;AACjC,qDAAiE;AAIjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SA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I,EAAE,EAAE,IAAI,CAAC,CAAC,CAC3G,CAAC;IACN,CAAC;CACJ;AA1GD,4CA0GC","sourcesContent":["/**\n * The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every\n * file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport {\n DiffScope,\n ModifiedCodeMode,\n NoInlineImportInApiLibConfig,\n NoUtilityTypesInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n Option,\n RequiredTypeSuffixConfig,\n RuleFailError,\n hasDisable,\n isPathExcluded,\n} from '@webpieces/rules-config';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n private readonly scanScope: ScanScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {\n found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n this.scanScope.recordSites(this.name, found.map((each: FoundSite) => each.relFile));\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): FoundSite[] {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = this.scanScope.isLineScoped(mode)\n ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (isPathExcluded(relFile, this.config.allowedPaths ?? [])) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuG;AAKvG,qDAAiE;AAIjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AATD,gCASC;AAED,+FAA+F;AAC/F,MAAa,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OAAe;QACvD,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1D,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;YACjF,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAEO,OAAO,CAAC,KAA2B;QACvC,MAAM,OAAO,GACT,GAAG,KAAK,CAAC,MAAM,eAAe,IAAI,CAAC,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,IAAI;YAClE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChI,mDAAmD,IAAI,CAAC,IAAI,cAAc,CAAC;QAC/E,OAAO,IAAI,4BAAa,CACpB,IAAI,CAAC,IAAI,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAC3G,CAAC;IACN,CAAC;CACJ;AA1GD,4CA0GC","sourcesContent":["/**\n * The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every\n * file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { DiffScope, Option, RuleFailError, hasDisable, isPathExcluded } from \"@webpieces/rules-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n private readonly scanScope: ScanScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {\n found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n this.scanScope.recordSites(this.name, found.map((each: FoundSite) => each.relFile));\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): FoundSite[] {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = this.scanScope.isLineScoped(mode)\n ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file, not under `allowedPaths`, that {@link isApiLibrarySource} claims. */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (isPathExcluded(relFile, this.config.allowedPaths ?? [])) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
@@ -4,6 +4,7 @@ exports.CodeRulesBootstrap = void 0;
4
4
  require("reflect-metadata");
5
5
  const inversify_1 = require("inversify");
6
6
  const rules_config_1 = require("@webpieces/rules-config");
7
+ const rules_sdk_1 = require("@webpieces/rules-sdk");
7
8
  const tooling_common_1 = require("@webpieces/tooling-common");
8
9
  const code_rules_app_1 = require("./code-rules-app");
9
10
  const code_rules_context_1 = require("./code-rules-context");
@@ -55,10 +56,10 @@ class CodeRulesBootstrap {
55
56
  container.bind(code_rules_run_request_1.RuleSelection).toConstantValue(new code_rules_run_request_1.RuleSelection(plan?.rule));
56
57
  container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(plan?.projects));
57
58
  for (const binding of code_rules_config_table_1.CONFIG_BINDINGS) {
58
- const ConfigClass = binding[0];
59
- const configured = loaded.rulesConfig[binding[1]];
59
+ const ConfigClass = binding.configClass;
60
+ const configured = loaded.rulesConfig[binding.ruleId];
60
61
  const config = configured ?? new ConfigClass();
61
- container.bind(ConfigClass).toConstantValue(plan?.rule === binding[1] ? this.overridden(config, plan) : config);
62
+ container.bind(ConfigClass).toConstantValue(plan?.rule === binding.ruleId ? this.overridden(config, plan) : config);
62
63
  }
63
64
  const result = await container.get(code_rules_app_1.CodeRulesApp).run();
64
65
  if (plan === undefined)
@@ -97,14 +98,14 @@ class CodeRulesBootstrap {
97
98
  /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */
98
99
  wholeScopeModesOf(rule, loaded) {
99
100
  if (loaded.matchRules.some((mr) => mr.name === rule))
100
- return rules_config_1.MODIFIED_CODE_MODES;
101
- if (!code_rules_config_table_1.CONFIG_BINDINGS.some((binding) => binding[1] === rule))
101
+ return rules_sdk_1.MODIFIED_CODE_MODES;
102
+ if (!code_rules_config_table_1.CONFIG_BINDINGS.some((binding) => binding.ruleId === rule))
102
103
  return undefined;
103
- const modes = rules_config_1.RULE_SCHEMAS[rule]?.['mode']?.enumValues ?? [];
104
+ const modes = code_rules_config_table_1.CONFIG_BINDINGS.find(binding => binding.ruleId === rule)?.schema['mode']?.enumValues ?? [];
104
105
  return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME') ? modes : undefined;
105
106
  }
106
107
  debuggableRules(loaded) {
107
- const builtIns = code_rules_config_table_1.CONFIG_BINDINGS.map((binding) => binding[1]);
108
+ const builtIns = code_rules_config_table_1.CONFIG_BINDINGS.map((binding) => binding.ruleId);
108
109
  const names = [...builtIns, ...loaded.matchRules.map((mr) => mr.name)];
109
110
  return names.filter((name) => this.wholeScopeModesOf(name, loaded) !== undefined);
110
111
  }
@@ -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,0DAAuI;AACvI,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAuE;AACvE,uEAA2E;AAC3E,qEAA8E;AAC9E,6CAAwF;AAExF,0GAA0G;AAC1G,MAAM,SAAS;IAEE;I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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;AAxHD,gDAwHC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { DiffScope, LoadedConfig, MatchRuleConfig, MODIFIED_CODE_MODES, RULE_SCHEMAS, loadAndValidate } from '@webpieces/rules-config';\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[0];\n const configured = loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined;\n const config = configured ?? new ConfigClass();\n container.bind(ConfigClass).toConstantValue(plan?.rule === binding[1] ? 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[1] === rule)) return undefined;\n const modes = RULE_SCHEMAS[rule]?.['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[1] 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":";;;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;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,CAAC,qEAAqE,CAAC,CAAC;QACnG,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,kHAAkH;QAClH,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC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,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAChE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,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;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,13 +1,11 @@
1
- import { BaseRuleConfig } from '@webpieces/rules-sdk';
2
- import { WebpiecesRulesConfig } from '@webpieces/rules-config';
3
- /** A rule config class usable as an inversify inject-by-type token. */
1
+ import { BaseRuleConfig, FieldDef } from '@webpieces/rules-sdk';
2
+ /** A concrete configuration data constructor used as the owner DI token. */
4
3
  export type ConfigCtor = new () => BaseRuleConfig;
5
- /**
6
- * The 1:1 table of `[config class, webpieces.config.json rule key]`. The composition root iterates it
7
- * to bind each rule's config into the container (`bind(ConfigClass).toConstantValue(config[key] ??
8
- * new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only
9
- * — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).
10
- */
11
- /** One `[config class, rule key]` row of {@link CONFIG_BINDINGS}. */
12
- export type ConfigBinding = readonly [ConfigCtor, keyof WebpiecesRulesConfig];
4
+ /** An owner-local configuration binding and its canonical schema. */
5
+ export declare class ConfigBinding {
6
+ readonly configClass: ConfigCtor;
7
+ readonly ruleId: string;
8
+ readonly schema: Readonly<Record<string, FieldDef>>;
9
+ constructor(configClass: ConfigCtor, ruleId: string, schema: Readonly<Record<string, FieldDef>>);
10
+ }
13
11
  export declare const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding>;
@@ -1,38 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG_BINDINGS = void 0;
4
- const rules_config_1 = require("@webpieces/rules-config");
3
+ exports.CONFIG_BINDINGS = exports.ConfigBinding = void 0;
4
+ const rule_configs_1 = require("./configs/rule-configs");
5
+ const no_client_creation_config_1 = require("./configs/no-client-creation-config");
6
+ const no_state_paths_config_1 = require("./configs/no-state-paths-config");
7
+ const api_lib_spelling_configs_1 = require("./configs/api-lib-spelling-configs");
8
+ const no_utility_types_config_1 = require("./configs/no-utility-types-config");
9
+ const required_type_suffix_config_1 = require("./configs/required-type-suffix-config");
10
+ const tag_truth_configs_1 = require("./configs/tag-truth-configs");
11
+ /** An owner-local configuration binding and its canonical schema. */
12
+ class ConfigBinding {
13
+ configClass;
14
+ ruleId;
15
+ schema;
16
+ constructor(configClass, ruleId, schema) {
17
+ this.configClass = configClass;
18
+ this.ruleId = ruleId;
19
+ this.schema = schema;
20
+ }
21
+ }
22
+ exports.ConfigBinding = ConfigBinding;
5
23
  exports.CONFIG_BINDINGS = [
6
- [rules_config_1.MaxMethodLinesConfig, 'max-method-lines'],
7
- [rules_config_1.MaxFileLinesConfig, 'max-file-lines'],
8
- [rules_config_1.RequireReturnTypeConfig, 'require-return-type'],
9
- [rules_config_1.NoInlineTypeLiteralsConfig, 'no-inline-type-literals'],
10
- [rules_config_1.NoAnyUnknownConfig, 'no-any-unknown'],
11
- [rules_config_1.NoImplicitAnyConfig, 'no-implicit-any'],
12
- [rules_config_1.PrismaValidateDtosConfig, 'prisma-validate-dtos'],
13
- [rules_config_1.PrismaConverterConfig, 'prisma-converter'],
14
- [rules_config_1.NoDestructureConfig, 'no-destructure'],
15
- [rules_config_1.CatchErrorPatternConfig, 'catch-error-pattern'],
16
- [rules_config_1.NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions'],
17
- [rules_config_1.AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver'],
18
- [rules_config_1.NoSymbolDiTokensConfig, 'no-symbol-di-tokens'],
19
- [rules_config_1.NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client'],
20
- [rules_config_1.NoCustomCssConfig, 'no-custom-css'],
21
- [rules_config_1.NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates'],
22
- [rules_config_1.NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main'],
23
- [rules_config_1.NoFunctionOutsideClassConfig, 'no-function-outside-class'],
24
- [
25
- rules_config_1.InjectAnnotationNotNeededForConcreteClassConfig,
26
- 'inject-annotation-not-needed-for-concrete-class',
27
- ],
28
- [rules_config_1.FrameworkTagConfig, 'framework-tag'],
29
- [rules_config_1.RoleTagConfig, 'role-tag'],
30
- [rules_config_1.EnsureWeAreSecureConfig, 'ensure-we-are-secure'],
31
- [rules_config_1.NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib'],
32
- [rules_config_1.OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib'],
33
- [rules_config_1.NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib'],
34
- [rules_config_1.RequiredTypeSuffixConfig, 'required-type-suffix'],
35
- [rules_config_1.FrameworkTsconfigConfig, 'framework-tsconfig'],
36
- [rules_config_1.FrameworkPackagesConfig, 'framework-packages'],
24
+ new ConfigBinding(rule_configs_1.MaxMethodLinesConfig, 'max-method-lines', rule_configs_1.MaxMethodLinesConfig.SCHEMA),
25
+ new ConfigBinding(rule_configs_1.MaxFileLinesConfig, 'max-file-lines', rule_configs_1.MaxFileLinesConfig.SCHEMA),
26
+ new ConfigBinding(rule_configs_1.RequireReturnTypeConfig, 'require-return-type', rule_configs_1.RequireReturnTypeConfig.SCHEMA),
27
+ new ConfigBinding(rule_configs_1.NoInlineTypeLiteralsConfig, 'no-inline-type-literals', rule_configs_1.NoInlineTypeLiteralsConfig.SCHEMA),
28
+ new ConfigBinding(rule_configs_1.NoAnyUnknownConfig, 'no-any-unknown', rule_configs_1.NoAnyUnknownConfig.SCHEMA),
29
+ new ConfigBinding(rule_configs_1.NoImplicitAnyConfig, 'no-implicit-any', rule_configs_1.NoImplicitAnyConfig.SCHEMA),
30
+ new ConfigBinding(rule_configs_1.PrismaValidateDtosConfig, 'prisma-validate-dtos', rule_configs_1.PrismaValidateDtosConfig.SCHEMA),
31
+ new ConfigBinding(rule_configs_1.PrismaConverterConfig, 'prisma-converter', rule_configs_1.PrismaConverterConfig.SCHEMA),
32
+ new ConfigBinding(rule_configs_1.NoDestructureConfig, 'no-destructure', rule_configs_1.NoDestructureConfig.SCHEMA),
33
+ new ConfigBinding(rule_configs_1.CatchErrorPatternConfig, 'catch-error-pattern', rule_configs_1.CatchErrorPatternConfig.SCHEMA),
34
+ new ConfigBinding(rule_configs_1.NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions', rule_configs_1.NoUnmanagedExceptionsConfig.SCHEMA),
35
+ new ConfigBinding(rule_configs_1.AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver', rule_configs_1.AngularNoDirectApiInResolverConfig.SCHEMA),
36
+ new ConfigBinding(rule_configs_1.NoSymbolDiTokensConfig, 'no-symbol-di-tokens', rule_configs_1.NoSymbolDiTokensConfig.SCHEMA),
37
+ new ConfigBinding(no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client', no_client_creation_config_1.NoClientCreationOutsideServerOrClientConfig.SCHEMA),
38
+ new ConfigBinding(rule_configs_1.NoCustomCssConfig, 'no-custom-css', rule_configs_1.NoCustomCssConfig.SCHEMA),
39
+ new ConfigBinding(no_state_paths_config_1.NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates', no_state_paths_config_1.NoStatePathsInTemplatesConfig.SCHEMA),
40
+ new ConfigBinding(rule_configs_1.NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main', rule_configs_1.NoProcessExitOutsideMainConfig.SCHEMA),
41
+ new ConfigBinding(rule_configs_1.NoFunctionOutsideClassConfig, 'no-function-outside-class', rule_configs_1.NoFunctionOutsideClassConfig.SCHEMA),
42
+ new ConfigBinding(rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig, 'inject-annotation-not-needed-for-concrete-class', rule_configs_1.InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA),
43
+ new ConfigBinding(rule_configs_1.FrameworkTagConfig, 'framework-tag', rule_configs_1.FrameworkTagConfig.SCHEMA),
44
+ new ConfigBinding(rule_configs_1.RoleTagConfig, 'role-tag', rule_configs_1.RoleTagConfig.SCHEMA),
45
+ new ConfigBinding(rule_configs_1.EnsureWeAreSecureConfig, 'ensure-we-are-secure', rule_configs_1.EnsureWeAreSecureConfig.SCHEMA),
46
+ new ConfigBinding(api_lib_spelling_configs_1.NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib', api_lib_spelling_configs_1.NoInlineImportInApiLibConfig.SCHEMA),
47
+ new ConfigBinding(api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib', api_lib_spelling_configs_1.OneEnumSpellingInApiLibConfig.SCHEMA),
48
+ new ConfigBinding(no_utility_types_config_1.NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib', no_utility_types_config_1.NoUtilityTypesInApiLibConfig.SCHEMA),
49
+ new ConfigBinding(required_type_suffix_config_1.RequiredTypeSuffixConfig, 'required-type-suffix', required_type_suffix_config_1.RequiredTypeSuffixConfig.SCHEMA),
50
+ new ConfigBinding(tag_truth_configs_1.FrameworkTsconfigConfig, 'framework-tsconfig', tag_truth_configs_1.FrameworkTsconfigConfig.SCHEMA),
51
+ new ConfigBinding(tag_truth_configs_1.FrameworkPackagesConfig, 'framework-packages', tag_truth_configs_1.FrameworkPackagesConfig.SCHEMA),
37
52
  ];
38
53
  //# sourceMappingURL=code-rules-config-table.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AACA,0DAAgzB;AAcnyB,QAAA,eAAe,GAAiC;IACzD,CAAC,mCAAoB,EAAE,kBAAkB,CAAC;IAC1C,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,yCAA0B,EAAE,yBAAyB,CAAC;IACvD,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,kCAAmB,EAAE,iBAAiB,CAAC;IACxC,CAAC,uCAAwB,EAAE,sBAAsB,CAAC;IAClD,CAAC,oCAAqB,EAAE,kBAAkB,CAAC;IAC3C,CAAC,kCAAmB,EAAE,gBAAgB,CAAC;IACvC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,0CAA2B,EAAE,yBAAyB,CAAC;IACxD,CAAC,iDAAkC,EAAE,mCAAmC,CAAC;IACzE,CAAC,qCAAsB,EAAE,qBAAqB,CAAC;IAC/C,CAAC,0DAA2C,EAAE,6CAA6C,CAAC;IAC5F,CAAC,gCAAiB,EAAE,eAAe,CAAC;IACpC,CAAC,4CAA6B,EAAE,6BAA6B,CAAC;IAC9D,CAAC,6CAA8B,EAAE,8BAA8B,CAAC;IAChE,CAAC,2CAA4B,EAAE,2BAA2B,CAAC;IAC3D;QACI,8DAA+C;QAC/C,iDAAiD;KACpD;IACD,CAAC,iCAAkB,EAAE,eAAe,CAAC;IACrC,CAAC,4BAAa,EAAE,UAAU,CAAC;IAC3B,CAAC,sCAAuB,EAAE,sBAAsB,CAAC;IACjD,CAAC,2CAA4B,EAAE,6BAA6B,CAAC;IAC7D,CAAC,4CAA6B,EAAE,8BAA8B,CAAC;IAC/D,CAAC,2CAA4B,EAAE,6BAA6B,CAAC;IAC7D,CAAC,uCAAwB,EAAE,sBAAsB,CAAC;IAClD,CAAC,sCAAuB,EAAE,oBAAoB,CAAC;IAC/C,CAAC,sCAAuB,EAAE,oBAAoB,CAAC;CAClD,CAAC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport { WebpiecesRulesConfig, MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, CatchErrorPatternConfig, NoUnmanagedExceptionsConfig, AngularNoDirectApiInResolverConfig, NoSymbolDiTokensConfig, NoClientCreationOutsideServerOrClientConfig, NoCustomCssConfig, NoStatePathsInTemplatesConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig, NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig, NoUtilityTypesInApiLibConfig, RequiredTypeSuffixConfig, FrameworkTsconfigConfig, FrameworkPackagesConfig } from '@webpieces/rules-config';\n\n/** A rule config class usable as an inversify inject-by-type token. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\n/**\n * The 1:1 table of `[config class, webpieces.config.json rule key]`. The composition root iterates it\n * to bind each rule's config into the container (`bind(ConfigClass).toConstantValue(config[key] ??\n * new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only\n * — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).\n */\n/** One `[config class, rule key]` row of {@link CONFIG_BINDINGS}. */\nexport type ConfigBinding = readonly [ConfigCtor, keyof WebpiecesRulesConfig];\n\nexport const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding> = [\n [MaxMethodLinesConfig, 'max-method-lines'],\n [MaxFileLinesConfig, 'max-file-lines'],\n [RequireReturnTypeConfig, 'require-return-type'],\n [NoInlineTypeLiteralsConfig, 'no-inline-type-literals'],\n [NoAnyUnknownConfig, 'no-any-unknown'],\n [NoImplicitAnyConfig, 'no-implicit-any'],\n [PrismaValidateDtosConfig, 'prisma-validate-dtos'],\n [PrismaConverterConfig, 'prisma-converter'],\n [NoDestructureConfig, 'no-destructure'],\n [CatchErrorPatternConfig, 'catch-error-pattern'],\n [NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions'],\n [AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver'],\n [NoSymbolDiTokensConfig, 'no-symbol-di-tokens'],\n [NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client'],\n [NoCustomCssConfig, 'no-custom-css'],\n [NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates'],\n [NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main'],\n [NoFunctionOutsideClassConfig, 'no-function-outside-class'],\n [\n InjectAnnotationNotNeededForConcreteClassConfig,\n 'inject-annotation-not-needed-for-concrete-class',\n ],\n [FrameworkTagConfig, 'framework-tag'],\n [RoleTagConfig, 'role-tag'],\n [EnsureWeAreSecureConfig, 'ensure-we-are-secure'],\n [NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib'],\n [OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib'],\n [NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib'],\n [RequiredTypeSuffixConfig, 'required-type-suffix'],\n [FrameworkTsconfigConfig, 'framework-tsconfig'],\n [FrameworkPackagesConfig, 'framework-packages'],\n];\n"]}
1
+ {"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AACA,yDAAsiB;AACtiB,mFAAkG;AAClG,2EAAgF;AAChF,iFAAiH;AACjH,+EAAiF;AACjF,uFAAiF;AACjF,mEAA+F;AAK/F,qEAAqE;AACrE,MAAa,aAAa;IAET;IACA;IACA;IAHb,YACa,WAAuB,EACvB,MAAc,EACd,MAA0C;QAF1C,gBAAW,GAAX,WAAW,CAAY;QACvB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAA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,CAAC,MAAM,CAAC;IAC/E,IAAI,aAAa,CAAC,qDAA6B,EAAE,6BAA6B,EAAE,qDAA6B,CAAC,MAAM,CAAC;IACrH,IAAI,aAAa,CAAC,6CAA8B,EAAE,8BAA8B,EAAE,6CAA8B,CAAC,MAAM,CAAC;IACxH,IAAI,aAAa,CAAC,2CAA4B,EAAE,2BAA2B,EAAE,2CAA4B,CAAC,MAAM,CAAC;IACjH,IAAI,aAAa,CAAC,8DAA+C,EAAE,iDAAiD,EAAE,8DAA+C,CAAC,MAAM,CAAC;IAC7K,IAAI,aAAa,CAAC,iCAAkB,EAAE,eAAe,EAAE,iCAAkB,CAAC,MAAM,CAAC;IACjF,IAAI,aAAa,CAAC,4BAAa,EAAE,UAAU,EAAE,4BAAa,CAAC,MAAM,CAAC;IAClE,IAAI,aAAa,CAAC,sCAAuB,EAAE,sBAAsB,EAAE,sCAAuB,CAAC,MAAM,CAAC;IAClG,IAAI,aAAa,CAAC,uDAA4B,EAAE,6BAA6B,EAAE,uDAA4B,CAAC,MAAM,CAAC;IACnH,IAAI,aAAa,CAAC,wDAA6B,EAAE,8BAA8B,EAAE,wDAA6B,CAAC,MAAM,CAAC;IACtH,IAAI,aAAa,CAAC,sDAA4B,EAAE,6BAA6B,EAAE,sDAA4B,CAAC,MAAM,CAAC;IACnH,IAAI,aAAa,CAAC,sDAAwB,EAAE,sBAAsB,EAAE,sDAAwB,CAAC,MAAM,CAAC;IACpG,IAAI,aAAa,CAAC,2CAAuB,EAAE,oBAAoB,EAAE,2CAAuB,CAAC,MAAM,CAAC;IAChG,IAAI,aAAa,CAAC,2CAAuB,EAAE,oBAAoB,EAAE,2CAAuB,CAAC,MAAM,CAAC;CACnG,CAAC","sourcesContent":["import { BaseRuleConfig, FieldDef } from '@webpieces/rules-sdk';\nimport { MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoInlineTypeLiteralsConfig, NoAnyUnknownConfig, NoImplicitAnyConfig, PrismaValidateDtosConfig, PrismaConverterConfig, NoDestructureConfig, CatchErrorPatternConfig, NoUnmanagedExceptionsConfig, AngularNoDirectApiInResolverConfig, NoSymbolDiTokensConfig, NoCustomCssConfig, NoProcessExitOutsideMainConfig, NoFunctionOutsideClassConfig, InjectAnnotationNotNeededForConcreteClassConfig, FrameworkTagConfig, RoleTagConfig, EnsureWeAreSecureConfig } from \"./configs/rule-configs\";\nimport { NoClientCreationOutsideServerOrClientConfig } from \"./configs/no-client-creation-config\";\nimport { NoStatePathsInTemplatesConfig } from \"./configs/no-state-paths-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { FrameworkTsconfigConfig, FrameworkPackagesConfig } from \"./configs/tag-truth-configs\";\n\n/** A concrete configuration data constructor used as the owner DI token. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\n/** An owner-local configuration binding and its canonical schema. */\nexport class ConfigBinding {\n constructor(\n readonly configClass: ConfigCtor,\n readonly ruleId: string,\n readonly schema: Readonly<Record<string, FieldDef>>,\n ) {}\n}\n\nexport const CONFIG_BINDINGS: ReadonlyArray<ConfigBinding> = [\n new ConfigBinding(MaxMethodLinesConfig, 'max-method-lines', MaxMethodLinesConfig.SCHEMA),\n new ConfigBinding(MaxFileLinesConfig, 'max-file-lines', MaxFileLinesConfig.SCHEMA),\n new ConfigBinding(RequireReturnTypeConfig, 'require-return-type', RequireReturnTypeConfig.SCHEMA),\n new ConfigBinding(NoInlineTypeLiteralsConfig, 'no-inline-type-literals', NoInlineTypeLiteralsConfig.SCHEMA),\n new ConfigBinding(NoAnyUnknownConfig, 'no-any-unknown', NoAnyUnknownConfig.SCHEMA),\n new ConfigBinding(NoImplicitAnyConfig, 'no-implicit-any', NoImplicitAnyConfig.SCHEMA),\n new ConfigBinding(PrismaValidateDtosConfig, 'prisma-validate-dtos', PrismaValidateDtosConfig.SCHEMA),\n new ConfigBinding(PrismaConverterConfig, 'prisma-converter', PrismaConverterConfig.SCHEMA),\n new ConfigBinding(NoDestructureConfig, 'no-destructure', NoDestructureConfig.SCHEMA),\n new ConfigBinding(CatchErrorPatternConfig, 'catch-error-pattern', CatchErrorPatternConfig.SCHEMA),\n new ConfigBinding(NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions', NoUnmanagedExceptionsConfig.SCHEMA),\n new ConfigBinding(AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver', AngularNoDirectApiInResolverConfig.SCHEMA),\n new ConfigBinding(NoSymbolDiTokensConfig, 'no-symbol-di-tokens', NoSymbolDiTokensConfig.SCHEMA),\n new ConfigBinding(NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client', NoClientCreationOutsideServerOrClientConfig.SCHEMA),\n new ConfigBinding(NoCustomCssConfig, 'no-custom-css', NoCustomCssConfig.SCHEMA),\n new ConfigBinding(NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates', NoStatePathsInTemplatesConfig.SCHEMA),\n new ConfigBinding(NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main', NoProcessExitOutsideMainConfig.SCHEMA),\n new ConfigBinding(NoFunctionOutsideClassConfig, 'no-function-outside-class', NoFunctionOutsideClassConfig.SCHEMA),\n new ConfigBinding(InjectAnnotationNotNeededForConcreteClassConfig, 'inject-annotation-not-needed-for-concrete-class', InjectAnnotationNotNeededForConcreteClassConfig.SCHEMA),\n new ConfigBinding(FrameworkTagConfig, 'framework-tag', FrameworkTagConfig.SCHEMA),\n new ConfigBinding(RoleTagConfig, 'role-tag', RoleTagConfig.SCHEMA),\n new ConfigBinding(EnsureWeAreSecureConfig, 'ensure-we-are-secure', EnsureWeAreSecureConfig.SCHEMA),\n new ConfigBinding(NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib', NoInlineImportInApiLibConfig.SCHEMA),\n new ConfigBinding(OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib', OneEnumSpellingInApiLibConfig.SCHEMA),\n new ConfigBinding(NoUtilityTypesInApiLibConfig, 'no-utility-types-in-api-lib', NoUtilityTypesInApiLibConfig.SCHEMA),\n new ConfigBinding(RequiredTypeSuffixConfig, 'required-type-suffix', RequiredTypeSuffixConfig.SCHEMA),\n new ConfigBinding(FrameworkTsconfigConfig, 'framework-tsconfig', FrameworkTsconfigConfig.SCHEMA),\n new ConfigBinding(FrameworkPackagesConfig, 'framework-packages', FrameworkPackagesConfig.SCHEMA),\n];\n"]}
@@ -0,0 +1,40 @@
1
+ import { SchemaShape, BaseRuleConfig } from "@webpieces/rules-sdk";
2
+ import { ModifiedCodeMode } from "@webpieces/rules-sdk";
3
+ /**
4
+ * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`
5
+ * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`
6
+ * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library
7
+ * dependency from every reader of the contract and from the tools that read its imports.
8
+ *
9
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
10
+ * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
11
+ * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched
12
+ * project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). `allowedPaths` exempts whole trees. The per-site escape hatch is
13
+ * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
14
+ */
15
+ export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
16
+ mode?: ModifiedCodeMode;
17
+ allowedPaths?: string[];
18
+ static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig>;
19
+ }
20
+ /**
21
+ * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string
22
+ * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string
23
+ * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one
24
+ * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:
25
+ * a string-literal union of two or more members (in a type alias, a field or a parameter),
26
+ * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,
27
+ * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the
28
+ * wire).
29
+ *
30
+ * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
31
+ * mode grandfathers. This rule is what forbids NEW ones in an api library.
32
+ *
33
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
34
+ * values as above; `allowedPaths` and the per-site disable work the same way.
35
+ */
36
+ export declare class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {
37
+ mode?: ModifiedCodeMode;
38
+ allowedPaths?: string[];
39
+ static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig>;
40
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OneEnumSpellingInApiLibConfig = exports.NoInlineImportInApiLibConfig = void 0;
4
+ const rules_sdk_1 = require("@webpieces/rules-sdk");
5
+ const rules_sdk_2 = require("@webpieces/rules-sdk");
6
+ /**
7
+ * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`
8
+ * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`
9
+ * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library
10
+ * dependency from every reader of the contract and from the tools that read its imports.
11
+ *
12
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
13
+ * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
14
+ * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched
15
+ * project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). `allowedPaths` exempts whole trees. The per-site escape hatch is
16
+ * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
17
+ */
18
+ class NoInlineImportInApiLibConfig extends rules_sdk_1.BaseRuleConfig {
19
+ allowedPaths;
20
+ static SCHEMA = {
21
+ mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
22
+ allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
23
+ ...rules_sdk_1.BASE_RULE_SCHEMA,
24
+ };
25
+ }
26
+ exports.NoInlineImportInApiLibConfig = NoInlineImportInApiLibConfig;
27
+ /**
28
+ * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string
29
+ * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string
30
+ * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one
31
+ * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:
32
+ * a string-literal union of two or more members (in a type alias, a field or a parameter),
33
+ * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,
34
+ * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the
35
+ * wire).
36
+ *
37
+ * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
38
+ * mode grandfathers. This rule is what forbids NEW ones in an api library.
39
+ *
40
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
41
+ * values as above; `allowedPaths` and the per-site disable work the same way.
42
+ */
43
+ class OneEnumSpellingInApiLibConfig extends rules_sdk_1.BaseRuleConfig {
44
+ allowedPaths;
45
+ static SCHEMA = {
46
+ mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
47
+ allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
48
+ ...rules_sdk_1.BASE_RULE_SCHEMA,
49
+ };
50
+ }
51
+ exports.OneEnumSpellingInApiLibConfig = OneEnumSpellingInApiLibConfig;
52
+ //# sourceMappingURL=api-lib-spelling-configs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,oDAA+F;AAC/F,oDAA6E;AAC7E;;;;;;;;;;;GAWG;AACH,MAAa,4BAA6B,SAAQ,0BAAc;IAE5D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA8C;QAChE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,4BAAgB;KACtB,CAAC;;AARN,oEASC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,6BAA8B,SAAQ,0BAAc;IAE7D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,4BAAgB;KACtB,CAAC;;AARN,sEASC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig, BASE_RULE_SCHEMA } from \"@webpieces/rules-sdk\";\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from \"@webpieces/rules-sdk\";\n/**\n * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`\n * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`\n * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library\n * dependency from every reader of the contract and from the tools that read its imports.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |\n * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every\n * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in a touched\n * project / in the repo — #1027; count what is left with `wp-validate-code --rule=… --mode=RUN_EVERY_TIME`). `allowedPaths` exempts whole trees. The per-site escape hatch is\n * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.\n */\nexport class NoInlineImportInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n\n/**\n * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string\n * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string\n * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one\n * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:\n * a string-literal union of two or more members (in a type alias, a field or a parameter),\n * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,\n * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the\n * wire).\n *\n * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's\n * mode grandfathers. This rule is what forbids NEW ones in an api library.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three\n * values as above; `allowedPaths` and the per-site disable work the same way.\n */\nexport class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { SchemaShape, BaseRuleConfig } from "@webpieces/rules-sdk";
2
+ import { ModifiedCodeMode } from "@webpieces/rules-sdk";
3
+ export declare const CLIENT_CREATION_SEVERITIES: readonly ["warn", "error"];
4
+ export type ClientCreationSeverity = typeof CLIENT_CREATION_SEVERITIES[number];
5
+ export declare class NoClientCreationOutsideServerOrClientConfig extends BaseRuleConfig {
6
+ mode?: ModifiedCodeMode;
7
+ severity?: ClientCreationSeverity;
8
+ disableAllowed?: boolean;
9
+ allowedRoles?: string[];
10
+ allowedPaths?: string[];
11
+ static readonly SCHEMA: SchemaShape<NoClientCreationOutsideServerOrClientConfig>;
12
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoClientCreationOutsideServerOrClientConfig = exports.CLIENT_CREATION_SEVERITIES = void 0;
4
+ const rules_sdk_1 = require("@webpieces/rules-sdk");
5
+ const rules_sdk_2 = require("@webpieces/rules-sdk");
6
+ // no-client-creation-outside-server-or-client severity. Landed as a hard failure this rule would
7
+ // break every existing Angular repo on upgrade (provideCoreClient-style helpers create the client
8
+ // inside a role:lib on purpose), so it ships WARN — reports + prints the migration but passes the
9
+ // build — and a repo flips it to `error` once it has migrated its libraries.
10
+ exports.CLIENT_CREATION_SEVERITIES = ['warn', 'error'];
11
+ // no-client-creation-outside-server-or-client — flags a project that CONSTRUCTS an rpc/pubsub client
12
+ // (`factory.createRpcClient(...)` / `factory.createPubSubClient(...)`) when the project's `role:` tag
13
+ // is not one of `allowedRoles`. Only a runnable entrypoint (server / client app / app) has a declared
14
+ // identity (`serviceName`) or target (`callsService`), so a client built there is attributable in the
15
+ // runtime graph; a client built inside a `role:lib` reaches the fan-out fallback (one `uses` edge to
16
+ // EVERY implementer of the api) and draws calls that cannot happen. A reusable library takes the api
17
+ // INJECTED — the server/app module binds it to a client. Importing the api type or its DI token is
18
+ // FINE and never flagged; only constructing the transport is.
19
+ //
20
+ // `severity` ships "warn" (report + migration, build passes) so an upgrade can't break an un-migrated
21
+ // Angular repo; flip to "error" once libraries are migrated. `allowedRoles` defaults to the runnable
22
+ // roles; `allowedPaths` exempts whole file trees (shared glob semantics). Standard rollout knobs via
23
+ // the base: mode (OFF | NEW_AND_MODIFIED_CODE | NEW_AND_MODIFIED_FILES), turnOffRuleUntilEpoch,
24
+ // branch, and disableAllowed for the inline `// webpieces-disable` escape.
25
+ class NoClientCreationOutsideServerOrClientConfig extends rules_sdk_1.BaseRuleConfig {
26
+ severity;
27
+ disableAllowed;
28
+ allowedRoles;
29
+ allowedPaths;
30
+ static SCHEMA = {
31
+ mode: new rules_sdk_1.FieldDef('string', rules_sdk_2.MODIFIED_CODE_MODES),
32
+ severity: rules_sdk_1.FieldDef.optional('string', exports.CLIENT_CREATION_SEVERITIES),
33
+ disableAllowed: rules_sdk_1.FieldDef.optional('boolean'),
34
+ allowedRoles: rules_sdk_1.FieldDef.optional('string[]'),
35
+ allowedPaths: rules_sdk_1.FieldDef.optional('string[]'),
36
+ ...rules_sdk_1.BASE_RULE_SCHEMA,
37
+ };
38
+ }
39
+ exports.NoClientCreationOutsideServerOrClientConfig = NoClientCreationOutsideServerOrClientConfig;
40
+ //# sourceMappingURL=no-client-creation-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-client-creation-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/no-client-creation-config.ts"],"names":[],"mappings":";;;AAAA,oDAA+F;AAC/F,oDAA6E;AAC7E,iGAAiG;AACjG,kGAAkG;AAClG,kGAAkG;AAClG,6EAA6E;AAChE,QAAA,0BAA0B,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAIrE,qGAAqG;AACrG,sGAAsG;AACtG,sGAAsG;AACtG,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,mGAAmG;AACnG,8DAA8D;AAC9D,EAAE;AACF,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,gGAAgG;AAChG,2EAA2E;AAC3E,MAAa,2CAA4C,SAAQ,0BAAc;IAE3E,QAAQ,CAA0B;IAClC,cAAc,CAAW;IACzB,YAAY,CAAY;IACxB,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA6D;QAC/E,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,QAAQ,EAAE,oBAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,kCAA0B,CAAC;QACjE,cAAc,EAAE,oBAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC5C,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,4BAAgB;KACtB,CAAC;;AAdN,kGAeC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig, BASE_RULE_SCHEMA } from \"@webpieces/rules-sdk\";\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from \"@webpieces/rules-sdk\";\n// no-client-creation-outside-server-or-client severity. Landed as a hard failure this rule would\n// break every existing Angular repo on upgrade (provideCoreClient-style helpers create the client\n// inside a role:lib on purpose), so it ships WARN — reports + prints the migration but passes the\n// build — and a repo flips it to `error` once it has migrated its libraries.\nexport const CLIENT_CREATION_SEVERITIES = ['warn', 'error'] as const;\n\nexport type ClientCreationSeverity = typeof CLIENT_CREATION_SEVERITIES[number];\n\n// no-client-creation-outside-server-or-client — flags a project that CONSTRUCTS an rpc/pubsub client\n// (`factory.createRpcClient(...)` / `factory.createPubSubClient(...)`) when the project's `role:` tag\n// is not one of `allowedRoles`. Only a runnable entrypoint (server / client app / app) has a declared\n// identity (`serviceName`) or target (`callsService`), so a client built there is attributable in the\n// runtime graph; a client built inside a `role:lib` reaches the fan-out fallback (one `uses` edge to\n// EVERY implementer of the api) and draws calls that cannot happen. A reusable library takes the api\n// INJECTED — the server/app module binds it to a client. Importing the api type or its DI token is\n// FINE and never flagged; only constructing the transport is.\n//\n// `severity` ships \"warn\" (report + migration, build passes) so an upgrade can't break an un-migrated\n// Angular repo; flip to \"error\" once libraries are migrated. `allowedRoles` defaults to the runnable\n// roles; `allowedPaths` exempts whole file trees (shared glob semantics). Standard rollout knobs via\n// the base: mode (OFF | NEW_AND_MODIFIED_CODE | NEW_AND_MODIFIED_FILES), turnOffRuleUntilEpoch,\n// branch, and disableAllowed for the inline `// webpieces-disable` escape.\nexport class NoClientCreationOutsideServerOrClientConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n severity?: ClientCreationSeverity;\n disableAllowed?: boolean;\n allowedRoles?: string[];\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<NoClientCreationOutsideServerOrClientConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n severity: FieldDef.optional('string', CLIENT_CREATION_SEVERITIES),\n disableAllowed: FieldDef.optional('boolean'),\n allowedRoles: FieldDef.optional('string[]'),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}