Skip to content

Lint generated provider bindings with ESLint to catch ESM/Node type-stripping incompatibilities #344

Description

@sakul-learning

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):

  1. Missing /index in ESM importsnodenext resolution looks for ../provider-functions.js, not ../provider-functions/index.js
  2. TypeScript parameter propertiesconstructor(private readonly x: T) is NOT pure type erasure; the compiler synthesizes an assignment, so Node type-stripping throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX
  3. T[] binding ambiguity with union typesboolean | 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions