Background
The provider-generator (packages/@cdktn/provider-generator) outputs TypeScript bindings consumed as real source code by downstream projects. When the demo harness was moved to ESM with Node native type-stripping (--experimental-strip-types), three defects surfaced that were invisible to the existing test suite (snapshot tests + jsii compilation):
- Missing
/index in ESM imports — nodenext resolution looks for ../provider-functions.js, not ../provider-functions/index.js
- TypeScript parameter properties —
constructor(private readonly x: T) is NOT pure type erasure; the compiler synthesizes an assignment, so Node type-stripping throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX
T[] binding ambiguity with union types — boolean | cdktn.IResolvable[] binds differently from Array<boolean | cdktn.IResolvable>
All three were fixed in #296, but they were only caught by exercising the generated code manually — not by any automated linting.
Problem
Generated code is never linted. The repo has ESLint flat configs, but generated output in providers/<provider>/ is never pointed at them. Patterns that are valid TypeScript but incompatible with Node type-stripping, ESM resolution, or modern best practices can ship in generated code without detection.
Proposed Solution
Add a linting step to the provider-generator test/CI pipeline that runs ESLint over generated output with a targeted ruleset.
Suggested ESLint rules
| Rule |
What it catches |
import/no-unresolved |
Broken ESM import paths (would have caught the missing /index) |
import/extensions |
Missing .js extensions in ESM-relative imports |
@typescript-eslint/consistent-type-imports |
Imports that should be import type (ensures type-stripper erasability) |
@typescript-eslint/no-explicit-any |
any types in generated signatures (force deliberate usage) |
@typescript-eslint/no-unused-vars |
Unused imports or unreferenced constructor params |
no-duplicate-imports |
Duplicate imports in generated struct shards |
Integration considerations
- Disable formatting rules (
prettier/prettier) — formatting is the generator's job
- Disable
@nx/enforce-module-boundaries — generated code has no Nx project context
- The generator uses
import * as cdktn from 'cdktn' namespace imports — may need inline disable or rule override for no-unused-vars
any types are intentional for unknown Terraform provider shapes, but lint enforcement forces deliberate // eslint-disable-next-line usage
Related
Flagged during review of PR #296 by @so0k.
Background
The provider-generator (
packages/@cdktn/provider-generator) outputs TypeScript bindings consumed as real source code by downstream projects. When the demo harness was moved to ESM with Node native type-stripping (--experimental-strip-types), three defects surfaced that were invisible to the existing test suite (snapshot tests + jsii compilation):/indexin ESM imports —nodenextresolution looks for../provider-functions.js, not../provider-functions/index.jsconstructor(private readonly x: T)is NOT pure type erasure; the compiler synthesizes an assignment, so Node type-stripping throwsERR_UNSUPPORTED_TYPESCRIPT_SYNTAXT[]binding ambiguity with union types —boolean | cdktn.IResolvable[]binds differently fromArray<boolean | cdktn.IResolvable>All three were fixed in #296, but they were only caught by exercising the generated code manually — not by any automated linting.
Problem
Generated code is never linted. The repo has ESLint flat configs, but generated output in
providers/<provider>/is never pointed at them. Patterns that are valid TypeScript but incompatible with Node type-stripping, ESM resolution, or modern best practices can ship in generated code without detection.Proposed Solution
Add a linting step to the provider-generator test/CI pipeline that runs ESLint over generated output with a targeted ruleset.
Suggested ESLint rules
import/no-unresolved/index)import/extensions.jsextensions in ESM-relative imports@typescript-eslint/consistent-type-importsimport type(ensures type-stripper erasability)@typescript-eslint/no-explicit-anyanytypes in generated signatures (force deliberate usage)@typescript-eslint/no-unused-varsno-duplicate-importsIntegration considerations
prettier/prettier) — formatting is the generator's job@nx/enforce-module-boundaries— generated code has no Nx project contextimport * as cdktn from 'cdktn'namespace imports — may need inline disable or rule override forno-unused-varsanytypes are intentional for unknown Terraform provider shapes, but lint enforcement forces deliberate// eslint-disable-next-lineusageRelated
provider-functions-emitter.ts:40-46— the parameter-property avoidance commentFlagged during review of PR #296 by @so0k.