@webpieces/code-rules 0.4.975 → 0.4.977

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 (70) hide show
  1. package/package.json +6 -6
  2. package/src/api-lib-source-rule.js +5 -5
  3. package/src/api-lib-source-rule.js.map +1 -1
  4. package/src/code-policy-composition.js +2 -0
  5. package/src/code-policy-composition.js.map +1 -1
  6. package/src/code-rules-bootstrap.js +3 -3
  7. package/src/code-rules-bootstrap.js.map +1 -1
  8. package/src/project-scan-targets.d.ts +1 -1
  9. package/src/project-scan-targets.js +7 -7
  10. package/src/project-scan-targets.js.map +1 -1
  11. package/src/rule-debug-run.d.ts +2 -2
  12. package/src/rule-debug-run.js +7 -7
  13. package/src/rule-debug-run.js.map +1 -1
  14. package/src/scan-scope.d.ts +4 -4
  15. package/src/scan-scope.js +28 -23
  16. package/src/scan-scope.js.map +1 -1
  17. package/src/tag-rule.js +2 -2
  18. package/src/tag-rule.js.map +1 -1
  19. package/src/validate-catch-error-pattern.js +6 -5
  20. package/src/validate-catch-error-pattern.js.map +1 -1
  21. package/src/validate-catch-must-propagate.js +3 -3
  22. package/src/validate-catch-must-propagate.js.map +1 -1
  23. package/src/validate-dtos.js +15 -12
  24. package/src/validate-dtos.js.map +1 -1
  25. package/src/validate-ensure-we-are-secure.js +2 -2
  26. package/src/validate-ensure-we-are-secure.js.map +1 -1
  27. package/src/validate-framework-packages.js +2 -2
  28. package/src/validate-framework-packages.js.map +1 -1
  29. package/src/validate-framework-tsconfig.js +2 -2
  30. package/src/validate-framework-tsconfig.js.map +1 -1
  31. package/src/validate-inject-annotation-not-needed-for-concrete-class.js +5 -5
  32. package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
  33. package/src/validate-match-rules.js +5 -5
  34. package/src/validate-match-rules.js.map +1 -1
  35. package/src/validate-modified-files.js +2 -2
  36. package/src/validate-modified-files.js.map +1 -1
  37. package/src/validate-modified-methods.js +6 -5
  38. package/src/validate-modified-methods.js.map +1 -1
  39. package/src/validate-new-methods.js +6 -5
  40. package/src/validate-new-methods.js.map +1 -1
  41. package/src/validate-no-any-unknown.js +6 -6
  42. package/src/validate-no-any-unknown.js.map +1 -1
  43. package/src/validate-no-client-creation-outside-server-or-client.js +7 -7
  44. package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
  45. package/src/validate-no-custom-css.js +5 -5
  46. package/src/validate-no-custom-css.js.map +1 -1
  47. package/src/validate-no-destructure.js +6 -6
  48. package/src/validate-no-destructure.js.map +1 -1
  49. package/src/validate-no-direct-api-resolver.js +10 -10
  50. package/src/validate-no-direct-api-resolver.js.map +1 -1
  51. package/src/validate-no-function-outside-class.js +5 -5
  52. package/src/validate-no-function-outside-class.js.map +1 -1
  53. package/src/validate-no-implicit-any.js +6 -5
  54. package/src/validate-no-implicit-any.js.map +1 -1
  55. package/src/validate-no-inline-types.js +10 -10
  56. package/src/validate-no-inline-types.js.map +1 -1
  57. package/src/validate-no-process-exit-outside-main.js +6 -5
  58. package/src/validate-no-process-exit-outside-main.js.map +1 -1
  59. package/src/validate-no-state-paths-in-templates.js +5 -5
  60. package/src/validate-no-state-paths-in-templates.js.map +1 -1
  61. package/src/validate-no-symbol-di-tokens.js +6 -5
  62. package/src/validate-no-symbol-di-tokens.js.map +1 -1
  63. package/src/validate-no-unmanaged-exceptions.js +6 -5
  64. package/src/validate-no-unmanaged-exceptions.js.map +1 -1
  65. package/src/validate-prisma-converters.js +13 -11
  66. package/src/validate-prisma-converters.js.map +1 -1
  67. package/src/validate-return-types.js +10 -10
  68. package/src/validate-return-types.js.map +1 -1
  69. package/src/wp-ci.js +2 -2
  70. package/src/wp-ci.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validate-no-client-creation-outside-server-or-client.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-client-creation-outside-server-or-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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YACJ,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;YAC3F,OAAO,CAAC,KAAK,CAAC,6BAA6B,SAAS,cAAc,CAAC,CAAC;YACpE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC;IACL,CAAC;CACJ,CAAA;AAxLY,wGAA8C;yDAA9C,8CAA8C;IAD1D,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGzB,uEAA2C;QACpB,2CAAmB;QACtB,sBAAS;GAJhC,8CAA8C,CAwL1D","sourcesContent":["/**\n * Validate No Client Creation Outside Server Or Client\n *\n * Flags a project that CONSTRUCTS an rpc/pubsub transport client when the project's `role:` tag is\n * not one of the runnable/entrypoint roles (`allowedRoles`, default server | client | app).\n *\n * ============================================================================\n * WHY\n * ============================================================================\n * The runtime architecture graph draws a `uses` edge from every client-creation site to the api's\n * implementer. When the site sits in a project with a declared identity (`serviceName`) or target\n * (`callsService`) — a server, a client app, an app — the edge is attributable. When it sits in a\n * `role:lib`, the target can't be attributed, so the graph falls back to a fan-out: one `uses` edge\n * to EVERY implementer of the api, i.e. calls that cannot happen. A company-wide api (warmup,\n * browser-log, auth) then draws every caller to every server — pure fiction. This rule removes the\n * failure mode by construction: a reusable library takes the api INJECTED; the server/app module\n * binds it to a client.\n *\n * ============================================================================\n * VIOLATIONS (BAD) — flagged when the OWNING project's role is not in allowedRoles:\n * ============================================================================\n * factory.createRpcClient(SomeApi, new ClientConfig('svc'))\n * clientCloudTasksFactory.createPubSubClient(SomeApi, config)\n *\n * ============================================================================\n * ALLOWED\n * ============================================================================\n * - Any site in a project whose role IS in allowedRoles (server / client / app).\n * - A project with NO `role:` tag (the role-tag rule owns \"every project must declare a role\").\n * - Merely IMPORTING the api type or its DI token, or injecting the api — only constructing the\n * transport (a `.createRpcClient(` / `.createPubSubClient(` CALL) is a violation.\n * - Test files and lines carrying the webpieces-disable escape. (Files under the rule's or the top-level\n * `excludePaths` never reach the rule — the framework drops them.)\n *\n * ============================================================================\n * SEVERITY (WARN first, then error)\n * ============================================================================\n * severity \"warn\" (default) prints the violations + migration but PASSES the build, so an upgrade\n * can't break an un-migrated Angular repo. Flip to \"error\" once libraries are migrated.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { hasDisable, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoClientCreationOutsideServerOrClientConfig, ClientCreationSeverity } from \"./configs/no-client-creation-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\nconst RULE_NAME = \"no-client-creation-outside-server-or-client\";\nconst DEFAULT_ALLOWED_ROLES = ['server', 'client', 'app'];\n// A `.createRpcClient(` / `.createPubSubClient(` method CALL — the leading dot excludes the framework\n// method DEFINITIONS (`createRpcClient<T>(apiPrototype, ...)`, no receiver); the `[(<]` requires a call\n// or a generic call, so a bare property reference isn't matched.\nconst CLIENT_CREATE_REGEX = /\\.(createRpcClient|createPubSubClient)\\s*[(<]/;\n\n/** One client-creation call site found in a file. */\nclass CreationSite {\n constructor(\n public readonly line: number,\n public readonly context: string,\n public readonly hasDisableComment: boolean,\n ) {}\n}\n\n/** A reported violation: a client-creation site in a project whose role is not allowed. */\nclass Violation {\n constructor(\n public readonly file: string,\n public readonly line: number,\n public readonly context: string,\n public readonly role: string,\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoClientCreationOutsideServerOrClientValidator extends CodeValidator<NoClientCreationOutsideServerOrClientConfig> {\n constructor(\n config: NoClientCreationOutsideServerOrClientConfig,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly scanScope: ScanScope,\n ) {\n super(config, RULE_NAME, RULE_NAME);\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode = this.config.mode ?? 'OFF';\n if (mode === 'OFF') {\n console.log(`\\n⏭️ Skipping ${RULE_NAME} validation (mode: OFF)`);\n console.log('');\n return { success: true };\n }\n\n const severity: ClientCreationSeverity = this.config.severity ?? 'warn';\n console.log(`\\n📏 Validating No Client Creation Outside Server Or Client\\n`);\n console.log(` Mode: ${mode} · Severity: ${severity}`);\n\n const base = this.resolveBase(workspaceRoot);\n if (base === null) return { success: true };\n const head = process.env['NX_HEAD'];\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = this.scanScope.files(workspaceRoot, mode, base, head);\n if (changedFiles.length === 0) {\n console.log('✅ No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n const violations = this.findViolations(workspaceRoot, changedFiles, mode, base, head);\n\n if (violations.length === 0) {\n console.log('✅ No client-creation-in-a-library violations found');\n return { success: true };\n }\n\n this.scanScope.recordSites(RULE_NAME, violations.map((v: Violation) => v.file));\n this.report(violations, severity);\n // WARN reports but passes; only \"error\" fails the build.\n return { success: severity !== 'error' };\n }\n\n private allowedRoles(): string[] {\n const configured = this.config.allowedRoles;\n return configured && configured.length > 0 ? configured : DEFAULT_ALLOWED_ROLES;\n }\n\n private disableAllowed(): boolean {\n return this.config.disableAllowed ?? true;\n }\n\n private resolveBase(workspaceRoot: string): string | null {\n const envBase = process.env['NX_BASE'];\n if (envBase) return envBase;\n const detected = detectBase(workspaceRoot);\n if (!detected) {\n console.log(`\\n⏭️ Skipping ${RULE_NAME} validation (could not detect base branch)`);\n console.log('');\n return null;\n }\n return detected;\n }\n\n /** Violations across changed files: a creation site in a project whose role is not allowed. In\n * NEW_AND_MODIFIED_CODE only sites on changed lines count; in NEW_AND_MODIFIED_FILES (and the whole-scope modes) every site\n * in a changed file counts. */\n private findViolations(\n workspaceRoot: string,\n changedFiles: string[],\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): Violation[] {\n const allowed = new Set(this.allowedRoles());\n const violations: Violation[] = [];\n for (const file of changedFiles) {\n if (this.isExempt(file)) continue;\n\n const role = this.roleResolver.roleOf(workspaceRoot, file);\n // No role tag → role-tag rule owns it; an allowed role → fine. Either way, skip.\n if (role === null || allowed.has(role)) continue;\n\n const changedLines = this.scanScope.isLineScoped(mode)\n ? getChangedLineNumbers(getFileDiff(workspaceRoot, file, base, head))\n : null;\n if (changedLines !== null && changedLines.size === 0) continue;\n\n for (const site of this.scanFile(workspaceRoot, file)) {\n if (this.disableAllowed() && site.hasDisableComment) continue;\n if (changedLines !== null && !changedLines.has(site.line)) continue;\n violations.push(new Violation(file, site.line, site.context, role));\n }\n }\n return violations;\n }\n\n private isExempt(file: string): boolean {\n return this.isTestFile(file);\n }\n\n private isTestFile(filePath: string): boolean {\n return filePath.includes('.spec.ts') || filePath.includes('.test.ts') || filePath.includes('__tests__/');\n }\n\n /** Every client-creation call site in a file, ignoring occurrences inside comments. */\n private scanFile(workspaceRoot: string, relFile: string): CreationSite[] {\n const fullPath = path.join(workspaceRoot, relFile);\n if (!fs.existsSync(fullPath)) return [];\n const lines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n const code = this.stripComments(lines);\n\n const sites: CreationSite[] = [];\n for (let i = 0; i < code.length; i++) {\n if (!CLIENT_CREATE_REGEX.test(code[i] ?? '')) continue;\n const raw = lines[i] ?? '';\n const prev = i > 0 ? (lines[i - 1] ?? '') : '';\n const disabled = hasDisable(raw, RULE_NAME) || hasDisable(prev, RULE_NAME);\n sites.push(new CreationSite(i + 1, raw.trim(), disabled));\n }\n return sites;\n }\n\n /** The code-only text of each line: block comments (/* … *\\/) and line comments (// …) blanked\n * out, so a `factory.createRpcClient(` in a JSDoc example is never matched. */\n private stripComments(lines: string[]): string[] {\n const out: string[] = [];\n let inBlock = false;\n for (const line of lines) {\n let result = '';\n let i = 0;\n while (i < line.length) {\n if (inBlock) {\n if (line[i] === '*' && line[i + 1] === '/') { inBlock = false; i += 2; } else { i += 1; }\n continue;\n }\n if (line[i] === '/' && line[i + 1] === '*') { inBlock = true; i += 2; continue; }\n if (line[i] === '/' && line[i + 1] === '/') break;\n result += line[i];\n i += 1;\n }\n out.push(result);\n }\n return out;\n }\n\n // webpieces-disable max-lines-new-methods -- console guidance block + violation list\n private report(violations: Violation[], severity: ClientCreationSeverity): void {\n const icon = severity === 'error' ? '❌' : '⚠️';\n console.error('');\n console.error(`${icon} A library (role:lib) must NOT construct an rpc/pubsub client!`);\n console.error('');\n console.error(' Only a runnable entrypoint (role:server / role:client / role:app) has a declared identity');\n console.error(' (serviceName) or target (callsService), so a client built there is attributable in the');\n console.error(' runtime graph. A client built in a library reaches the fan-out fallback — one \"uses\" edge');\n console.error(' to EVERY implementer of the api, i.e. calls that cannot happen.');\n console.error('');\n console.error(' Migrate: the library takes the api INJECTED (constructor(private readonly api: SomeApi)),');\n console.error(' and the server/app DI module constructs the client with factory.createRpcClient(SomeApi, ...).');\n console.error('');\n for (const v of violations) {\n console.error(` ${icon} ${v.file}:${v.line} (role:${v.role})`);\n console.error(` ${v.context}`);\n }\n console.error('');\n if (this.disableAllowed()) {\n console.error(' Escape hatch (use sparingly):');\n console.error(` // webpieces-disable ${RULE_NAME} -- <reason>`);\n } else {\n console.error(' Escape hatch: DISABLED (disableAllowed: false)');\n }\n console.error('');\n if (severity !== 'error') {\n console.error(' Severity: WARN — reported but NOT failing the build. Migrate, then set');\n console.error(` \"severity\": \"error\" on ${RULE_NAME} to enforce.`);\n console.error('');\n }\n }\n}\n"]}
1
+ {"version":3,"file":"validate-no-client-creation-outside-server-or-client.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-client-creation-outside-server-or-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;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OAAO,CAAC,KAAK,CAAC,2BAA2B,SAAS,cAAc,CAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;YAC3F,OAAO,CAAC,KAAK,CAAC,6BAA6B,SAAS,cAAc,CAAC,CAAC;YACpE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtB,CAAC;IACL,CAAC;CACJ,CAAA;AAxLY,wGAA8C;yDAA9C,8CAA8C;IAD1D,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGzB,uEAA2C;QACpB,2CAAmB;QACtB,sBAAS;GAJhC,8CAA8C,CAwL1D","sourcesContent":["/**\n * Validate No Client Creation Outside Server Or Client\n *\n * Flags a project that CONSTRUCTS an rpc/pubsub transport client when the project's `role:` tag is\n * not one of the runnable/entrypoint roles (`allowedRoles`, default server | client | app).\n *\n * ============================================================================\n * WHY\n * ============================================================================\n * The runtime architecture graph draws a `uses` edge from every client-creation site to the api's\n * implementer. When the site sits in a project with a declared identity (`serviceName`) or target\n * (`callsService`) — a server, a client app, an app — the edge is attributable. When it sits in a\n * `role:lib`, the target can't be attributed, so the graph falls back to a fan-out: one `uses` edge\n * to EVERY implementer of the api, i.e. calls that cannot happen. A company-wide api (warmup,\n * browser-log, auth) then draws every caller to every server — pure fiction. This rule removes the\n * failure mode by construction: a reusable library takes the api INJECTED; the server/app module\n * binds it to a client.\n *\n * ============================================================================\n * VIOLATIONS (BAD) — flagged when the OWNING project's role is not in allowedRoles:\n * ============================================================================\n * factory.createRpcClient(SomeApi, new ClientConfig('svc'))\n * clientCloudTasksFactory.createPubSubClient(SomeApi, config)\n *\n * ============================================================================\n * ALLOWED\n * ============================================================================\n * - Any site in a project whose role IS in allowedRoles (server / client / app).\n * - A project with NO `role:` tag (the role-tag rule owns \"every project must declare a role\").\n * - Merely IMPORTING the api type or its DI token, or injecting the api — only constructing the\n * transport (a `.createRpcClient(` / `.createPubSubClient(` CALL) is a violation.\n * - Test files and lines carrying the webpieces-disable escape. (Files under the rule's or the top-level\n * `excludePaths` never reach the rule — the framework drops them.)\n *\n * ============================================================================\n * SEVERITY (WARN first, then error)\n * ============================================================================\n * severity \"warn\" (default) prints the violations + migration but PASSES the build, so an upgrade\n * can't break an un-migrated Angular repo. Flip to \"error\" once libraries are migrated.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { hasDisable, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoClientCreationOutsideServerOrClientConfig, ClientCreationSeverity } from \"./configs/no-client-creation-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\nconst RULE_NAME = \"no-client-creation-outside-server-or-client\";\nconst DEFAULT_ALLOWED_ROLES = ['server', 'client', 'app'];\n// A `.createRpcClient(` / `.createPubSubClient(` method CALL — the leading dot excludes the framework\n// method DEFINITIONS (`createRpcClient<T>(apiPrototype, ...)`, no receiver); the `[(<]` requires a call\n// or a generic call, so a bare property reference isn't matched.\nconst CLIENT_CREATE_REGEX = /\\.(createRpcClient|createPubSubClient)\\s*[(<]/;\n\n/** One client-creation call site found in a file. */\nclass CreationSite {\n constructor(\n public readonly line: number,\n public readonly context: string,\n public readonly hasDisableComment: boolean,\n ) {}\n}\n\n/** A reported violation: a client-creation site in a project whose role is not allowed. */\nclass Violation {\n constructor(\n public readonly file: string,\n public readonly line: number,\n public readonly context: string,\n public readonly role: string,\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoClientCreationOutsideServerOrClientValidator extends CodeValidator<NoClientCreationOutsideServerOrClientConfig> {\n constructor(\n config: NoClientCreationOutsideServerOrClientConfig,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly scanScope: ScanScope,\n ) {\n super(config, RULE_NAME, RULE_NAME);\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode = this.config.mode ?? 'OFF';\n if (mode === 'OFF') {\n console.log(`\\n⏭️ Skipping ${RULE_NAME} validation (mode: OFF)`);\n console.log('');\n return { success: true };\n }\n\n const severity: ClientCreationSeverity = this.config.severity ?? 'warn';\n console.log(`\\n📏 Validating No Client Creation Outside Server Or Client\\n`);\n console.log(` Mode: ${mode} · Severity: ${severity}`);\n\n const base = await this.resolveBase(workspaceRoot);\n if (base === null) return { success: true };\n const head = process.env['NX_HEAD'];\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = await this.scanScope.files(workspaceRoot, mode, base, head);\n if (changedFiles.length === 0) {\n console.log('✅ No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n const violations = await this.findViolations(workspaceRoot, changedFiles, mode, base, head);\n\n if (violations.length === 0) {\n console.log('✅ No client-creation-in-a-library violations found');\n return { success: true };\n }\n\n this.scanScope.recordSites(RULE_NAME, violations.map((v: Violation) => v.file));\n this.report(violations, severity);\n // WARN reports but passes; only \"error\" fails the build.\n return { success: severity !== 'error' };\n }\n\n private allowedRoles(): string[] {\n const configured = this.config.allowedRoles;\n return configured && configured.length > 0 ? configured : DEFAULT_ALLOWED_ROLES;\n }\n\n private disableAllowed(): boolean {\n return this.config.disableAllowed ?? true;\n }\n\n private async resolveBase(workspaceRoot: string): Promise<string | null> {\n const envBase = process.env['NX_BASE'];\n if (envBase) return envBase;\n const detected = await detectBase(workspaceRoot);\n if (!detected) {\n console.log(`\\n⏭️ Skipping ${RULE_NAME} validation (could not detect base branch)`);\n console.log('');\n return null;\n }\n return detected;\n }\n\n /** Violations across changed files: a creation site in a project whose role is not allowed. In\n * NEW_AND_MODIFIED_CODE only sites on changed lines count; in NEW_AND_MODIFIED_FILES (and the whole-scope modes) every site\n * in a changed file counts. */\n private async findViolations(\n workspaceRoot: string,\n changedFiles: string[],\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): Promise<Violation[]> {\n const allowed = new Set(this.allowedRoles());\n const violations: Violation[] = [];\n for (const file of changedFiles) {\n if (this.isExempt(file)) continue;\n\n const role = this.roleResolver.roleOf(workspaceRoot, file);\n // No role tag → role-tag rule owns it; an allowed role → fine. Either way, skip.\n if (role === null || allowed.has(role)) continue;\n\n const changedLines = this.scanScope.isLineScoped(mode)\n ? getChangedLineNumbers(await getFileDiff(workspaceRoot, file, base, head))\n : null;\n if (changedLines !== null && changedLines.size === 0) continue;\n\n for (const site of this.scanFile(workspaceRoot, file)) {\n if (this.disableAllowed() && site.hasDisableComment) continue;\n if (changedLines !== null && !changedLines.has(site.line)) continue;\n violations.push(new Violation(file, site.line, site.context, role));\n }\n }\n return violations;\n }\n\n private isExempt(file: string): boolean {\n return this.isTestFile(file);\n }\n\n private isTestFile(filePath: string): boolean {\n return filePath.includes('.spec.ts') || filePath.includes('.test.ts') || filePath.includes('__tests__/');\n }\n\n /** Every client-creation call site in a file, ignoring occurrences inside comments. */\n private scanFile(workspaceRoot: string, relFile: string): CreationSite[] {\n const fullPath = path.join(workspaceRoot, relFile);\n if (!fs.existsSync(fullPath)) return [];\n const lines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n const code = this.stripComments(lines);\n\n const sites: CreationSite[] = [];\n for (let i = 0; i < code.length; i++) {\n if (!CLIENT_CREATE_REGEX.test(code[i] ?? '')) continue;\n const raw = lines[i] ?? '';\n const prev = i > 0 ? (lines[i - 1] ?? '') : '';\n const disabled = hasDisable(raw, RULE_NAME) || hasDisable(prev, RULE_NAME);\n sites.push(new CreationSite(i + 1, raw.trim(), disabled));\n }\n return sites;\n }\n\n /** The code-only text of each line: block comments (/* … *\\/) and line comments (// …) blanked\n * out, so a `factory.createRpcClient(` in a JSDoc example is never matched. */\n private stripComments(lines: string[]): string[] {\n const out: string[] = [];\n let inBlock = false;\n for (const line of lines) {\n let result = '';\n let i = 0;\n while (i < line.length) {\n if (inBlock) {\n if (line[i] === '*' && line[i + 1] === '/') { inBlock = false; i += 2; } else { i += 1; }\n continue;\n }\n if (line[i] === '/' && line[i + 1] === '*') { inBlock = true; i += 2; continue; }\n if (line[i] === '/' && line[i + 1] === '/') break;\n result += line[i];\n i += 1;\n }\n out.push(result);\n }\n return out;\n }\n\n // webpieces-disable max-lines-new-methods -- console guidance block + violation list\n private report(violations: Violation[], severity: ClientCreationSeverity): void {\n const icon = severity === 'error' ? '❌' : '⚠️';\n console.error('');\n console.error(`${icon} A library (role:lib) must NOT construct an rpc/pubsub client!`);\n console.error('');\n console.error(' Only a runnable entrypoint (role:server / role:client / role:app) has a declared identity');\n console.error(' (serviceName) or target (callsService), so a client built there is attributable in the');\n console.error(' runtime graph. A client built in a library reaches the fan-out fallback — one \"uses\" edge');\n console.error(' to EVERY implementer of the api, i.e. calls that cannot happen.');\n console.error('');\n console.error(' Migrate: the library takes the api INJECTED (constructor(private readonly api: SomeApi)),');\n console.error(' and the server/app DI module constructs the client with factory.createRpcClient(SomeApi, ...).');\n console.error('');\n for (const v of violations) {\n console.error(` ${icon} ${v.file}:${v.line} (role:${v.role})`);\n console.error(` ${v.context}`);\n }\n console.error('');\n if (this.disableAllowed()) {\n console.error(' Escape hatch (use sparingly):');\n console.error(` // webpieces-disable ${RULE_NAME} -- <reason>`);\n } else {\n console.error(' Escape hatch: DISABLED (disableAllowed: false)');\n }\n console.error('');\n if (severity !== 'error') {\n console.error(' Severity: WARN — reported but NOT failing the build. Migrate, then set');\n console.error(` \"severity\": \"error\" on ${RULE_NAME} to enforce.`);\n console.error('');\n }\n }\n}\n"]}
@@ -90,7 +90,7 @@ let NoCustomCssValidator = class NoCustomCssValidator extends code_validator_1.C
90
90
  let base = process.env['NX_BASE'];
91
91
  const head = process.env['NX_HEAD'];
92
92
  if (!base) {
93
- base = (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
93
+ base = await (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
94
94
  if (!base) {
95
95
  console.log('\n⏭️ Skipping no-custom-css validation (could not detect base branch)\n');
96
96
  return { success: true };
@@ -99,14 +99,14 @@ let NoCustomCssValidator = class NoCustomCssValidator extends code_validator_1.C
99
99
  console.log(` Base: ${base}`);
100
100
  console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}\n`);
101
101
  // tsOnly:false so changed .html templates are included; then filter to relevant files.
102
- const changedFiles = this.scanScope.files(workspaceRoot, mode, base, head, { tsOnly: false }).filter((f) => this.isRelevantFile(f));
102
+ const changedFiles = (await this.scanScope.files(workspaceRoot, mode, base, head, { tsOnly: false })).filter((f) => this.isRelevantFile(f));
103
103
  if (changedFiles.length === 0) {
104
104
  console.log('✅ No Angular .ts/.html files changed');
105
105
  return { success: true };
106
106
  }
107
107
  console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
108
108
  const violations = this.scanScope.isLineScoped(mode)
109
- ? this.findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed)
109
+ ? await this.findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed)
110
110
  : this.findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);
111
111
  if (violations.length === 0) {
112
112
  console.log('✅ No custom CSS found');
@@ -138,10 +138,10 @@ let NoCustomCssValidator = class NoCustomCssValidator extends code_validator_1.C
138
138
  return [];
139
139
  }
140
140
  /** NEW_AND_MODIFIED_CODE: only hits whose line is in the diff hunks. */
141
- findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
141
+ async findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
142
142
  const violations = [];
143
143
  for (const file of changedFiles) {
144
- const changedLines = (0, rules_config_1.getChangedLineNumbers)((0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head));
144
+ const changedLines = (0, rules_config_1.getChangedLineNumbers)(await (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head));
145
145
  if (changedLines.size === 0)
146
146
  continue;
147
147
  for (const h of this.findHitsForFile(file, workspaceRoot)) {
@@ -1 +1 @@
1
- {"version":3,"file":"validate-no-custom-css.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-custom-css.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuH;AACvH,yDAA2D;AAE3D,qDAAiE;AACjE,yCAA2D;AAC3D,6CAAyC;AAEzC,gEAAgE;AAChE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AAEjE,yFAAyF;AACzF,iEAAiE;AACjE,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AACxC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,MAAa,YAAY;IAER;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,MAAc;QAHd,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAPD,oCAOC;AAED,MAAa,MAAM;IAEF;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,MAAc,EACd,MAAc,EACd,iBAA0B;QAH1B,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,sBAAiB,GAAjB,iBAAiB,CAAS;IACpC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oB,CA4MhC","sourcesContent":["/**\n * Validate No Custom CSS Executor\n *\n * Enforces Tailwind-first styling in Angular sources by banning hand-written CSS on CHANGED code:\n * - `.ts` — `styles:` / `styleUrls:` / `styleUrl:` inside an `@Component({...})` decorator\n * (detected via the TypeScript AST, so only the real decorator triggers it).\n * - `.html` — a static `style=\"…\"` attribute, a `[style]` / `[style.x]` binding, or `[ngStyle]`\n * (line/regex scan — Angular templates have no TS AST).\n *\n * Unlike an ESLint rule (which lints whole files), this is diff-scoped: NEW_AND_MODIFIED_CODE only\n * flags violations on changed lines, so a legacy Angular app is never retroactively flooded — the\n * rule bites when a file is next edited.\n *\n * MODES: OFF | NEW_AND_MODIFIED_CODE (changed lines) | NEW_AND_MODIFIED_FILES (all in changed files)\n * | MODIFIED_PROJECTS / RUN_EVERY_TIME (whole files of every touched project / of the repo — #1027).\n *\n * ESCAPE HATCH (a genuinely dynamic runtime value):\n * .ts: // webpieces-disable no-custom-css -- <reason>\n * .html: <!-- webpieces-disable no-custom-css -- <reason> -->\n *\n * PATH EXEMPTION: `allowGlobs` in the rule's webpieces.config.json entry (a vendored kit copied verbatim\n * with its own CSS, a generated artifact). It is applied by the shared `NoCustomCssScope`, the SAME class\n * the edit-time hook rule consults — so the editor and CI agree on which paths the rule looks at.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { hasDisable, NoCustomCssScope, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoCustomCssConfig } from \"./configs/rule-configs\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ScanScope } from './scan-scope';\n\n// @Component decorator properties that inject hand-written CSS.\nconst STYLE_PROPS = new Set(['styles', 'styleUrls', 'styleUrl']);\n\n// Template patterns. `[style.width]=\"x\"` is preceded by `[`, so the inline-style regex's\n// `(^|\\s)style=` boundary keeps it apart from the binding forms.\nconst RE_INLINE_STYLE = /(^|\\s)style\\s*=\\s*[\"']/;\nconst RE_NG_STYLE = /\\[?ngStyle\\]?\\s*=/;\nconst RE_STYLE_BINDING = /\\[style(?:\\.[\\w.-]+)?\\]/;\n\nexport class CssViolation {\n constructor(\n readonly file: string,\n readonly line: number,\n readonly column: number,\n readonly detail: string,\n ) {}\n}\n\nexport class CssHit {\n constructor(\n readonly line: number,\n readonly column: number,\n readonly detail: string,\n readonly hasDisableComment: boolean,\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoCustomCssValidator extends CodeValidator<NoCustomCssConfig> {\n // The SAME exemption the edit-time hook rule applies per file — one class in @webpieces/rules-config,\n // so `allowGlobs` cannot be honoured by the editor and ignored here (which is what it used to do).\n private readonly pathScope: NoCustomCssScope;\n\n constructor(config: NoCustomCssConfig, private readonly scanScope: ScanScope) {\n super(config, 'no-custom-css', 'no-custom-css');\n this.pathScope = new NoCustomCssScope(config);\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const opts = this.config;\n const mode = opts.mode ?? 'OFF';\n const disableAllowed = opts.disableAllowed ?? true;\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping no-custom-css validation (mode: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Validating No Custom CSS (Tailwind-first)\\n');\n console.log(` Mode: ${mode}`);\n\n let base = process.env['NX_BASE'];\n const head = process.env['NX_HEAD'];\n if (!base) {\n base = detectBase(workspaceRoot) ?? undefined;\n if (!base) {\n console.log('\\n⏭️ Skipping no-custom-css validation (could not detect base branch)\\n');\n return { success: true };\n }\n }\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}\\n`);\n\n // tsOnly:false so changed .html templates are included; then filter to relevant files.\n const changedFiles = this.scanScope.files(workspaceRoot, mode, base, head, { tsOnly: false }).filter((f: string) => this.isRelevantFile(f));\n if (changedFiles.length === 0) {\n console.log('✅ No Angular .ts/.html files changed');\n return { success: true };\n }\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n\n const violations =\n this.scanScope.isLineScoped(mode)\n ? this.findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed)\n : this.findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);\n\n if (violations.length === 0) {\n console.log('✅ No custom CSS found');\n return { success: true };\n }\n this.scanScope.recordSites(this.name, violations.map((v: CssViolation) => v.file));\n this.reportViolations(violations, mode);\n return { success: false };\n }\n\n /**\n * A changed file this rule cares about: an Angular .ts/.tsx or .html that the shared\n * {@link NoCustomCssScope} does not exempt (a test source, or a configured `allowGlobs` match).\n *\n * This is the ONE place the changed-file set is narrowed, which is what makes the exemption\n * impossible to apply in one mode and forget in the other — both `NEW_AND_MODIFIED_CODE` and\n * `NEW_AND_MODIFIED_FILES` run over the list this predicate produced.\n */\n isRelevantFile(file: string): boolean {\n if (this.pathScope.isExempt(file)) return false;\n return file.endsWith('.html') || file.endsWith('.ts') || file.endsWith('.tsx');\n }\n\n /** All banned-CSS hits in a single file (dispatches to the .ts AST or the .html line scan). */\n findHitsForFile(file: string, workspaceRoot: string): CssHit[] {\n if (file.endsWith('.html')) return this.findCustomCssInHtmlFile(file, workspaceRoot);\n if (file.endsWith('.ts') || file.endsWith('.tsx')) return this.findCustomCssInTsFile(file, workspaceRoot);\n return [];\n }\n\n /** NEW_AND_MODIFIED_CODE: only hits whose line is in the diff hunks. */\n private findViolationsForModifiedCode(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head: string | undefined,\n disableAllowed: boolean,\n ): CssViolation[] {\n const violations: CssViolation[] = [];\n for (const file of changedFiles) {\n const changedLines = getChangedLineNumbers(getFileDiff(workspaceRoot, file, base, head));\n if (changedLines.size === 0) continue;\n for (const h of this.findHitsForFile(file, workspaceRoot)) {\n if (disableAllowed && h.hasDisableComment) continue;\n if (!changedLines.has(h.line)) continue;\n violations.push(new CssViolation(file, h.line, h.column, h.detail));\n }\n }\n return violations;\n }\n\n /** NEW_AND_MODIFIED_FILES: all hits in any changed file. */\n private findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[], disableAllowed: boolean): CssViolation[] {\n const violations: CssViolation[] = [];\n for (const file of changedFiles) {\n for (const h of this.findHitsForFile(file, workspaceRoot)) {\n if (disableAllowed && h.hasDisableComment) continue;\n violations.push(new CssViolation(file, h.line, h.column, h.detail));\n }\n }\n return violations;\n }\n\n /** Flag styles:/styleUrls:/styleUrl: properties inside an `@Component({...})` decorator. */\n private findCustomCssInTsFile(filePath: string, workspaceRoot: string): CssHit[] {\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n const content = fs.readFileSync(fullPath, 'utf-8');\n const fileLines = content.split('\\n');\n const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);\n const hits: CssHit[] = [];\n this.collectTsHits(sourceFile, sourceFile, fileLines, hits);\n return hits;\n }\n\n /** Recurse the AST; every `@Component(...)` decorator contributes its banned style props. */\n private collectTsHits(node: ts.Node, sourceFile: ts.SourceFile, fileLines: string[], hits: CssHit[]): void {\n if (ts.isDecorator(node)) this.collectComponentStyleProps(node, sourceFile, fileLines, hits);\n ts.forEachChild(node, (child: ts.Node) => this.collectTsHits(child, sourceFile, fileLines, hits));\n }\n\n /** Pull the banned style props out of a single `@Component(...)` decorator node. */\n private collectComponentStyleProps(node: ts.Decorator, sourceFile: ts.SourceFile, fileLines: string[], hits: CssHit[]): void {\n const expr = node.expression;\n if (!ts.isCallExpression(expr) || !ts.isIdentifier(expr.expression) || expr.expression.text !== 'Component') return;\n const arg = expr.arguments[0];\n if (!arg || !ts.isObjectLiteralExpression(arg)) return;\n for (const prop of arg.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue;\n const name = prop.name.text;\n if (!STYLE_PROPS.has(name)) continue;\n const pos = sourceFile.getLineAndCharacterOfPosition(prop.getStart(sourceFile));\n const line = pos.line + 1;\n hits.push(new CssHit(line, pos.character + 1, `\\`${name}\\` block in @Component`, this.hasDisableComment(fileLines, line)));\n }\n }\n\n /** Flag inline style=, [style.x]/[style], and [ngStyle] in an Angular template via a line scan. */\n private findCustomCssInHtmlFile(filePath: string, workspaceRoot: string): CssHit[] {\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n const fileLines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n const hits: CssHit[] = [];\n for (let i = 0; i < fileLines.length; i++) {\n const detail = this.detailForTemplateLine(fileLines[i] ?? '');\n if (!detail) continue;\n const line = i + 1;\n hits.push(new CssHit(line, 1, detail, this.hasDisableComment(fileLines, line)));\n }\n return hits;\n }\n\n /** The banned-pattern label for a template line, or '' when the line is clean. */\n private detailForTemplateLine(raw: string): string {\n if (RE_NG_STYLE.test(raw)) return 'inline `[ngStyle]`';\n if (RE_STYLE_BINDING.test(raw)) return 'inline `[style.x]` binding';\n if (RE_INLINE_STYLE.test(raw)) return 'inline `style=` attribute';\n return '';\n }\n\n /** True if a `webpieces-disable no-custom-css` marker sits on this line or up to 3 lines above. */\n private hasDisableComment(lines: string[], lineNumber: number): boolean {\n const start = Math.max(0, lineNumber - 4);\n for (let i = lineNumber - 1; i >= start; i--) {\n if (hasDisable(lines[i] ?? '', \"no-custom-css\")) return true;\n }\n return false;\n }\n\n private reportViolations(violations: CssViolation[], mode: ModifiedCodeMode): void {\n console.error('');\n console.error('❌ Custom CSS found in Angular source! Style with Tailwind utility classes instead.');\n console.error('');\n console.error('📚 Tailwind-first keeps styling in the template, greppable and consistent:');\n console.error(' BAD: styles: [\".card { display: flex; gap: 1rem; }\"]');\n console.error(' GOOD: class=\"flex gap-4\"');\n console.error(' BAD: <div style=\"width: 240px\"> | [style.width] | [ngStyle]');\n console.error(' GOOD: <div class=\"w-[240px]\"> | [class.x] toggles');\n console.error('');\n for (const v of violations) {\n console.error(` ❌ ${v.file}:${v.line}:${v.column}`);\n console.error(` ${v.detail}`);\n }\n console.error('');\n console.error(' To fix: delete the CSS and use Tailwind utility classes (arbitrary values like');\n console.error(' `bg-[#fffde7]` / `grid-cols-[2fr_2fr_2fr_48px]` cover the long tail).');\n console.error('');\n console.error(' Whole tree not yours to restyle (a vendored kit, a generated artifact)?');\n console.error(' Add a glob to no-custom-css.allowGlobs in webpieces.config.json — it exempts the');\n console.error(' path here and in the editor hook alike.');\n console.error('');\n console.error(' Escape hatch (genuinely dynamic runtime value, use sparingly):');\n console.error(' .ts // webpieces-disable no-custom-css -- <reason>');\n console.error(' .html <!-- webpieces-disable no-custom-css -- <reason> -->');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n }\n}\n"]}
1
+ {"version":3,"file":"validate-no-custom-css.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-custom-css.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuH;AACvH,yDAA2D;AAE3D,qDAAiE;AACjE,yCAA2D;AAC3D,6CAAyC;AAEzC,gEAAgE;AAChE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AAEjE,yFAAyF;AACzF,iEAAiE;AACjE,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,WAAW,GAAG,mBAAmB,CAAC;AACxC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAEnD,MAAa,YAAY;IAER;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,MAAc;QAHd,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAPD,oCAOC;AAED,MAAa,MAAM;IAEF;IACA;IACA;IACA;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AC,oBAAoB,IAAI,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;CACJ,CAAA;AA5MY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAMjB,gCAAiB,EAA8B,sBAAS;GALnE,oBAAoB,CA4MhC","sourcesContent":["/**\n * Validate No Custom CSS Executor\n *\n * Enforces Tailwind-first styling in Angular sources by banning hand-written CSS on CHANGED code:\n * - `.ts` — `styles:` / `styleUrls:` / `styleUrl:` inside an `@Component({...})` decorator\n * (detected via the TypeScript AST, so only the real decorator triggers it).\n * - `.html` — a static `style=\"…\"` attribute, a `[style]` / `[style.x]` binding, or `[ngStyle]`\n * (line/regex scan — Angular templates have no TS AST).\n *\n * Unlike an ESLint rule (which lints whole files), this is diff-scoped: NEW_AND_MODIFIED_CODE only\n * flags violations on changed lines, so a legacy Angular app is never retroactively flooded — the\n * rule bites when a file is next edited.\n *\n * MODES: OFF | NEW_AND_MODIFIED_CODE (changed lines) | NEW_AND_MODIFIED_FILES (all in changed files)\n * | MODIFIED_PROJECTS / RUN_EVERY_TIME (whole files of every touched project / of the repo — #1027).\n *\n * ESCAPE HATCH (a genuinely dynamic runtime value):\n * .ts: // webpieces-disable no-custom-css -- <reason>\n * .html: <!-- webpieces-disable no-custom-css -- <reason> -->\n *\n * PATH EXEMPTION: `allowGlobs` in the rule's webpieces.config.json entry (a vendored kit copied verbatim\n * with its own CSS, a generated artifact). It is applied by the shared `NoCustomCssScope`, the SAME class\n * the edit-time hook rule consults — so the editor and CI agree on which paths the rule looks at.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { hasDisable, NoCustomCssScope, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoCustomCssConfig } from \"./configs/rule-configs\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ScanScope } from './scan-scope';\n\n// @Component decorator properties that inject hand-written CSS.\nconst STYLE_PROPS = new Set(['styles', 'styleUrls', 'styleUrl']);\n\n// Template patterns. `[style.width]=\"x\"` is preceded by `[`, so the inline-style regex's\n// `(^|\\s)style=` boundary keeps it apart from the binding forms.\nconst RE_INLINE_STYLE = /(^|\\s)style\\s*=\\s*[\"']/;\nconst RE_NG_STYLE = /\\[?ngStyle\\]?\\s*=/;\nconst RE_STYLE_BINDING = /\\[style(?:\\.[\\w.-]+)?\\]/;\n\nexport class CssViolation {\n constructor(\n readonly file: string,\n readonly line: number,\n readonly column: number,\n readonly detail: string,\n ) {}\n}\n\nexport class CssHit {\n constructor(\n readonly line: number,\n readonly column: number,\n readonly detail: string,\n readonly hasDisableComment: boolean,\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoCustomCssValidator extends CodeValidator<NoCustomCssConfig> {\n // The SAME exemption the edit-time hook rule applies per file — one class in @webpieces/rules-config,\n // so `allowGlobs` cannot be honoured by the editor and ignored here (which is what it used to do).\n private readonly pathScope: NoCustomCssScope;\n\n constructor(config: NoCustomCssConfig, private readonly scanScope: ScanScope) {\n super(config, 'no-custom-css', 'no-custom-css');\n this.pathScope = new NoCustomCssScope(config);\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const opts = this.config;\n const mode = opts.mode ?? 'OFF';\n const disableAllowed = opts.disableAllowed ?? true;\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping no-custom-css validation (mode: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Validating No Custom CSS (Tailwind-first)\\n');\n console.log(` Mode: ${mode}`);\n\n let base = process.env['NX_BASE'];\n const head = process.env['NX_HEAD'];\n if (!base) {\n base = await detectBase(workspaceRoot) ?? undefined;\n if (!base) {\n console.log('\\n⏭️ Skipping no-custom-css validation (could not detect base branch)\\n');\n return { success: true };\n }\n }\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}\\n`);\n\n // tsOnly:false so changed .html templates are included; then filter to relevant files.\n const changedFiles = (await this.scanScope.files(workspaceRoot, mode, base, head, { tsOnly: false })).filter((f: string) => this.isRelevantFile(f));\n if (changedFiles.length === 0) {\n console.log('✅ No Angular .ts/.html files changed');\n return { success: true };\n }\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n\n const violations =\n this.scanScope.isLineScoped(mode)\n ? await this.findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed)\n : this.findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);\n\n if (violations.length === 0) {\n console.log('✅ No custom CSS found');\n return { success: true };\n }\n this.scanScope.recordSites(this.name, violations.map((v: CssViolation) => v.file));\n this.reportViolations(violations, mode);\n return { success: false };\n }\n\n /**\n * A changed file this rule cares about: an Angular .ts/.tsx or .html that the shared\n * {@link NoCustomCssScope} does not exempt (a test source, or a configured `allowGlobs` match).\n *\n * This is the ONE place the changed-file set is narrowed, which is what makes the exemption\n * impossible to apply in one mode and forget in the other — both `NEW_AND_MODIFIED_CODE` and\n * `NEW_AND_MODIFIED_FILES` run over the list this predicate produced.\n */\n isRelevantFile(file: string): boolean {\n if (this.pathScope.isExempt(file)) return false;\n return file.endsWith('.html') || file.endsWith('.ts') || file.endsWith('.tsx');\n }\n\n /** All banned-CSS hits in a single file (dispatches to the .ts AST or the .html line scan). */\n findHitsForFile(file: string, workspaceRoot: string): CssHit[] {\n if (file.endsWith('.html')) return this.findCustomCssInHtmlFile(file, workspaceRoot);\n if (file.endsWith('.ts') || file.endsWith('.tsx')) return this.findCustomCssInTsFile(file, workspaceRoot);\n return [];\n }\n\n /** NEW_AND_MODIFIED_CODE: only hits whose line is in the diff hunks. */\n private async findViolationsForModifiedCode(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head: string | undefined,\n disableAllowed: boolean,\n ): Promise<CssViolation[]> {\n const violations: CssViolation[] = [];\n for (const file of changedFiles) {\n const changedLines = getChangedLineNumbers(await getFileDiff(workspaceRoot, file, base, head));\n if (changedLines.size === 0) continue;\n for (const h of this.findHitsForFile(file, workspaceRoot)) {\n if (disableAllowed && h.hasDisableComment) continue;\n if (!changedLines.has(h.line)) continue;\n violations.push(new CssViolation(file, h.line, h.column, h.detail));\n }\n }\n return violations;\n }\n\n /** NEW_AND_MODIFIED_FILES: all hits in any changed file. */\n private findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[], disableAllowed: boolean): CssViolation[] {\n const violations: CssViolation[] = [];\n for (const file of changedFiles) {\n for (const h of this.findHitsForFile(file, workspaceRoot)) {\n if (disableAllowed && h.hasDisableComment) continue;\n violations.push(new CssViolation(file, h.line, h.column, h.detail));\n }\n }\n return violations;\n }\n\n /** Flag styles:/styleUrls:/styleUrl: properties inside an `@Component({...})` decorator. */\n private findCustomCssInTsFile(filePath: string, workspaceRoot: string): CssHit[] {\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n const content = fs.readFileSync(fullPath, 'utf-8');\n const fileLines = content.split('\\n');\n const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);\n const hits: CssHit[] = [];\n this.collectTsHits(sourceFile, sourceFile, fileLines, hits);\n return hits;\n }\n\n /** Recurse the AST; every `@Component(...)` decorator contributes its banned style props. */\n private collectTsHits(node: ts.Node, sourceFile: ts.SourceFile, fileLines: string[], hits: CssHit[]): void {\n if (ts.isDecorator(node)) this.collectComponentStyleProps(node, sourceFile, fileLines, hits);\n ts.forEachChild(node, (child: ts.Node) => this.collectTsHits(child, sourceFile, fileLines, hits));\n }\n\n /** Pull the banned style props out of a single `@Component(...)` decorator node. */\n private collectComponentStyleProps(node: ts.Decorator, sourceFile: ts.SourceFile, fileLines: string[], hits: CssHit[]): void {\n const expr = node.expression;\n if (!ts.isCallExpression(expr) || !ts.isIdentifier(expr.expression) || expr.expression.text !== 'Component') return;\n const arg = expr.arguments[0];\n if (!arg || !ts.isObjectLiteralExpression(arg)) return;\n for (const prop of arg.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue;\n const name = prop.name.text;\n if (!STYLE_PROPS.has(name)) continue;\n const pos = sourceFile.getLineAndCharacterOfPosition(prop.getStart(sourceFile));\n const line = pos.line + 1;\n hits.push(new CssHit(line, pos.character + 1, `\\`${name}\\` block in @Component`, this.hasDisableComment(fileLines, line)));\n }\n }\n\n /** Flag inline style=, [style.x]/[style], and [ngStyle] in an Angular template via a line scan. */\n private findCustomCssInHtmlFile(filePath: string, workspaceRoot: string): CssHit[] {\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n const fileLines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n const hits: CssHit[] = [];\n for (let i = 0; i < fileLines.length; i++) {\n const detail = this.detailForTemplateLine(fileLines[i] ?? '');\n if (!detail) continue;\n const line = i + 1;\n hits.push(new CssHit(line, 1, detail, this.hasDisableComment(fileLines, line)));\n }\n return hits;\n }\n\n /** The banned-pattern label for a template line, or '' when the line is clean. */\n private detailForTemplateLine(raw: string): string {\n if (RE_NG_STYLE.test(raw)) return 'inline `[ngStyle]`';\n if (RE_STYLE_BINDING.test(raw)) return 'inline `[style.x]` binding';\n if (RE_INLINE_STYLE.test(raw)) return 'inline `style=` attribute';\n return '';\n }\n\n /** True if a `webpieces-disable no-custom-css` marker sits on this line or up to 3 lines above. */\n private hasDisableComment(lines: string[], lineNumber: number): boolean {\n const start = Math.max(0, lineNumber - 4);\n for (let i = lineNumber - 1; i >= start; i--) {\n if (hasDisable(lines[i] ?? '', \"no-custom-css\")) return true;\n }\n return false;\n }\n\n private reportViolations(violations: CssViolation[], mode: ModifiedCodeMode): void {\n console.error('');\n console.error('❌ Custom CSS found in Angular source! Style with Tailwind utility classes instead.');\n console.error('');\n console.error('📚 Tailwind-first keeps styling in the template, greppable and consistent:');\n console.error(' BAD: styles: [\".card { display: flex; gap: 1rem; }\"]');\n console.error(' GOOD: class=\"flex gap-4\"');\n console.error(' BAD: <div style=\"width: 240px\"> | [style.width] | [ngStyle]');\n console.error(' GOOD: <div class=\"w-[240px]\"> | [class.x] toggles');\n console.error('');\n for (const v of violations) {\n console.error(` ❌ ${v.file}:${v.line}:${v.column}`);\n console.error(` ${v.detail}`);\n }\n console.error('');\n console.error(' To fix: delete the CSS and use Tailwind utility classes (arbitrary values like');\n console.error(' `bg-[#fffde7]` / `grid-cols-[2fr_2fr_2fr_48px]` cover the long tail).');\n console.error('');\n console.error(' Whole tree not yours to restyle (a vendored kit, a generated artifact)?');\n console.error(' Add a glob to no-custom-css.allowGlobs in webpieces.config.json — it exempts the');\n console.error(' path here and in the editor hook alike.');\n console.error('');\n console.error(' Escape hatch (genuinely dynamic runtime value, use sparingly):');\n console.error(' .ts // webpieces-disable no-custom-css -- <reason>');\n console.error(' .html <!-- webpieces-disable no-custom-css -- <reason> -->');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n }\n}\n"]}
@@ -231,11 +231,11 @@ function getDestructureContext(node) {
231
231
  /**
232
232
  * NEW_AND_MODIFIED_CODE mode: Flag violations on changed lines in diff hunks.
233
233
  */
234
- // webpieces-disable max-lines-new-methods -- File iteration with diff parsing and line filtering
235
- function findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
234
+ // webpieces-disable max-lines-new-methods, no-function-outside-class -- File iteration with diff parsing and line filtering
235
+ async function findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
236
236
  const violations = [];
237
237
  for (const file of changedFiles) {
238
- const diff = (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
238
+ const diff = await (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
239
239
  const changedLines = (0, rules_config_1.getChangedLineNumbers)(diff);
240
240
  if (changedLines.size === 0)
241
241
  continue;
@@ -330,7 +330,7 @@ async function runValidatorImpl(scan, options, workspaceRoot) {
330
330
  let base = process.env['NX_BASE'];
331
331
  const head = process.env['NX_HEAD'];
332
332
  if (!base) {
333
- base = (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
333
+ base = await (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
334
334
  if (!base) {
335
335
  console.log('\n\u23ed\ufe0f Skipping no-destructure validation (could not detect base branch)');
336
336
  console.log('');
@@ -340,7 +340,7 @@ async function runValidatorImpl(scan, options, workspaceRoot) {
340
340
  console.log(` Base: ${base}`);
341
341
  console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
342
342
  console.log('');
343
- const changedFiles = scan.files(workspaceRoot, mode, base, head);
343
+ const changedFiles = await scan.files(workspaceRoot, mode, base, head);
344
344
  if (changedFiles.length === 0) {
345
345
  console.log('\u2705 No TypeScript files changed');
346
346
  return { success: true };
@@ -348,7 +348,7 @@ async function runValidatorImpl(scan, options, workspaceRoot) {
348
348
  console.log(`\ud83d\udcc2 Checking ${changedFiles.length} changed file(s)...`);
349
349
  let violations = [];
350
350
  if (mode === 'NEW_AND_MODIFIED_CODE') {
351
- violations = findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);
351
+ violations = await findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);
352
352
  }
353
353
  else {
354
354
  // NEW_AND_MODIFIED_FILES and the whole-scope modes (#1027) all judge every site of every file.
@@ -1 +1 @@
1
- {"version":3,"file":"validate-no-destructure.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-destructure.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;;AAiHH,0DAuDC;;AAtKD,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAqG;AACrG,yDAA6D;AAE7D,qDAAiE;AACjE,yCAA2D;AAC3D,6CAAyC;AASzC;;GAEG;AACH,SAAS,iBAAiB,CAA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,8BAA8B,CAAC,aAAa,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;IAC7F,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAuB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACxF,gBAAgB,CAAC,UAAU,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IAEnD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAGM,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,8BAAkC;IAChB;IAA1D,YAAY,MAA2B,EAAmB,SAAoB;QAC1E,KAAK,CAAC,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;QADI,cAAS,GAAT,SAAS,CAAW;IAE9E,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,aAAqB;QAC3B,OAAO,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AARY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEjB,kCAAmB,EAA8B,sBAAS;GADrE,sBAAsB,CAQlC","sourcesContent":["/**\n * Validate No Destructure Executor\n *\n * Validates that destructuring patterns are not used in TypeScript code.\n * Uses LINE-BASED detection (not method-based) for git diff filtering.\n *\n * ============================================================================\n * VIOLATIONS (BAD) - These patterns are flagged:\n * ============================================================================\n *\n * - const { x, y } = obj — object destructuring in variable declarations\n * - const [a, b] = fn() — array destructuring (except Promise.all)\n * - for (const { email } of items) — object destructuring in for-of loops\n * - for (const [a, b] of items) — array destructuring in for-of (except Object.entries)\n * - const { page = 0 } = opts — destructuring with defaults\n * - const { done: streamDone } = obj — destructuring with renaming\n * - function foo({ x, y }: Type) — function parameter destructuring\n *\n * ============================================================================\n * ALLOWED (skip — NOT violations)\n * ============================================================================\n *\n * - const [a, b] = await Promise.all([...]) — Promise.all array destructuring\n * - for (const [key, value] of Object.entries(obj)) — Object.entries in for-of\n * - const { extracted, ...rest } = obj — rest operator separation\n * - Lines with // webpieces-disable no-destructure -- [reason] (only when disableAllowed: true)\n * - Files under the rule's `excludePaths` (or the top-level one), dropped by the framework before the\n * rule runs — e.g. a React/React Native tree, where useState and destructured props are the\n * framework's own idiom. This is the ONLY escape when disableAllowed: false.\n *\n * ============================================================================\n * MODES (LINE-BASED)\n * ============================================================================\n * - OFF: Skip validation entirely\n * - NEW_AND_MODIFIED_CODE: Flag destructuring on changed lines (lines in diff hunks)\n * - NEW_AND_MODIFIED_FILES: Flag ALL destructuring in files that were modified\n *\n * ============================================================================\n * ESCAPE HATCH\n * ============================================================================\n * Add comment above the violation:\n * // webpieces-disable no-destructure -- [your justification]\n * const { x, y } = obj;\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { hasDisable, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoDestructureConfig } from \"./configs/rule-configs\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ScanScope } from './scan-scope';\n\ninterface DestructureViolation {\n file: string;\n line: number;\n column: number;\n context: string;\n}\n\n/**\n * Check if a line contains a webpieces-disable comment for no-destructure.\n */\nfunction hasDisableComment(lines: string[], lineNumber: number): boolean {\n const startCheck = Math.max(0, lineNumber - 5);\n for (let i = lineNumber - 2; i >= startCheck; i--) {\n const line = lines[i]?.trim() ?? '';\n if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {\n break;\n }\n if (hasDisable(line, \"no-destructure\")) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Check if an ArrayBindingPattern's initializer is `await Promise.all(...)`.\n */\nfunction isPromiseAllDestructure(node: ts.ArrayBindingPattern): boolean {\n const parent = node.parent;\n if (!ts.isVariableDeclaration(parent)) return false;\n const initializer = parent.initializer;\n if (!initializer) return false;\n\n // Handle: const [a, b] = await Promise.all([...])\n if (ts.isAwaitExpression(initializer)) {\n const awaitedExpr = initializer.expression;\n if (ts.isCallExpression(awaitedExpr)) {\n const callExpr = awaitedExpr.expression;\n // Promise.all(...)\n if (ts.isPropertyAccessExpression(callExpr) && callExpr.name.text === 'all') {\n const obj = callExpr.expression;\n if (ts.isIdentifier(obj) && obj.text === 'Promise') {\n return true;\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Check if an ArrayBindingPattern in a for-of loop iterates over Object.entries(...).\n */\nfunction isObjectEntriesForOf(node: ts.ArrayBindingPattern): boolean {\n // Walk up: ArrayBindingPattern -> VariableDeclaration -> VariableDeclarationList -> ForOfStatement\n const varDecl = node.parent;\n if (!ts.isVariableDeclaration(varDecl)) return false;\n\n const varDeclList = varDecl.parent;\n if (!ts.isVariableDeclarationList(varDeclList)) return false;\n\n const forOfStmt = varDeclList.parent;\n if (!ts.isForOfStatement(forOfStmt)) return false;\n\n // Check iterable expression ends with .entries()\n const iterable = forOfStmt.expression;\n if (ts.isCallExpression(iterable)) {\n const callExpr = iterable.expression;\n if (ts.isPropertyAccessExpression(callExpr) && callExpr.name.text === 'entries') {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Check if an ObjectBindingPattern contains a rest element (...rest).\n */\nfunction hasRestElement(node: ts.ObjectBindingPattern): boolean {\n for (const element of node.elements) {\n if (element.dotDotDotToken) {\n return true;\n }\n }\n return false;\n}\n\nexport interface DestructureInfo {\n line: number;\n column: number;\n context: string;\n hasDisableComment: boolean;\n}\n\n/**\n * Find all destructuring patterns in a file using AST.\n */\n// webpieces-disable max-lines-new-methods -- AST traversal with multiple destructuring pattern checks and exception detection\n// webpieces-disable no-function-outside-class -- the rule engine is inherently functional; validators can't be class members\nexport function findDestructuringInFile(filePath: string, workspaceRoot: string, disableAllowed: boolean): DestructureInfo[] {\n // Guard on the REPO-RELATIVE path, before the join below — globs like `mobile/**` never match an\n // absolute path. This is the only escape when disableAllowed is false.\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const fileLines = content.split('\\n');\n const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);\n\n const violations: DestructureInfo[] = [];\n\n // webpieces-disable max-lines-new-methods -- AST visitor needs to handle object/array binding patterns in declarations, for-of, and parameters\n function visit(node: ts.Node): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // Check ObjectBindingPattern\n if (ts.isObjectBindingPattern(node)) {\n // Exception: rest operator separation\n if (hasRestElement(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n const context = getDestructureContext(node);\n recordViolation(node, context, fileLines, sourceFile, violations, disableAllowed);\n }\n\n // Check ArrayBindingPattern\n if (ts.isArrayBindingPattern(node)) {\n // Exception: Promise.all destructure\n if (isPromiseAllDestructure(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n // Exception: Object.entries in for-of\n if (isObjectEntriesForOf(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n const context = getDestructureContext(node);\n recordViolation(node, context, fileLines, sourceFile, violations, disableAllowed);\n }\n } catch (err: unknown) {\n //const error = toError(err);\n // Skip nodes that cause errors during analysis\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return violations;\n}\n\nfunction recordViolation(\n node: ts.Node,\n context: string,\n fileLines: string[],\n sourceFile: ts.SourceFile,\n violations: DestructureInfo[],\n disableAllowed: boolean,\n): void {\n const startPos = node.getStart(sourceFile);\n if (startPos >= 0) {\n const pos = sourceFile.getLineAndCharacterOfPosition(startPos);\n const line = pos.line + 1;\n const column = pos.character + 1;\n const disabled = hasDisableComment(fileLines, line);\n\n if (!disableAllowed && disabled) {\n // When disableAllowed is false, ignore disable comments — still a violation\n violations.push({ line, column, context, hasDisableComment: false });\n } else {\n violations.push({ line, column, context, hasDisableComment: disabled });\n }\n }\n}\n\n/**\n * Get a description of where the destructuring pattern appears.\n */\nfunction getDestructureContext(node: ts.Node): string {\n const parent = node.parent;\n if (ts.isParameter(parent)) {\n return 'function parameter destructuring';\n }\n if (ts.isVariableDeclaration(parent)) {\n const grandparent = parent.parent;\n if (grandparent && ts.isVariableDeclarationList(grandparent)) {\n const forOfParent = grandparent.parent;\n if (forOfParent && ts.isForOfStatement(forOfParent)) {\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring in for-of loop'\n : 'array destructuring in for-of loop';\n }\n }\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring in variable declaration'\n : 'array destructuring in variable declaration';\n }\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring'\n : 'array destructuring';\n}\n\n/**\n * NEW_AND_MODIFIED_CODE mode: Flag violations on changed lines in diff hunks.\n */\n// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and line filtering\nfunction findViolationsForModifiedCode(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head: string | undefined,\n disableAllowed: boolean,\n): DestructureViolation[] {\n const violations: DestructureViolation[] = [];\n\n for (const file of changedFiles) {\n const diff = getFileDiff(workspaceRoot, file, base, head);\n const changedLines = getChangedLineNumbers(diff);\n\n if (changedLines.size === 0) continue;\n\n const allViolations = findDestructuringInFile(file, workspaceRoot, disableAllowed);\n\n for (const v of allViolations) {\n if (disableAllowed && v.hasDisableComment) continue;\n // LINE-BASED: Only include if the violation is on a changed line\n if (!changedLines.has(v.line)) continue;\n\n violations.push({\n file,\n line: v.line,\n column: v.column,\n context: v.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * NEW_AND_MODIFIED_FILES mode: Flag ALL violations in files that were modified.\n */\n// webpieces-disable no-function-outside-class -- the rule engine is inherently functional; validators can't be class members\nfunction findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[], disableAllowed: boolean): DestructureViolation[] {\n const violations: DestructureViolation[] = [];\n\n for (const file of changedFiles) {\n const allViolations = findDestructuringInFile(file, workspaceRoot, disableAllowed);\n\n for (const v of allViolations) {\n if (disableAllowed && v.hasDisableComment) continue;\n\n violations.push({\n file,\n line: v.line,\n column: v.column,\n context: v.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Report violations to console.\n */\n// webpieces-disable max-lines-new-methods -- Console output with examples and escape hatch information\nfunction reportViolations(violations: DestructureViolation[], mode: ModifiedCodeMode, disableAllowed: boolean): void {\n console.error('');\n console.error('\\u274c Destructuring patterns found! Use explicit property access instead.');\n console.error('');\n console.error('\\ud83d\\udcda Avoiding destructuring improves code traceability:');\n console.error('');\n console.error(' BAD: const { name, age } = user;');\n console.error(' GOOD: const name = user.name;');\n console.error(' const age = user.age;');\n console.error('');\n console.error(' BAD: function process({ x, y }: Point) { }');\n console.error(' GOOD: function process(point: Point) { point.x; point.y; }');\n console.error('');\n\n for (const v of violations) {\n console.error(` \\u274c ${v.file}:${v.line}:${v.column}`);\n console.error(` ${v.context}`);\n }\n console.error('');\n\n console.error(' Allowed exceptions:');\n console.error(' - const [a, b] = await Promise.all([...])');\n console.error(' - for (const [key, value] of Object.entries(obj))');\n console.error(' - const { extracted, ...rest } = obj (rest operator separation)');\n console.error('');\n\n if (disableAllowed) {\n console.error(' Escape hatch (use sparingly):');\n console.error(' // webpieces-disable no-destructure -- [your reason]');\n } else {\n console.error(' Escape hatch: DISABLED (disableAllowed: false)');\n console.error(' Disable comments are ignored. Fix the destructuring directly.');\n }\n console.error(' Whole-tree exemption (e.g. React/React Native): add a glob to no-destructure.excludePaths in webpieces.config.json');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n}\n\nasync function runValidatorImpl(\n scan: ScanScope,\n options: NoDestructureConfig,\n workspaceRoot: string\n): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode = options.mode ?? 'OFF';\n const disableAllowed = options.disableAllowed ?? true;\n\n if (mode === 'OFF') {\n console.log('\\n\\u23ed\\ufe0f Skipping no-destructure validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n\\ud83d\\udccf Validating No Destructuring\\n');\n console.log(` Mode: ${mode}`);\n\n let base = process.env['NX_BASE'];\n const head = process.env['NX_HEAD'];\n\n if (!base) {\n base = detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n\\u23ed\\ufe0f Skipping no-destructure validation (could not detect base branch)');\n console.log('');\n return { success: true };\n }\n }\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = scan.files(workspaceRoot, mode, base, head);\n\n if (changedFiles.length === 0) {\n console.log('\\u2705 No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`\\ud83d\\udcc2 Checking ${changedFiles.length} changed file(s)...`);\n\n let violations: DestructureViolation[] = [];\n\n if (mode === 'NEW_AND_MODIFIED_CODE') {\n violations = findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);\n } else {\n // NEW_AND_MODIFIED_FILES and the whole-scope modes (#1027) all judge every site of every file.\n violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);\n }\n\n if (violations.length === 0) {\n console.log('\\u2705 No destructuring patterns found');\n return { success: true };\n }\n\n scan.recordSites('no-destructure', violations.map((v: DestructureViolation) => v.file));\n reportViolations(violations, mode, disableAllowed);\n\n return { success: false };\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoDestructureValidator extends CodeValidator<NoDestructureConfig> {\n constructor(config: NoDestructureConfig, private readonly scanScope: ScanScope) {\n super(config, 'no-destructure', 'no-destructure');\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n return runValidatorImpl(this.scanScope, this.config, workspaceRoot);\n }\n}\n"]}
1
+ {"version":3,"file":"validate-no-destructure.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-destructure.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;;AAiHH,0DAuDC;;AAtKD,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAqG;AACrG,yDAA6D;AAE7D,qDAAiE;AACjE,yCAA2D;AAC3D,6CAAyC;AASzC;;GAEG;AACH,SAAS,iBAAiB,CAAC,KAAe,EAAE,UAAkB;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QAChD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClF,MAAM;QACV,CAAC;QACD,IAAI,IAAA,yBAAU,EAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,IAA4B;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACpD,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACvC,IA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,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AARY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEjB,kCAAmB,EAA8B,sBAAS;GADrE,sBAAsB,CAQlC","sourcesContent":["/**\n * Validate No Destructure Executor\n *\n * Validates that destructuring patterns are not used in TypeScript code.\n * Uses LINE-BASED detection (not method-based) for git diff filtering.\n *\n * ============================================================================\n * VIOLATIONS (BAD) - These patterns are flagged:\n * ============================================================================\n *\n * - const { x, y } = obj — object destructuring in variable declarations\n * - const [a, b] = fn() — array destructuring (except Promise.all)\n * - for (const { email } of items) — object destructuring in for-of loops\n * - for (const [a, b] of items) — array destructuring in for-of (except Object.entries)\n * - const { page = 0 } = opts — destructuring with defaults\n * - const { done: streamDone } = obj — destructuring with renaming\n * - function foo({ x, y }: Type) — function parameter destructuring\n *\n * ============================================================================\n * ALLOWED (skip — NOT violations)\n * ============================================================================\n *\n * - const [a, b] = await Promise.all([...]) — Promise.all array destructuring\n * - for (const [key, value] of Object.entries(obj)) — Object.entries in for-of\n * - const { extracted, ...rest } = obj — rest operator separation\n * - Lines with // webpieces-disable no-destructure -- [reason] (only when disableAllowed: true)\n * - Files under the rule's `excludePaths` (or the top-level one), dropped by the framework before the\n * rule runs — e.g. a React/React Native tree, where useState and destructured props are the\n * framework's own idiom. This is the ONLY escape when disableAllowed: false.\n *\n * ============================================================================\n * MODES (LINE-BASED)\n * ============================================================================\n * - OFF: Skip validation entirely\n * - NEW_AND_MODIFIED_CODE: Flag destructuring on changed lines (lines in diff hunks)\n * - NEW_AND_MODIFIED_FILES: Flag ALL destructuring in files that were modified\n *\n * ============================================================================\n * ESCAPE HATCH\n * ============================================================================\n * Add comment above the violation:\n * // webpieces-disable no-destructure -- [your justification]\n * const { x, y } = obj;\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { hasDisable, detectBase, getFileDiff, getChangedLineNumbers } from \"@webpieces/rules-config\";\nimport { NoDestructureConfig } from \"./configs/rule-configs\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ScanScope } from './scan-scope';\n\ninterface DestructureViolation {\n file: string;\n line: number;\n column: number;\n context: string;\n}\n\n/**\n * Check if a line contains a webpieces-disable comment for no-destructure.\n */\nfunction hasDisableComment(lines: string[], lineNumber: number): boolean {\n const startCheck = Math.max(0, lineNumber - 5);\n for (let i = lineNumber - 2; i >= startCheck; i--) {\n const line = lines[i]?.trim() ?? '';\n if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {\n break;\n }\n if (hasDisable(line, \"no-destructure\")) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Check if an ArrayBindingPattern's initializer is `await Promise.all(...)`.\n */\nfunction isPromiseAllDestructure(node: ts.ArrayBindingPattern): boolean {\n const parent = node.parent;\n if (!ts.isVariableDeclaration(parent)) return false;\n const initializer = parent.initializer;\n if (!initializer) return false;\n\n // Handle: const [a, b] = await Promise.all([...])\n if (ts.isAwaitExpression(initializer)) {\n const awaitedExpr = initializer.expression;\n if (ts.isCallExpression(awaitedExpr)) {\n const callExpr = awaitedExpr.expression;\n // Promise.all(...)\n if (ts.isPropertyAccessExpression(callExpr) && callExpr.name.text === 'all') {\n const obj = callExpr.expression;\n if (ts.isIdentifier(obj) && obj.text === 'Promise') {\n return true;\n }\n }\n }\n }\n\n return false;\n}\n\n/**\n * Check if an ArrayBindingPattern in a for-of loop iterates over Object.entries(...).\n */\nfunction isObjectEntriesForOf(node: ts.ArrayBindingPattern): boolean {\n // Walk up: ArrayBindingPattern -> VariableDeclaration -> VariableDeclarationList -> ForOfStatement\n const varDecl = node.parent;\n if (!ts.isVariableDeclaration(varDecl)) return false;\n\n const varDeclList = varDecl.parent;\n if (!ts.isVariableDeclarationList(varDeclList)) return false;\n\n const forOfStmt = varDeclList.parent;\n if (!ts.isForOfStatement(forOfStmt)) return false;\n\n // Check iterable expression ends with .entries()\n const iterable = forOfStmt.expression;\n if (ts.isCallExpression(iterable)) {\n const callExpr = iterable.expression;\n if (ts.isPropertyAccessExpression(callExpr) && callExpr.name.text === 'entries') {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Check if an ObjectBindingPattern contains a rest element (...rest).\n */\nfunction hasRestElement(node: ts.ObjectBindingPattern): boolean {\n for (const element of node.elements) {\n if (element.dotDotDotToken) {\n return true;\n }\n }\n return false;\n}\n\nexport interface DestructureInfo {\n line: number;\n column: number;\n context: string;\n hasDisableComment: boolean;\n}\n\n/**\n * Find all destructuring patterns in a file using AST.\n */\n// webpieces-disable max-lines-new-methods -- AST traversal with multiple destructuring pattern checks and exception detection\n// webpieces-disable no-function-outside-class -- the rule engine is inherently functional; validators can't be class members\nexport function findDestructuringInFile(filePath: string, workspaceRoot: string, disableAllowed: boolean): DestructureInfo[] {\n // Guard on the REPO-RELATIVE path, before the join below — globs like `mobile/**` never match an\n // absolute path. This is the only escape when disableAllowed is false.\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const fileLines = content.split('\\n');\n const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);\n\n const violations: DestructureInfo[] = [];\n\n // webpieces-disable max-lines-new-methods -- AST visitor needs to handle object/array binding patterns in declarations, for-of, and parameters\n function visit(node: ts.Node): void {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // Check ObjectBindingPattern\n if (ts.isObjectBindingPattern(node)) {\n // Exception: rest operator separation\n if (hasRestElement(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n const context = getDestructureContext(node);\n recordViolation(node, context, fileLines, sourceFile, violations, disableAllowed);\n }\n\n // Check ArrayBindingPattern\n if (ts.isArrayBindingPattern(node)) {\n // Exception: Promise.all destructure\n if (isPromiseAllDestructure(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n // Exception: Object.entries in for-of\n if (isObjectEntriesForOf(node)) {\n ts.forEachChild(node, visit);\n return;\n }\n\n const context = getDestructureContext(node);\n recordViolation(node, context, fileLines, sourceFile, violations, disableAllowed);\n }\n } catch (err: unknown) {\n //const error = toError(err);\n // Skip nodes that cause errors during analysis\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return violations;\n}\n\nfunction recordViolation(\n node: ts.Node,\n context: string,\n fileLines: string[],\n sourceFile: ts.SourceFile,\n violations: DestructureInfo[],\n disableAllowed: boolean,\n): void {\n const startPos = node.getStart(sourceFile);\n if (startPos >= 0) {\n const pos = sourceFile.getLineAndCharacterOfPosition(startPos);\n const line = pos.line + 1;\n const column = pos.character + 1;\n const disabled = hasDisableComment(fileLines, line);\n\n if (!disableAllowed && disabled) {\n // When disableAllowed is false, ignore disable comments — still a violation\n violations.push({ line, column, context, hasDisableComment: false });\n } else {\n violations.push({ line, column, context, hasDisableComment: disabled });\n }\n }\n}\n\n/**\n * Get a description of where the destructuring pattern appears.\n */\nfunction getDestructureContext(node: ts.Node): string {\n const parent = node.parent;\n if (ts.isParameter(parent)) {\n return 'function parameter destructuring';\n }\n if (ts.isVariableDeclaration(parent)) {\n const grandparent = parent.parent;\n if (grandparent && ts.isVariableDeclarationList(grandparent)) {\n const forOfParent = grandparent.parent;\n if (forOfParent && ts.isForOfStatement(forOfParent)) {\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring in for-of loop'\n : 'array destructuring in for-of loop';\n }\n }\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring in variable declaration'\n : 'array destructuring in variable declaration';\n }\n return ts.isObjectBindingPattern(node)\n ? 'object destructuring'\n : 'array destructuring';\n}\n\n/**\n * NEW_AND_MODIFIED_CODE mode: Flag violations on changed lines in diff hunks.\n */\n// webpieces-disable max-lines-new-methods, no-function-outside-class -- File iteration with diff parsing and line filtering\nasync function findViolationsForModifiedCode(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head: string | undefined,\n disableAllowed: boolean,\n): Promise<DestructureViolation[]> {\n const violations: DestructureViolation[] = [];\n\n for (const file of changedFiles) {\n const diff = await getFileDiff(workspaceRoot, file, base, head);\n const changedLines = getChangedLineNumbers(diff);\n\n if (changedLines.size === 0) continue;\n\n const allViolations = findDestructuringInFile(file, workspaceRoot, disableAllowed);\n\n for (const v of allViolations) {\n if (disableAllowed && v.hasDisableComment) continue;\n // LINE-BASED: Only include if the violation is on a changed line\n if (!changedLines.has(v.line)) continue;\n\n violations.push({\n file,\n line: v.line,\n column: v.column,\n context: v.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * NEW_AND_MODIFIED_FILES mode: Flag ALL violations in files that were modified.\n */\n// webpieces-disable no-function-outside-class -- the rule engine is inherently functional; validators can't be class members\nfunction findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[], disableAllowed: boolean): DestructureViolation[] {\n const violations: DestructureViolation[] = [];\n\n for (const file of changedFiles) {\n const allViolations = findDestructuringInFile(file, workspaceRoot, disableAllowed);\n\n for (const v of allViolations) {\n if (disableAllowed && v.hasDisableComment) continue;\n\n violations.push({\n file,\n line: v.line,\n column: v.column,\n context: v.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Report violations to console.\n */\n// webpieces-disable max-lines-new-methods -- Console output with examples and escape hatch information\nfunction reportViolations(violations: DestructureViolation[], mode: ModifiedCodeMode, disableAllowed: boolean): void {\n console.error('');\n console.error('\\u274c Destructuring patterns found! Use explicit property access instead.');\n console.error('');\n console.error('\\ud83d\\udcda Avoiding destructuring improves code traceability:');\n console.error('');\n console.error(' BAD: const { name, age } = user;');\n console.error(' GOOD: const name = user.name;');\n console.error(' const age = user.age;');\n console.error('');\n console.error(' BAD: function process({ x, y }: Point) { }');\n console.error(' GOOD: function process(point: Point) { point.x; point.y; }');\n console.error('');\n\n for (const v of violations) {\n console.error(` \\u274c ${v.file}:${v.line}:${v.column}`);\n console.error(` ${v.context}`);\n }\n console.error('');\n\n console.error(' Allowed exceptions:');\n console.error(' - const [a, b] = await Promise.all([...])');\n console.error(' - for (const [key, value] of Object.entries(obj))');\n console.error(' - const { extracted, ...rest } = obj (rest operator separation)');\n console.error('');\n\n if (disableAllowed) {\n console.error(' Escape hatch (use sparingly):');\n console.error(' // webpieces-disable no-destructure -- [your reason]');\n } else {\n console.error(' Escape hatch: DISABLED (disableAllowed: false)');\n console.error(' Disable comments are ignored. Fix the destructuring directly.');\n }\n console.error(' Whole-tree exemption (e.g. React/React Native): add a glob to no-destructure.excludePaths in webpieces.config.json');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n}\n\nasync function runValidatorImpl(\n scan: ScanScope,\n options: NoDestructureConfig,\n workspaceRoot: string\n): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode = options.mode ?? 'OFF';\n const disableAllowed = options.disableAllowed ?? true;\n\n if (mode === 'OFF') {\n console.log('\\n\\u23ed\\ufe0f Skipping no-destructure validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n\\ud83d\\udccf Validating No Destructuring\\n');\n console.log(` Mode: ${mode}`);\n\n let base = process.env['NX_BASE'];\n const head = process.env['NX_HEAD'];\n\n if (!base) {\n base = await detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n\\u23ed\\ufe0f Skipping no-destructure validation (could not detect base branch)');\n console.log('');\n return { success: true };\n }\n }\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = await scan.files(workspaceRoot, mode, base, head);\n\n if (changedFiles.length === 0) {\n console.log('\\u2705 No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`\\ud83d\\udcc2 Checking ${changedFiles.length} changed file(s)...`);\n\n let violations: DestructureViolation[] = [];\n\n if (mode === 'NEW_AND_MODIFIED_CODE') {\n violations = await findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);\n } else {\n // NEW_AND_MODIFIED_FILES and the whole-scope modes (#1027) all judge every site of every file.\n violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);\n }\n\n if (violations.length === 0) {\n console.log('\\u2705 No destructuring patterns found');\n return { success: true };\n }\n\n scan.recordSites('no-destructure', violations.map((v: DestructureViolation) => v.file));\n reportViolations(violations, mode, disableAllowed);\n\n return { success: false };\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoDestructureValidator extends CodeValidator<NoDestructureConfig> {\n constructor(config: NoDestructureConfig, private readonly scanScope: ScanScope) {\n super(config, 'no-destructure', 'no-destructure');\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n return runValidatorImpl(this.scanScope, this.config, workspaceRoot);\n }\n}\n"]}
@@ -173,11 +173,11 @@ function findViolationsInFile(filePath, workspaceRoot, disableAllowed) {
173
173
  /**
174
174
  * NEW_AND_MODIFIED_CODE mode: Flag violations on changed lines in diff hunks.
175
175
  */
176
- // webpieces-disable max-lines-new-methods -- File iteration with diff parsing and line filtering
177
- function findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
176
+ // webpieces-disable max-lines-new-methods, no-function-outside-class -- File iteration with diff parsing and line filtering
177
+ async function findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
178
178
  const violations = [];
179
179
  for (const file of changedFiles) {
180
- const diff = (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
180
+ const diff = await (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
181
181
  const changedLines = (0, rules_config_1.getChangedLineNumbers)(diff);
182
182
  if (changedLines.size === 0)
183
183
  continue;
@@ -309,11 +309,11 @@ function findMethodRanges(filePath, workspaceRoot) {
309
309
  * - For *.routes.ts: If any line in a route object is changed, flag all inject(XxxApi) violations in that route
310
310
  * - For *.component.ts: If a method is new/modified, flag all snapshot.data violations in that method
311
311
  */
312
- // webpieces-disable max-lines-new-methods -- Method-scoped validation with route objects and component methods
313
- function findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed) {
312
+ // webpieces-disable max-lines-new-methods, no-function-outside-class -- Method-scoped validation with route objects and component methods
313
+ async function findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed) {
314
314
  const violations = [];
315
315
  for (const file of changedFiles) {
316
- const diff = (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
316
+ const diff = await (0, rules_config_1.getFileDiff)(workspaceRoot, file, base, head);
317
317
  const changedLines = (0, rules_config_1.getChangedLineNumbers)(diff);
318
318
  const newMethodNames = (0, rules_config_1.findNewMethodSignaturesInDiff)(diff);
319
319
  if (changedLines.size === 0 && newMethodNames.size === 0)
@@ -447,7 +447,7 @@ async function runValidatorImpl(options, workspaceRoot) {
447
447
  let base = process.env['NX_BASE'];
448
448
  const head = process.env['NX_HEAD'];
449
449
  if (!base) {
450
- base = (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
450
+ base = await (0, rules_config_1.detectBase)(workspaceRoot) ?? undefined;
451
451
  if (!base) {
452
452
  console.log('\n\u23ed\ufe0f Skipping no-direct-api-resolver validation (could not detect base branch)');
453
453
  console.log('');
@@ -457,7 +457,7 @@ async function runValidatorImpl(options, workspaceRoot) {
457
457
  console.log(` Base: ${base}`);
458
458
  console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
459
459
  console.log('');
460
- const allChangedFiles = (0, rules_config_1.getChangedFiles)(workspaceRoot, base, head);
460
+ const allChangedFiles = await (0, rules_config_1.getChangedFiles)(workspaceRoot, base, head);
461
461
  const scopedFiles = filterByEnforcePaths(allChangedFiles, options.enforcePaths);
462
462
  const changedFiles = filterRelevantFiles(scopedFiles);
463
463
  if (changedFiles.length === 0) {
@@ -467,10 +467,10 @@ async function runValidatorImpl(options, workspaceRoot) {
467
467
  console.log(`\ud83d\udcc2 Checking ${changedFiles.length} changed file(s)...`);
468
468
  let violations = [];
469
469
  if (mode === 'NEW_AND_MODIFIED_CODE') {
470
- violations = findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);
470
+ violations = await findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);
471
471
  }
472
472
  else if (mode === 'NEW_AND_MODIFIED_METHODS') {
473
- violations = findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed);
473
+ violations = await findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed);
474
474
  }
475
475
  else if (mode === 'NEW_AND_MODIFIED_FILES') {
476
476
  violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);