Documentation
¶
Overview ¶
Package gensection provides a reusable engine for marker-based generated-section rules. A Directive implementation supplies rule-specific validation and content generation, while the Engine handles marker parsing, YAML extraction, content comparison, and fix (replacement) logic.
Index ¶
- func CollectIgnoredLines(f *lint.File, startPrefix, endMarker string) map[int]bool
- func EnsureTrailingNewline(s string) string
- func ExtractColumnsRaw(rawMap map[string]any) map[string]any
- func ExtractContent(f *lint.File, mp MarkerPair) string
- func MakeDiag(ruleID, ruleName, filePath string, line int, message string) lint.Diagnostic
- func ParseColumnConfig(raw map[string]any) map[string]ColumnConfig
- func ParseYAMLBody(filePath string, mp MarkerPair, ruleID, ruleName string) (map[string]any, []lint.Diagnostic)
- func ReplaceContent(f *lint.File, mp MarkerPair, content string) []byte
- func SplitLines(source []byte) [][]byte
- func ValidateStringParams(filePath string, line int, rawMap map[string]any, ruleID, ruleName string) (map[string]string, []lint.Diagnostic)
- type ColumnConfig
- type Directive
- type Engine
- type MarkerPair
- type ParsedDirective
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectIgnoredLines ¶
CollectIgnoredLines returns a set of 1-based line numbers inside fenced code blocks or HTML blocks, where markers should be ignored.
func EnsureTrailingNewline ¶
EnsureTrailingNewline appends \n if s does not already end with \n.
func ExtractColumnsRaw ¶
ExtractColumnsRaw removes and returns the "columns" key from rawMap.
func ExtractContent ¶
func ExtractContent(f *lint.File, mp MarkerPair) string
ExtractContent returns the content between markers as a string.
func MakeDiag ¶
func MakeDiag(ruleID, ruleName, filePath string, line int, message string) lint.Diagnostic
MakeDiag creates an error diagnostic at the given line using the provided rule ID and name.
func ParseColumnConfig ¶
func ParseColumnConfig(raw map[string]any) map[string]ColumnConfig
ParseColumnConfig parses the raw YAML columns map into ColumnConfig entries.
func ParseYAMLBody ¶
func ParseYAMLBody( filePath string, mp MarkerPair, ruleID, ruleName string, ) (map[string]any, []lint.Diagnostic)
ParseYAMLBody unmarshals the YAML body of a marker pair.
func ReplaceContent ¶
func ReplaceContent(f *lint.File, mp MarkerPair, content string) []byte
ReplaceContent replaces the content between markers with new content.
func SplitLines ¶
SplitLines splits source into lines (like bytes.Split but returns [][]byte).
Types ¶
type ColumnConfig ¶
type ColumnConfig struct {
MaxWidth int // maximum width for the column content
Wrap string // "truncate" (default) or "br"
}
ColumnConfig holds per-column width and wrapping configuration.
type Directive ¶
type Directive interface {
// Name returns the directive/rule name used in markers
// (e.g., "catalog"). Markers are derived as:
// start: "<!-- " + Name()
// end: "<!-- /" + Name() + " -->"
Name() string
// RuleID returns the lint rule ID (e.g., "MDS019").
RuleID() string
// RuleName returns the lint rule name (e.g., "catalog").
RuleName() string
// Validate checks directive-specific parameters. Returns
// diagnostics for invalid params.
Validate(filePath string, line int, params map[string]string,
columns map[string]ColumnConfig) []lint.Diagnostic
// Generate produces the expected content between markers.
// Returns content and any diagnostics.
Generate(f *lint.File, filePath string, line int,
params map[string]string,
columns map[string]ColumnConfig) (string, []lint.Diagnostic)
}
Directive defines a generated-section rule that produces content from markers.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates Check/Fix using a registered Directive.
type MarkerPair ¶
type MarkerPair struct {
StartLine int // 1-based line of start marker
EndLine int // 1-based line of end marker
ContentFrom int // 1-based line of the first content line
ContentTo int // 1-based line of the last content line
FirstLine string
YAMLBody string
}
MarkerPair holds the line numbers and parsed content of a start/end marker pair.
func FindMarkerPairs ¶
func FindMarkerPairs( f *lint.File, startPrefix, endMarker, ruleID, ruleName string, ) ([]MarkerPair, []lint.Diagnostic)
FindMarkerPairs scans the file for start/end marker pairs, skipping markers inside code blocks or HTML blocks. The startPrefix and endMarker are derived from the directive name.
type ParsedDirective ¶
type ParsedDirective struct {
Name string
Params map[string]string
Columns map[string]ColumnConfig
}
ParsedDirective holds the parsed directive from a marker pair.
func ParseDirective ¶
func ParseDirective( filePath string, mp MarkerPair, ruleID, ruleName string, ) (*ParsedDirective, []lint.Diagnostic)
ParseDirective extracts the YAML parameters from a marker pair.