Skip to content

feat: Add header comment generator configuration option#722

Merged
ascott18 merged 10 commits into
mainfrom
ascott18/glowing-winner
May 21, 2026
Merged

feat: Add header comment generator configuration option#722
ascott18 merged 10 commits into
mainfrom
ascott18/glowing-winner

Conversation

@ascott18
Copy link
Copy Markdown
Collaborator

Motivation

Generated code can be confusing without clear markers indicating its origin. This PR adds a configurable HeaderComment option that allows developers to emit informative comments at the start of generated files, helping prevent accidental edits and documenting the generation source.

Changes

  • New HeaderComment property on the Generator base class with [GeneratorConfig] attribute
  • Cascading config support in CompositeGenerator so child generators inherit parent header comments unless they define their own
  • Implementation in StringBuilderFileGenerator to prepend formatted comments to generated output
  • Default configurations in coalesce-vue3.json for the playground and CreateVitestTargets test
  • .prettierignore file added to repo root to ignore generated *.g.ts and *.g.tsx files

Usage

Configure header comments in coalesce.json:

{
  "generatorConfig": {
    "Scripts": {
      "headerComment": "Generated code - do not edit directly. Generated with: pnpm coalesce"
    }
  }
}

Child generators (TsMetadata, TsModels, etc.) automatically inherit the parent's header comment through the cascading system.

Generated Output

Generated TypeScript files now include a header comment for clarity:

// Generated code - do not edit directly. Generated with: pnpm coalesce

import { ... }

Notes

  • The feature uses simple // comment prefix since Coalesce only generates TypeScript, JavaScript, and C# files
  • Header comments are placed after ESLint/Prettier directives (if added in the future)
  • All tests pass; CreateVitestTargets test validates the feature

ascott18 and others added 10 commits May 21, 2026 10:06
- Add HeaderComment property to Generator base class with [GeneratorConfig] attribute
- Implement PrependHeaderComment in StringBuilderFileGenerator to emit comments at file start
- Support multiple language comment styles (// and # based)
- Update CreateVitestTargets test to configure header comments on generated TypeScript files
- Update coalesce-vue3.json playground config to explain generated code source
- Add blank line after comments for better code formatting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Define headerComment once on Scripts parent generator instead of duplicating on child generators
- Implement cascading in CompositeGenerator.Generator<T>() to pass parent HeaderComment to children
- Child generators inherit parent's headerComment unless they have their own config
- Simplifies config and follows DRY principle

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ectives

- Add DisableLinting property (bool?, default true) to Generator
- Prepend ESLint, Prettier, and TypeScript directives to generated TS files
- Only applies to .ts and .tsx files
- Can be disabled per generator via config
- Directives placed before header comment for proper file structure

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Ignore *.g.ts and *.g.tsx files in prettier formatting
- Added to repo root for development
- Added to template content for generated projects

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ascott18 ascott18 merged commit f3e4ca9 into main May 21, 2026
17 checks passed
@ascott18 ascott18 deleted the ascott18/glowing-winner branch May 21, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant