@webpieces/code-rules 0.4.818 → 0.4.820

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 (84) hide show
  1. package/package.json +2 -2
  2. package/src/api-lib-source-rule.d.ts +5 -2
  3. package/src/api-lib-source-rule.js +8 -4
  4. package/src/api-lib-source-rule.js.map +1 -1
  5. package/src/cli.js +13 -14
  6. package/src/cli.js.map +1 -1
  7. package/src/code-rules-bootstrap.d.ts +31 -8
  8. package/src/code-rules-bootstrap.js +136 -18
  9. package/src/code-rules-bootstrap.js.map +1 -1
  10. package/src/code-rules-config-table.d.ts +3 -1
  11. package/src/code-rules-config-table.js +0 -6
  12. package/src/code-rules-config-table.js.map +1 -1
  13. package/src/code-rules-engine.d.ts +4 -13
  14. package/src/code-rules-engine.js +9 -31
  15. package/src/code-rules-engine.js.map +1 -1
  16. package/src/code-rules-run-request.d.ts +30 -34
  17. package/src/code-rules-run-request.js +43 -80
  18. package/src/code-rules-run-request.js.map +1 -1
  19. package/src/index.d.ts +4 -2
  20. package/src/index.js +14 -3
  21. package/src/index.js.map +1 -1
  22. package/src/scan-scope.d.ts +82 -0
  23. package/src/scan-scope.js +200 -0
  24. package/src/scan-scope.js.map +1 -0
  25. package/src/validate-catch-error-pattern.d.ts +3 -1
  26. package/src/validate-catch-error-pattern.js +11 -6
  27. package/src/validate-catch-error-pattern.js.map +1 -1
  28. package/src/validate-code.d.ts +4 -5
  29. package/src/validate-code.js +6 -17
  30. package/src/validate-code.js.map +1 -1
  31. package/src/validate-inject-annotation-not-needed-for-concrete-class.d.ts +3 -1
  32. package/src/validate-inject-annotation-not-needed-for-concrete-class.js +11 -6
  33. package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
  34. package/src/validate-match-rules.d.ts +3 -0
  35. package/src/validate-match-rules.js +10 -3
  36. package/src/validate-match-rules.js.map +1 -1
  37. package/src/validate-no-any-unknown.d.ts +3 -1
  38. package/src/validate-no-any-unknown.js +11 -6
  39. package/src/validate-no-any-unknown.js.map +1 -1
  40. package/src/validate-no-client-creation-outside-server-or-client.d.ts +4 -2
  41. package/src/validate-no-client-creation-outside-server-or-client.js +10 -5
  42. package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
  43. package/src/validate-no-custom-css.d.ts +4 -2
  44. package/src/validate-no-custom-css.js +9 -5
  45. package/src/validate-no-custom-css.js.map +1 -1
  46. package/src/validate-no-destructure.d.ts +3 -1
  47. package/src/validate-no-destructure.js +11 -6
  48. package/src/validate-no-destructure.js.map +1 -1
  49. package/src/validate-no-function-outside-class.d.ts +3 -1
  50. package/src/validate-no-function-outside-class.js +12 -6
  51. package/src/validate-no-function-outside-class.js.map +1 -1
  52. package/src/validate-no-implicit-any.d.ts +3 -1
  53. package/src/validate-no-implicit-any.js +13 -8
  54. package/src/validate-no-implicit-any.js.map +1 -1
  55. package/src/validate-no-inline-import-in-api-lib.d.ts +2 -1
  56. package/src/validate-no-inline-import-in-api-lib.js +4 -3
  57. package/src/validate-no-inline-import-in-api-lib.js.map +1 -1
  58. package/src/validate-no-process-exit-outside-main.d.ts +3 -1
  59. package/src/validate-no-process-exit-outside-main.js +12 -6
  60. package/src/validate-no-process-exit-outside-main.js.map +1 -1
  61. package/src/validate-no-state-paths-in-templates.d.ts +4 -2
  62. package/src/validate-no-state-paths-in-templates.js +9 -5
  63. package/src/validate-no-state-paths-in-templates.js.map +1 -1
  64. package/src/validate-no-symbol-di-tokens.d.ts +3 -1
  65. package/src/validate-no-symbol-di-tokens.js +11 -6
  66. package/src/validate-no-symbol-di-tokens.js.map +1 -1
  67. package/src/validate-no-unmanaged-exceptions.d.ts +3 -1
  68. package/src/validate-no-unmanaged-exceptions.js +11 -6
  69. package/src/validate-no-unmanaged-exceptions.js.map +1 -1
  70. package/src/validate-no-utility-types-in-api-lib.d.ts +2 -1
  71. package/src/validate-no-utility-types-in-api-lib.js +4 -3
  72. package/src/validate-no-utility-types-in-api-lib.js.map +1 -1
  73. package/src/validate-one-enum-spelling-in-api-lib.d.ts +2 -1
  74. package/src/validate-one-enum-spelling-in-api-lib.js +4 -3
  75. package/src/validate-one-enum-spelling-in-api-lib.js.map +1 -1
  76. package/src/validate-required-type-suffix.d.ts +13 -27
  77. package/src/validate-required-type-suffix.js +25 -52
  78. package/src/validate-required-type-suffix.js.map +1 -1
  79. package/src/debug-run-report.d.ts +0 -22
  80. package/src/debug-run-report.js +0 -127
  81. package/src/debug-run-report.js.map +0 -1
  82. package/src/rule-scope-plan.d.ts +0 -72
  83. package/src/rule-scope-plan.js +0 -132
  84. package/src/rule-scope-plan.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;AAEH,0DAMiC;AACjC,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAE9D,iEAAiE;AACjE,MAAa,UAAU;IAEN;IACA;IAEA;IAEA;IAEA;IARb,YACa,KAA8B,EAC9B,IAAY;IACrB,2EAA2E;IAClE,aAAqB;IAC9B,2CAA2C;IAClC,YAAoB;IAC7B,iEAAiE;IACxD,KAAa;QAPb,UAAK,GAAL,KAAK,CAAyB;QAC9B,SAAI,GAAJ,IAAI,CAAQ;QAEZ,kBAAa,GAAb,aAAa,CAAQ;QAErB,iBAAY,GAAZ,YAAY,CAAQ;QAEpB,UAAK,GAAL,KAAK,CAAQ;IACvB,CAAC;CACP;AAXD,gCAWC;AAED;;;;;GAKG;AACH,MAAa,iBAAiB;IAClB,MAAM,CAAU,IAAI,GAAG,WAAW,CAAC;IAE3C,QAAQ,CAAC,OAAe,EAAE,OAA2C;QACjE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC;IAChD,CAAC;IAED,4FAA4F;IAC5F,MAAM,CAAC,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EAA2B;sCAA3B,2BAA2B;IADvC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAKjB,uCAAwB,EAAgB,2CAAmB,EAAa,wBAAS;GAJ5F,2BAA2B,CA6BvC","sourcesContent":["/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with the suffixes allowed there:\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"] }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"] }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the MOST SPECIFIC entry governs a file ({@link SuffixEntryPicker}); suffixes are\n * never unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport {\n DiffScope,\n RULE_NAMES,\n RequiredTypeSuffixConfig,\n RequiredTypeSuffixEntry,\n matchesAnyGlob,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport * as ts from 'typescript';\nimport { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';\nimport { ProjectRoleResolver } from './project-role-resolver';\n\n/** One glob of one entry, with how specific it is. Data-only. */\nexport class RankedGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n /** Characters before the first glob metacharacter (`*`, `?`, `[`, `{`). */\n readonly literalPrefix: number,\n /** Every non-metacharacter in the glob. */\n readonly literalChars: number,\n /** Position of the entry in the config — the final tie-break. */\n readonly order: number,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file. Among the entries with a glob matching the file, the one whose\n * matching glob has the longest LITERAL PREFIX (the characters before its first `*`, `?`, `[` or `{`)\n * wins; a tie goes to the glob with more literal characters overall, then to the entry listed first. So\n * `libraries/apis/internal/**` beats `libraries/apis/**` whatever order they are listed in.\n */\nexport class SuffixEntryPicker {\n private static readonly META = /[*?[\\]{}]/;\n\n entryFor(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The winning glob (and its entry) for `relFile`, or undefined when no entry covers it. */\n winner(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): RankedGlob | undefined {\n let best: RankedGlob | undefined;\n entries.forEach((entry: RequiredTypeSuffixEntry, order: number) => {\n for (const glob of entry.paths) {\n if (!matchesAnyGlob(relFile, [glob])) continue;\n const ranked = this.rank(entry, glob, order);\n if (best === undefined || this.beats(ranked, best)) best = ranked;\n }\n });\n return best;\n }\n\n private rank(entry: RequiredTypeSuffixEntry, glob: string, order: number): RankedGlob {\n const firstMeta = glob.search(SuffixEntryPicker.META);\n const literalPrefix = firstMeta === -1 ? glob.length : firstMeta;\n const literalChars = glob.replace(/[*?[\\]{}]/g, '').length;\n return new RankedGlob(entry, glob, literalPrefix, literalChars, order);\n }\n\n private beats(a: RankedGlob, b: RankedGlob): boolean {\n if (a.literalPrefix !== b.literalPrefix) return a.literalPrefix > b.literalPrefix;\n if (a.literalChars !== b.literalChars) return a.literalChars > b.literalChars;\n return a.order < b.order;\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface', 'Payload', 'Options', 'Object', 'Params', 'Output', 'Option', 'Record', 'Input', 'Model',\n 'Entry', 'Shape', 'Data', 'Info', 'Item', 'Type', 'Body', 'Row', 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find((s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()));\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find((t: string) => name.length > t.length && name.endsWith(t));\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(file, declared, declared.name, declared.name?.getText(file.source) ?? '', entry, glob);\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined) continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause)) continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get((element.propertyName ?? element.name).getText(file.source));\n if (local === undefined) continue;\n const site = this.judge(file, local, element.name, element.name.getText(file.source), entry, glob);\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) || ts.isClassDeclaration(statement)) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (entry.suffixes.some((suffix: string) => name.length > suffix.length && name.endsWith(suffix))) return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name).replace(/\\s+/g, ' ').trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates.slice(1).map((c: string) => `\\`${c}\\``).join(' / ');\n const cure = `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === '' ? '' : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(config: RequiredTypeSuffixConfig, roleResolver: ProjectRoleResolver, diffScope: DiffScope) {\n super(config, RULE_NAMES.REQUIRED_TYPE_SUFFIX, roleResolver, diffScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return 'every exported interface / class / enum / type there must end in one of its path\\'s allowed suffixes — ' +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.';\n }\n}\n"]}
1
+ {"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";AAAA;;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CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrE,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,yEAAyE;IACtD,kBAAkB,CAAC,cAAsB,EAAE,OAAe;QACzE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;IAC5E,CAAC;IAEkB,UAAU;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3F,OAAO,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,GAAG;QACT,OAAO,yGAAyG;YAC5G,uGAAuG;YACvG,yFAAyF,CAAC;IAClG,CAAC;CACJ,CAAA;AAlCY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAMzB,uCAAwB;QAClB,2CAAmB;QACtB,wBAAS;QACT,sBAAS;GARf,2BAA2B,CAkCvC","sourcesContent":["/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with the suffixes allowed there:\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"] }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"] }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the FIRST entry in config order whose paths match governs a file\n * ({@link SuffixEntryPicker}), so a narrower entry must be listed before a broader one; suffixes are never\n * unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport {\n DiffScope,\n RULE_NAMES,\n RequiredTypeSuffixConfig,\n RequiredTypeSuffixEntry,\n matchesAnyGlob,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport * as ts from 'typescript';\nimport { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The entry that governs a file, and the glob of it that matched — named in every failure. Data-only. */\nexport class GoverningGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file: the FIRST entry, in config order, with a glob matching the\n * file. Order matters — to give a narrower directory stricter suffixes, list its entry ABOVE the broader\n * one; listed below, it never applies to the files the broader entry already covers.\n */\nexport class SuffixEntryPicker {\n entryFor(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */\n winner(relFile: string, entries: readonly RequiredTypeSuffixEntry[]): GoverningGlob | undefined {\n for (const entry of entries) {\n const glob = entry.paths.find((g: string) => matchesAnyGlob(relFile, [g]));\n if (glob !== undefined) return new GoverningGlob(entry, glob);\n }\n return undefined;\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface', 'Payload', 'Options', 'Object', 'Params', 'Output', 'Option', 'Record', 'Input', 'Model',\n 'Entry', 'Shape', 'Data', 'Info', 'Item', 'Type', 'Body', 'Row', 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find((s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()));\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find((t: string) => name.length > t.length && name.endsWith(t));\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(file, declared, declared.name, declared.name?.getText(file.source) ?? '', entry, glob);\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined) continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause)) continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get((element.propertyName ?? element.name).getText(file.source));\n if (local === undefined) continue;\n const site = this.judge(file, local, element.name, element.name.getText(file.source), entry, glob);\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) || ts.isClassDeclaration(statement)) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (entry.suffixes.some((suffix: string) => name.length > suffix.length && name.endsWith(suffix))) return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name).replace(/\\s+/g, ' ').trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates.slice(1).map((c: string) => `\\`${c}\\``).join(' / ');\n const cure = `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === '' ? '' : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(\n config: RequiredTypeSuffixConfig,\n roleResolver: ProjectRoleResolver,\n diffScope: DiffScope,\n scanScope: ScanScope,\n ) {\n super(config, RULE_NAMES.REQUIRED_TYPE_SUFFIX, roleResolver, diffScope, scanScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return 'every exported interface / class / enum / type there must end in one of its path\\'s allowed suffixes — ' +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.';\n }\n}\n"]}
@@ -1,22 +0,0 @@
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
- }
@@ -1,127 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DebugRunReport = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs = tslib_1.__importStar(require("fs"));
6
- const path = tslib_1.__importStar(require("path"));
7
- const rules_config_1 = require("@webpieces/rules-config");
8
- const inversify_1 = require("inversify");
9
- const rule_reporter_1 = require("./rule-reporter");
10
- /** One site a rule printed: a file inside a project, and the line when the rule named one. Data-only. */
11
- class PrintedSite {
12
- relFile;
13
- line;
14
- projectRoot;
15
- constructor(relFile, line, projectRoot) {
16
- this.relFile = relFile;
17
- this.line = line;
18
- this.projectRoot = projectRoot;
19
- }
20
- }
21
- /**
22
- * Runs a DEBUG run (#1027): one rule, labelled as not the gate, its own failure text printed exactly as
23
- * the build prints it, then a count of sites per project. Nothing is written to webpieces.config.json.
24
- *
25
- * The count is taken from what the rule PRINTED — every `path` / `path:line` it named that is a file in
26
- * a project — rather than from each rule's internals, because the rules report through one renderer
27
- * but hold their sites in thirty different shapes. A site named twice (in the message and in a cure)
28
- * counts once. A passing run has no sites by definition, whatever file names it logged on the way.
29
- */
30
- let DebugRunReport = class DebugRunReport {
31
- reporter;
32
- constructor(reporter) {
33
- this.reporter = reporter;
34
- }
35
- async run(workspaceRoot, runs, target) {
36
- this.printBanner(target);
37
- const captured = [];
38
- const result = await this.capture(captured, () => this.reporter.runValidators(runs));
39
- const sites = result.success ? [] : this.sitesIn(workspaceRoot, captured.join('\n'));
40
- this.printCounts(workspaceRoot, target, sites);
41
- return { success: result.success };
42
- }
43
- printBanner(target) {
44
- const projects = target.projectNames === null ? 'every project' : target.projectNames.join(', ');
45
- console.log('');
46
- console.log('🔬 DEBUG RUN — not the gate. Nothing on disk changes; the build keeps judging the committed mode.');
47
- console.log(` rule: ${target.rule}`);
48
- console.log(` mode: ${target.mode}${target.mode === target.committedMode ? ' (committed)' : ` (committed: ${target.committedMode})`}`);
49
- console.log(` projects: ${projects}`);
50
- console.log(' turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch are ignored for this run.');
51
- console.log('');
52
- }
53
- // Tee console output: it still reaches the terminal, and the report reads it back afterwards.
54
- async capture(into, work) {
55
- const originals = [console.log, console.error, console.warn];
56
- const tee = (original) => (...args) => {
57
- into.push(args.map(String).join(' '));
58
- original(...args);
59
- };
60
- console.log = tee(originals[0]);
61
- console.error = tee(originals[1]);
62
- console.warn = tee(originals[2]);
63
- // webpieces-disable no-unmanaged-exceptions -- restores the console on every path; the reporter already isolates rule failures
64
- try {
65
- return await work();
66
- }
67
- finally {
68
- console.log = originals[0];
69
- console.error = originals[1];
70
- console.warn = originals[2];
71
- }
72
- }
73
- sitesIn(workspaceRoot, text) {
74
- const projects = new rules_config_1.ProjectIndex(workspaceRoot);
75
- const byKey = new Map();
76
- for (const raw of text.split(/\s+/)) {
77
- const site = this.siteOf(workspaceRoot, raw, projects);
78
- if (site !== null)
79
- byKey.set(`${site.relFile}:${site.line ?? ''}`, site);
80
- }
81
- const lined = new Set(Array.from(byKey.values()).filter((s) => s.line !== null).map((s) => s.relFile));
82
- return Array.from(byKey.values()).filter((s) => s.line !== null || !lined.has(s.relFile));
83
- }
84
- siteOf(workspaceRoot, raw, projects) {
85
- const token = raw.replace(/^[^\w./@-]+/, '').replace(/[^\w/]+$/, '');
86
- const match = /^(.+?\.[A-Za-z0-9]+)(?::(\d+))?(?::\d+)?$/.exec(token);
87
- if (match === null)
88
- return null;
89
- const prefix = workspaceRoot.endsWith('/') ? workspaceRoot : `${workspaceRoot}/`;
90
- const relFile = match[1].startsWith(prefix) ? match[1].slice(prefix.length) : match[1];
91
- if (path.isAbsolute(relFile) || !fs.existsSync(path.join(workspaceRoot, relFile)))
92
- return null;
93
- const projectRoot = projects.rootOf(relFile);
94
- if (projectRoot === null)
95
- return null;
96
- return new PrintedSite(relFile, match[2] ?? null, projectRoot);
97
- }
98
- printCounts(workspaceRoot, target, sites) {
99
- const projects = new rules_config_1.ProjectIndex(workspaceRoot);
100
- const counts = new Map();
101
- for (const root of target.projectRoots ?? [])
102
- counts.set(root, 0);
103
- for (const site of sites) {
104
- if (target.projectRoots !== null && !counts.has(site.projectRoot))
105
- continue;
106
- counts.set(site.projectRoot, (counts.get(site.projectRoot) ?? 0) + 1);
107
- }
108
- const names = new Map();
109
- for (const root of counts.keys())
110
- names.set(root, projects.nameOf(root));
111
- const total = Array.from(counts.values()).reduce((a, b) => a + b, 0);
112
- const width = Math.max(5, ...Array.from(names.values()).map((n) => n.length));
113
- console.log('');
114
- console.log(`🔬 DEBUG RUN — ${target.rule} @ ${target.mode}: sites per project`);
115
- for (const root of counts.keys()) {
116
- console.log(` ${(names.get(root) ?? root).padEnd(width)} ${counts.get(root) ?? 0}`);
117
- }
118
- console.log(` ${'TOTAL'.padEnd(width)} ${total}`);
119
- console.log('');
120
- }
121
- };
122
- exports.DebugRunReport = DebugRunReport;
123
- exports.DebugRunReport = DebugRunReport = tslib_1.__decorate([
124
- (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
125
- tslib_1.__metadata("design:paramtypes", [rule_reporter_1.RuleReporter])
126
- ], DebugRunReport);
127
- //# sourceMappingURL=debug-run-report.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug-run-report.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/debug-run-report.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAuD;AACvD,yCAA2D;AAI3D,mDAA+C;AAM/C,yGAAyG;AACzG,MAAM,WAAW;IAEA;IACA;IACA;IAHb,YACa,OAAe,EACf,IAAmB,EACnB,WAAmB;QAFnB,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAe;QACnB,gBAAW,GAAX,WAAW,CAAQ;IAC7B,CAAC;CACP;AAED;;;;;;;;GAQG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IACM;IAA7B,YAA6B,QAAsB;QAAtB,aAAQ,GAAR,QAAQ,CAAc;IAAG,CAAC;IAEvD,KAAK,CAAC,GAAG,CAAC,aAAqB,EAAE,IAAwB,EAAE,MAAmB;QAC1E,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACrF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrF,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,M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AAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACtF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,MAAM,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,qBAAqB,CAAC,CAAC;QACjF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpB,CAAC;CACJ,CAAA;AAtFY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEE,4BAAY;GAD1C,cAAc,CAsF1B","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { ProjectIndex } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { ExecutorResult, RuleRun } from './code-validator';\nimport { DebugTarget } from './rule-scope-plan';\nimport { RuleReporter } from './rule-reporter';\n\n/** The shape of console.log / console.error / console.warn. */\n// webpieces-disable no-any-unknown -- console methods take any printable values\ntype ConsoleFn = (...args: unknown[]) => void;\n\n/** One site a rule printed: a file inside a project, and the line when the rule named one. Data-only. */\nclass PrintedSite {\n constructor(\n readonly relFile: string,\n readonly line: string | null,\n readonly projectRoot: string,\n ) {}\n}\n\n/**\n * Runs a DEBUG run (#1027): one rule, labelled as not the gate, its own failure text printed exactly as\n * the build prints it, then a count of sites per project. Nothing is written to webpieces.config.json.\n *\n * The count is taken from what the rule PRINTED — every `path` / `path:line` it named that is a file in\n * a project — rather than from each rule's internals, because the rules report through one renderer\n * but hold their sites in thirty different shapes. A site named twice (in the message and in a cure)\n * counts once. A passing run has no sites by definition, whatever file names it logged on the way.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DebugRunReport {\n constructor(private readonly reporter: RuleReporter) {}\n\n async run(workspaceRoot: string, runs: readonly RuleRun[], target: DebugTarget): Promise<ExecutorResult> {\n this.printBanner(target);\n const captured: string[] = [];\n const result = await this.capture(captured, () => this.reporter.runValidators(runs));\n const sites = result.success ? [] : this.sitesIn(workspaceRoot, captured.join('\\n'));\n this.printCounts(workspaceRoot, target, sites);\n return { success: result.success };\n }\n\n private printBanner(target: DebugTarget): void {\n const projects = target.projectNames === null ? 'every project' : target.projectNames.join(', ');\n console.log('');\n console.log('🔬 DEBUG RUN — not the gate. Nothing on disk changes; the build keeps judging the committed mode.');\n console.log(` rule: ${target.rule}`);\n console.log(` mode: ${target.mode}${target.mode === target.committedMode ? ' (committed)' : ` (committed: ${target.committedMode})`}`);\n console.log(` projects: ${projects}`);\n console.log(' turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch are ignored for this run.');\n console.log('');\n }\n\n // Tee console output: it still reaches the terminal, and the report reads it back afterwards.\n private async capture(into: string[], work: () => Promise<ExecutorResult>): Promise<ExecutorResult> {\n const originals: ConsoleFn[] = [console.log, console.error, console.warn];\n const tee = (original: ConsoleFn): ConsoleFn => (...args: Parameters<ConsoleFn>): void => {\n into.push(args.map(String).join(' '));\n original(...args);\n };\n console.log = tee(originals[0]);\n console.error = tee(originals[1]);\n console.warn = tee(originals[2]);\n // webpieces-disable no-unmanaged-exceptions -- restores the console on every path; the reporter already isolates rule failures\n try {\n return await work();\n } finally {\n console.log = originals[0];\n console.error = originals[1];\n console.warn = originals[2];\n }\n }\n\n private sitesIn(workspaceRoot: string, text: string): PrintedSite[] {\n const projects = new ProjectIndex(workspaceRoot);\n const byKey = new Map<string, PrintedSite>();\n for (const raw of text.split(/\\s+/)) {\n const site = this.siteOf(workspaceRoot, raw, projects);\n if (site !== null) byKey.set(`${site.relFile}:${site.line ?? ''}`, site);\n }\n const lined = new Set(Array.from(byKey.values()).filter((s: PrintedSite) => s.line !== null).map((s: PrintedSite) => s.relFile));\n return Array.from(byKey.values()).filter((s: PrintedSite) => s.line !== null || !lined.has(s.relFile));\n }\n\n private siteOf(workspaceRoot: string, raw: string, projects: ProjectIndex): PrintedSite | null {\n const token = raw.replace(/^[^\\w./@-]+/, '').replace(/[^\\w/]+$/, '');\n const match = /^(.+?\\.[A-Za-z0-9]+)(?::(\\d+))?(?::\\d+)?$/.exec(token);\n if (match === null) return null;\n const prefix = workspaceRoot.endsWith('/') ? workspaceRoot : `${workspaceRoot}/`;\n const relFile = match[1].startsWith(prefix) ? match[1].slice(prefix.length) : match[1];\n if (path.isAbsolute(relFile) || !fs.existsSync(path.join(workspaceRoot, relFile))) return null;\n const projectRoot = projects.rootOf(relFile);\n if (projectRoot === null) return null;\n return new PrintedSite(relFile, match[2] ?? null, projectRoot);\n }\n\n private printCounts(workspaceRoot: string, target: DebugTarget, sites: readonly PrintedSite[]): void {\n const projects = new ProjectIndex(workspaceRoot);\n const counts = new Map<string, number>();\n for (const root of target.projectRoots ?? []) counts.set(root, 0);\n for (const site of sites) {\n if (target.projectRoots !== null && !counts.has(site.projectRoot)) continue;\n counts.set(site.projectRoot, (counts.get(site.projectRoot) ?? 0) + 1);\n }\n const names = new Map<string, string>();\n for (const root of counts.keys()) names.set(root, projects.nameOf(root));\n const total = Array.from(counts.values()).reduce((a: number, b: number) => a + b, 0);\n const width = Math.max(5, ...Array.from(names.values()).map((n: string) => n.length));\n console.log('');\n console.log(`🔬 DEBUG RUN — ${target.rule} @ ${target.mode}: sites per project`);\n for (const root of counts.keys()) {\n console.log(` ${(names.get(root) ?? root).padEnd(width)} ${counts.get(root) ?? 0}`);\n }\n console.log(` ${'TOTAL'.padEnd(width)} ${total}`);\n console.log('');\n }\n}\n"]}
@@ -1,72 +0,0 @@
1
- import { BaseRuleConfig, FileScope } from '@webpieces/rules-config';
2
- import { CodeRulesRunRequest } from './code-rules-run-request';
3
- /** What a debug run is judging, for its banner and its per-project report. Data-only. */
4
- export declare class DebugTarget {
5
- readonly rule: string;
6
- /** The mode webpieces.config.json commits the rule to. */
7
- readonly committedMode: string;
8
- /** The mode this run judges at (`--mode`, else the committed one). */
9
- readonly mode: string;
10
- /** `--projects` as given, or null for every project. */
11
- readonly projectNames: readonly string[] | null;
12
- /** Their repo-relative roots, in the same order, or null. */
13
- readonly projectRoots: readonly string[] | null;
14
- constructor(rule: string,
15
- /** The mode webpieces.config.json commits the rule to. */
16
- committedMode: string,
17
- /** The mode this run judges at (`--mode`, else the committed one). */
18
- mode: string,
19
- /** `--projects` as given, or null for every project. */
20
- projectNames: readonly string[] | null,
21
- /** Their repo-relative roots, in the same order, or null. */
22
- projectRoots: readonly string[] | null);
23
- }
24
- /**
25
- * The {@link FileScope} each rule runs inside, keyed by config key (a match-rule by its name), plus the
26
- * debug target when this is a debug run. Bound at the composition root; the engine wraps each rule's
27
- * run in `diffScope.within(scopes.of(key), …)`. A rule with no entry runs in today's plain diff scope.
28
- */
29
- export declare class RuleScopes {
30
- private readonly byKey;
31
- readonly debugTarget: DebugTarget | null;
32
- constructor(byKey: ReadonlyMap<string, FileScope>, debugTarget: DebugTarget | null);
33
- of(key: string): FileScope;
34
- }
35
- /**
36
- * Composition-time planner: turns each rule's COMMITTED config (plus a debug request) into the config
37
- * the rule actually runs with and the {@link FileScope} it runs inside. This is the one place the
38
- * whole-scope modes of #1027 are applied to a rule, for every rule at once:
39
- *
40
- * - a DIFF-scoped rule whose mode is MODIFIED_PROJECTS / RUN_EVERY_TIME runs with its most-whole
41
- * per-file mode (e.g. NEW_AND_MODIFIED_FILES) inside a widened FileScope — so the rule's own code
42
- * never has to know the two modes exist;
43
- * - a rule whose mode set has no diff-scoped mode (PROJECT_MODES) keeps its mode untouched — its own
44
- * MODIFIED_PROJECTS is its native behaviour, not a widening;
45
- * - the debug target additionally takes `--mode`, is restricted to `--projects`, and ignores the two
46
- * escape hatches for this run (it is a measurement, not the gate).
47
- *
48
- * The committed config object is never mutated: a rule that needs a different mode gets a copy.
49
- */
50
- export declare class RuleScopePlanner {
51
- private readonly request;
52
- private readonly projectRoots;
53
- /**
54
- * The one rule whose NEW_AND_MODIFIED_FILES is NOT a whole-file judgement, so the generic choice
55
- * (WholeScopeModes.wholeFileJudgeMode) would silently judge less than the whole file. max-method-lines at
56
- * NEW_AND_MODIFIED_FILES runs only its modified-methods sub-check, which leaves every NEW method to
57
- * the new-methods sub-check — and inside a whole scope every method reads as new. Its
58
- * NEW_AND_MODIFIED_METHODS runs both sub-checks, which is the whole file. Pinned by
59
- * whole-scope-modes.spec.ts, which fails if this entry is removed.
60
- */
61
- private static readonly WHOLE_FILE_JUDGE_OVERRIDES;
62
- private readonly scopes;
63
- private readonly wholeScope;
64
- private target;
65
- constructor(request: CodeRulesRunRequest, projectRoots: readonly string[] | null);
66
- /** The config `key`'s rule runs with. `modeSet` is the modes its schema accepts. */
67
- plan<C extends BaseRuleConfig>(key: string, config: C, modeSet: readonly string[]): C;
68
- /** The scopes planned so far. Throws when a debug run named a rule no `plan` call saw. */
69
- result(): RuleScopes;
70
- private judgeModeFor;
71
- private targetMode;
72
- }
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuleScopePlanner = exports.RuleScopes = exports.DebugTarget = void 0;
4
- const rules_config_1 = require("@webpieces/rules-config");
5
- /** What a debug run is judging, for its banner and its per-project report. Data-only. */
6
- class DebugTarget {
7
- rule;
8
- committedMode;
9
- mode;
10
- projectNames;
11
- projectRoots;
12
- constructor(rule,
13
- /** The mode webpieces.config.json commits the rule to. */
14
- committedMode,
15
- /** The mode this run judges at (`--mode`, else the committed one). */
16
- mode,
17
- /** `--projects` as given, or null for every project. */
18
- projectNames,
19
- /** Their repo-relative roots, in the same order, or null. */
20
- projectRoots) {
21
- this.rule = rule;
22
- this.committedMode = committedMode;
23
- this.mode = mode;
24
- this.projectNames = projectNames;
25
- this.projectRoots = projectRoots;
26
- }
27
- }
28
- exports.DebugTarget = DebugTarget;
29
- /**
30
- * The {@link FileScope} each rule runs inside, keyed by config key (a match-rule by its name), plus the
31
- * debug target when this is a debug run. Bound at the composition root; the engine wraps each rule's
32
- * run in `diffScope.within(scopes.of(key), …)`. A rule with no entry runs in today's plain diff scope.
33
- */
34
- class RuleScopes {
35
- byKey;
36
- debugTarget;
37
- constructor(byKey, debugTarget) {
38
- this.byKey = byKey;
39
- this.debugTarget = debugTarget;
40
- }
41
- of(key) {
42
- return this.byKey.get(key) ?? rules_config_1.FileScope.DIFF;
43
- }
44
- }
45
- exports.RuleScopes = RuleScopes;
46
- /**
47
- * Composition-time planner: turns each rule's COMMITTED config (plus a debug request) into the config
48
- * the rule actually runs with and the {@link FileScope} it runs inside. This is the one place the
49
- * whole-scope modes of #1027 are applied to a rule, for every rule at once:
50
- *
51
- * - a DIFF-scoped rule whose mode is MODIFIED_PROJECTS / RUN_EVERY_TIME runs with its most-whole
52
- * per-file mode (e.g. NEW_AND_MODIFIED_FILES) inside a widened FileScope — so the rule's own code
53
- * never has to know the two modes exist;
54
- * - a rule whose mode set has no diff-scoped mode (PROJECT_MODES) keeps its mode untouched — its own
55
- * MODIFIED_PROJECTS is its native behaviour, not a widening;
56
- * - the debug target additionally takes `--mode`, is restricted to `--projects`, and ignores the two
57
- * escape hatches for this run (it is a measurement, not the gate).
58
- *
59
- * The committed config object is never mutated: a rule that needs a different mode gets a copy.
60
- */
61
- class RuleScopePlanner {
62
- request;
63
- projectRoots;
64
- /**
65
- * The one rule whose NEW_AND_MODIFIED_FILES is NOT a whole-file judgement, so the generic choice
66
- * (WholeScopeModes.wholeFileJudgeMode) would silently judge less than the whole file. max-method-lines at
67
- * NEW_AND_MODIFIED_FILES runs only its modified-methods sub-check, which leaves every NEW method to
68
- * the new-methods sub-check — and inside a whole scope every method reads as new. Its
69
- * NEW_AND_MODIFIED_METHODS runs both sub-checks, which is the whole file. Pinned by
70
- * whole-scope-modes.spec.ts, which fails if this entry is removed.
71
- */
72
- static WHOLE_FILE_JUDGE_OVERRIDES = new Map([
73
- ['max-method-lines', 'NEW_AND_MODIFIED_METHODS'],
74
- ]);
75
- scopes = new Map();
76
- wholeScope = new rules_config_1.WholeScopeModes();
77
- target = null;
78
- constructor(request, projectRoots) {
79
- this.request = request;
80
- this.projectRoots = projectRoots;
81
- }
82
- /** The config `key`'s rule runs with. `modeSet` is the modes its schema accepts. */
83
- plan(key, config, modeSet) {
84
- const isTarget = this.request.rule === key;
85
- const committed = config.mode ?? 'OFF';
86
- const mode = isTarget ? this.targetMode(key, committed, modeSet) : committed;
87
- const judge = this.wholeScope.isWholeScopeMode(mode) ? this.judgeModeFor(key, modeSet) : null;
88
- const kind = judge !== null && this.wholeScope.isWholeScopeMode(mode) ? mode : 'DIFF';
89
- const scope = new rules_config_1.FileScope(kind, isTarget ? this.projectRoots : null);
90
- if (!scope.isPlainDiff())
91
- this.scopes.set(key, scope);
92
- if (isTarget) {
93
- this.target = new DebugTarget(key, committed, mode, this.request.projects, this.projectRoots);
94
- }
95
- if (judge === null && !isTarget)
96
- return config;
97
- const copy = Object.assign(Object.create(Object.getPrototypeOf(config)), config);
98
- const base = copy;
99
- base.mode = judge ?? mode;
100
- if (isTarget) {
101
- base.turnOffRuleUntilEpoch = 0;
102
- base.turnOffRuleWhileOnBranch = null;
103
- }
104
- return copy;
105
- }
106
- /** The scopes planned so far. Throws when a debug run named a rule no `plan` call saw. */
107
- result() {
108
- const rule = this.request.rule;
109
- if (rule !== null && this.target === null) {
110
- throw new rules_config_1.InformAiError(`--rule=${rule} names no code rule and no match-rule in webpieces.config.json. A debug run judges ` +
111
- `a rule @webpieces/code-rules runs at build time (the keys under "rules", or a "match-rules" name).`);
112
- }
113
- return new RuleScopes(this.scopes, this.target);
114
- }
115
- judgeModeFor(key, modeSet) {
116
- const generic = this.wholeScope.wholeFileJudgeMode(modeSet);
117
- return generic === null ? null : (RuleScopePlanner.WHOLE_FILE_JUDGE_OVERRIDES.get(key) ?? generic);
118
- }
119
- targetMode(key, committed, modeSet) {
120
- const mode = this.request.mode ?? committed;
121
- if (this.request.mode !== null && !modeSet.includes(mode)) {
122
- throw new rules_config_1.InformAiError(`--mode=${mode} is not a mode of ${key}. Its modes: ${modeSet.join(', ')}.`);
123
- }
124
- if (mode === 'OFF') {
125
- throw new rules_config_1.InformAiError(`${key} is "mode": "OFF" in webpieces.config.json, so a debug run at the committed mode judges ` +
126
- `nothing. Pass --mode=<MODE> to judge it at another mode for this run: ${modeSet.filter((m) => m !== 'OFF').join(', ')}.`);
127
- }
128
- return mode;
129
- }
130
- }
131
- exports.RuleScopePlanner = RuleScopePlanner;
132
- //# sourceMappingURL=rule-scope-plan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-scope-plan.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-scope-plan.ts"],"names":[],"mappings":";;;AAAA,0DAAmH;AAInH,yFAAyF;AACzF,MAAa,WAAW;IAEP;IAEA;IAEA;IAEA;IAEA;IATb,YACa,IAAY;IACrB,0DAA0D;IACjD,aAAqB;IAC9B,sEAAsE;IAC7D,IAAY;IACrB,wDAAwD;IAC/C,YAAsC;IAC/C,6DAA6D;IACpD,YAAsC;QARtC,SAAI,GAAJ,IAAI,CAAQ;QAEZ,kBAAa,GAAb,aAAa,CAAQ;QAErB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,iBAAY,GAAZ,YAAY,CAA0B;QAEtC,iBAAY,GAAZ,YAAY,CAA0B;IAChD,CAAC;CACP;AAZD,kCAYC;AAED;;;;GAIG;AACH,MAAa,UAAU;IAEE;IACR;IAFb,YACqB,KAAqC,EAC7C,WAA+B;QADvB,UAAK,GAAL,KAAK,CAAgC;Q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AAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,YAAY,CAAC,GAAW,EAAE,OAA0B;QACxD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC5D,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,0BAA0B,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;IACvG,CAAC;IAEO,UAAU,CAAC,GAAW,EAAE,SAAiB,EAAE,OAA0B;QACzE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;QAC5C,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,4BAAa,CACnB,UAAU,IAAI,qBAAqB,GAAG,gBAAgB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC9E,CAAC;QACN,CAAC;QACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACjB,MAAM,IAAI,4BAAa,CACnB,GAAG,GAAG,0FAA0F;gBAC5F,yEAAyE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACxI,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;;AA5EL,4CA6EC","sourcesContent":["import { BaseRuleConfig, FileScope, FileScopeKind, InformAiError, WholeScopeModes } from '@webpieces/rules-config';\n\nimport { CodeRulesRunRequest } from './code-rules-run-request';\n\n/** What a debug run is judging, for its banner and its per-project report. Data-only. */\nexport class DebugTarget {\n constructor(\n readonly rule: string,\n /** The mode webpieces.config.json commits the rule to. */\n readonly committedMode: string,\n /** The mode this run judges at (`--mode`, else the committed one). */\n readonly mode: string,\n /** `--projects` as given, or null for every project. */\n readonly projectNames: readonly string[] | null,\n /** Their repo-relative roots, in the same order, or null. */\n readonly projectRoots: readonly string[] | null,\n ) {}\n}\n\n/**\n * The {@link FileScope} each rule runs inside, keyed by config key (a match-rule by its name), plus the\n * debug target when this is a debug run. Bound at the composition root; the engine wraps each rule's\n * run in `diffScope.within(scopes.of(key), …)`. A rule with no entry runs in today's plain diff scope.\n */\nexport class RuleScopes {\n constructor(\n private readonly byKey: ReadonlyMap<string, FileScope>,\n readonly debugTarget: DebugTarget | null,\n ) {}\n\n of(key: string): FileScope {\n return this.byKey.get(key) ?? FileScope.DIFF;\n }\n}\n\n/**\n * Composition-time planner: turns each rule's COMMITTED config (plus a debug request) into the config\n * the rule actually runs with and the {@link FileScope} it runs inside. This is the one place the\n * whole-scope modes of #1027 are applied to a rule, for every rule at once:\n *\n * - a DIFF-scoped rule whose mode is MODIFIED_PROJECTS / RUN_EVERY_TIME runs with its most-whole\n * per-file mode (e.g. NEW_AND_MODIFIED_FILES) inside a widened FileScope — so the rule's own code\n * never has to know the two modes exist;\n * - a rule whose mode set has no diff-scoped mode (PROJECT_MODES) keeps its mode untouched — its own\n * MODIFIED_PROJECTS is its native behaviour, not a widening;\n * - the debug target additionally takes `--mode`, is restricted to `--projects`, and ignores the two\n * escape hatches for this run (it is a measurement, not the gate).\n *\n * The committed config object is never mutated: a rule that needs a different mode gets a copy.\n */\nexport class RuleScopePlanner {\n /**\n * The one rule whose NEW_AND_MODIFIED_FILES is NOT a whole-file judgement, so the generic choice\n * (WholeScopeModes.wholeFileJudgeMode) would silently judge less than the whole file. max-method-lines at\n * NEW_AND_MODIFIED_FILES runs only its modified-methods sub-check, which leaves every NEW method to\n * the new-methods sub-check — and inside a whole scope every method reads as new. Its\n * NEW_AND_MODIFIED_METHODS runs both sub-checks, which is the whole file. Pinned by\n * whole-scope-modes.spec.ts, which fails if this entry is removed.\n */\n private static readonly WHOLE_FILE_JUDGE_OVERRIDES: ReadonlyMap<string, string> = new Map([\n ['max-method-lines', 'NEW_AND_MODIFIED_METHODS'],\n ]);\n\n private readonly scopes = new Map<string, FileScope>();\n private readonly wholeScope = new WholeScopeModes();\n private target: DebugTarget | null = null;\n\n constructor(\n private readonly request: CodeRulesRunRequest,\n private readonly projectRoots: readonly string[] | null,\n ) {}\n\n /** The config `key`'s rule runs with. `modeSet` is the modes its schema accepts. */\n plan<C extends BaseRuleConfig>(key: string, config: C, modeSet: readonly string[]): C {\n const isTarget = this.request.rule === key;\n const committed = config.mode ?? 'OFF';\n const mode = isTarget ? this.targetMode(key, committed, modeSet) : committed;\n const judge = this.wholeScope.isWholeScopeMode(mode) ? this.judgeModeFor(key, modeSet) : null;\n const kind: FileScopeKind = judge !== null && this.wholeScope.isWholeScopeMode(mode) ? mode : 'DIFF';\n const scope = new FileScope(kind, isTarget ? this.projectRoots : null);\n if (!scope.isPlainDiff()) this.scopes.set(key, scope);\n if (isTarget) {\n this.target = new DebugTarget(key, committed, mode, this.request.projects, this.projectRoots);\n }\n if (judge === null && !isTarget) return config;\n const copy = Object.assign(Object.create(Object.getPrototypeOf(config) as object) as C, config);\n const base: BaseRuleConfig = copy;\n base.mode = judge ?? mode;\n if (isTarget) {\n base.turnOffRuleUntilEpoch = 0;\n base.turnOffRuleWhileOnBranch = null;\n }\n return copy;\n }\n\n /** The scopes planned so far. Throws when a debug run named a rule no `plan` call saw. */\n result(): RuleScopes {\n const rule = this.request.rule;\n if (rule !== null && this.target === null) {\n throw new InformAiError(\n `--rule=${rule} names no code rule and no match-rule in webpieces.config.json. A debug run judges ` +\n `a rule @webpieces/code-rules runs at build time (the keys under \"rules\", or a \"match-rules\" name).`,\n );\n }\n return new RuleScopes(this.scopes, this.target);\n }\n\n private judgeModeFor(key: string, modeSet: readonly string[]): string | null {\n const generic = this.wholeScope.wholeFileJudgeMode(modeSet);\n return generic === null ? null : (RuleScopePlanner.WHOLE_FILE_JUDGE_OVERRIDES.get(key) ?? generic);\n }\n\n private targetMode(key: string, committed: string, modeSet: readonly string[]): string {\n const mode = this.request.mode ?? committed;\n if (this.request.mode !== null && !modeSet.includes(mode)) {\n throw new InformAiError(\n `--mode=${mode} is not a mode of ${key}. Its modes: ${modeSet.join(', ')}.`,\n );\n }\n if (mode === 'OFF') {\n throw new InformAiError(\n `${key} is \"mode\": \"OFF\" in webpieces.config.json, so a debug run at the committed mode judges ` +\n `nothing. Pass --mode=<MODE> to judge it at another mode for this run: ${modeSet.filter((m: string) => m !== 'OFF').join(', ')}.`,\n );\n }\n return mode;\n }\n}\n"]}