feat: Add header comment generator configuration option#722
Merged
Conversation
- 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>
…heck directives" This reverts commit 8972c27.
- 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>
…eritance" This reverts commit 11cc74b.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Generated code can be confusing without clear markers indicating its origin. This PR adds a configurable
HeaderCommentoption that allows developers to emit informative comments at the start of generated files, helping prevent accidental edits and documenting the generation source.Changes
HeaderCommentproperty on theGeneratorbase class with[GeneratorConfig]attributeCompositeGeneratorso child generators inherit parent header comments unless they define their ownStringBuilderFileGeneratorto prepend formatted comments to generated outputcoalesce-vue3.jsonfor the playground andCreateVitestTargetstest.prettierignorefile added to repo root to ignore generated*.g.tsand*.g.tsxfilesUsage
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:
Notes
//comment prefix since Coalesce only generates TypeScript, JavaScript, and C# files