Documentation
¶
Overview ¶
Package processors provides built-in post-processors for common use cases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddGeneratedHeader ¶
type AddGeneratedHeader struct {
// Generator is the name of the generator to include in the header
Generator string
// FileTypes specifies which file extensions to process (e.g., []string{".go", ".java"})
// If empty, processes all files
FileTypes []string
}
AddGeneratedHeader adds a "Code generated" header to files. This helps identify generated files and discourages manual editing.
func NewAddGeneratedHeader ¶
func NewAddGeneratedHeader(generator string, fileTypes ...string) *AddGeneratedHeader
NewAddGeneratedHeader creates a new header processor.
func (*AddGeneratedHeader) ProcessContent ¶
func (a *AddGeneratedHeader) ProcessContent(filePath string, content []byte) ([]byte, error)
ProcessContent adds a generated header to the beginning of the file.
type GoImports ¶
type GoImports struct {
// TabWidth sets the tab width for formatting (default: 8)
TabWidth int
// TabIndent determines whether to use tabs for indentation (default: true)
TabIndent bool
// AllErrors determines whether to report all errors or just the first (default: false)
AllErrors bool
// Comments determines whether to update comments (default: true)
Comments bool
}
GoImports is a post-processor that fixes imports and formats Go source files. It uses goimports to organize imports and gofmt as a fallback.
Example usage:
eng := engine.New() eng.AddPostProcessor(processors.NewGoImports())
func NewGoImports ¶
func NewGoImports() *GoImports
NewGoImports creates a new Go imports processor with sensible defaults.
type RegexReplace ¶
type RegexReplace struct {
// Pattern is the regular expression to match
Pattern *regexp.Regexp
// Replacement is the replacement string (can include capture groups like $1, $2)
Replacement string
// FilePattern optionally limits processing to files matching this pattern
FilePattern *regexp.Regexp
}
RegexReplace is a processor that applies regex replacements to file content. It's useful for custom transformations that can't be easily expressed otherwise.
func NewRegexReplace ¶
func NewRegexReplace(pattern, replacement string) (*RegexReplace, error)
NewRegexReplace creates a new regex replacement processor.
func (*RegexReplace) ProcessContent ¶
func (r *RegexReplace) ProcessContent(filePath string, content []byte) ([]byte, error)
ProcessContent applies the regex replacement to the file content.
func (*RegexReplace) WithFilePattern ¶
func (r *RegexReplace) WithFilePattern(filePattern string) (*RegexReplace, error)
WithFilePattern adds a file pattern filter to the processor.
type TrimWhitespace ¶
type TrimWhitespace struct{}
TrimWhitespace is a processor that trims trailing whitespace from all lines. It's useful for cleaning up generated files.
func NewTrimWhitespace ¶
func NewTrimWhitespace() *TrimWhitespace
NewTrimWhitespace creates a new whitespace trimming processor.
func (*TrimWhitespace) ProcessContent ¶
func (t *TrimWhitespace) ProcessContent(filePath string, content []byte) ([]byte, error)
ProcessContent trims trailing whitespace from each line.