boilersuite

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// YearMarkerRegex matches the marker which should appear in boilerplate sample files but not in actual files
	YearMarkerRegex = regexp.MustCompile(`<<YEAR>>`)

	// AuthorMarkerRegex matches the marker which should appear in boilerplate sample files but not in actual files
	AuthorMarkerRegex = regexp.MustCompile(`<<AUTHOR>>`)

	// DateRegex matches the actual date found inside a file
	DateRegex = regexp.MustCompile(`Copyright 20\d\d`)

	// BuildConstraintsRegex matches golang build constraints
	BuildConstraintsRegex = regexp.MustCompile(`(?m)^(\/\/(go:build| \+build).*\n)+$`)

	// ShebangRegex matches shebangs in scripts; most shebangs should be on the first line
	// but we use a multiline here to be safe
	ShebangRegex = regexp.MustCompile(`(?m)^#!.*\n`)

	// SkipFileRegex matches files which should not be validated
	SkipFileRegex = regexp.MustCompile(`(?m)^(\/\/|#) \+skip_license_check$`)

	// GeneratedRegex matches comments added by k8s code generators
	GeneratedRegex = regexp.MustCompile(`(?m)^[\/*#]+.*DO NOT EDIT\.$`)
)

Functions

This section is empty.

Types

type BoilerplateTemplate

type BoilerplateTemplate struct {
	// contains filtered or unexported fields
}

BoilerplateTemplate takes a raw template as input and pre-processes it so it's ready for use during validation.

func NewBoilerplateTemplate

func NewBoilerplateTemplate(raw string, config BoilerplateTemplateConfiguration) (BoilerplateTemplate, error)

NewBoilerplateTemplate creates a new boilerplate template using the given raw template and configuration

func (BoilerplateTemplate) Validate

func (t BoilerplateTemplate) Validate(raw string) error

Validate checks the given raw input file against the template

type BoilerplateTemplateConfiguration

type BoilerplateTemplateConfiguration struct {
	// ExpectedAuthor contains the name of the author expected to be found in
	// the template. Related to the <<AUTHOR>> marker.
	ExpectedAuthor string

	// NormalizationFunc is an optional extra normalization step to take for
	// files matched by this template. For example, in go files we might need
	// to remove golang build constraints
	NormalizationFunc func(string) string
}

BoilerplateTemplateConfiguration holds configuration values which can be used for pre-processing a template

type TemplateMap

type TemplateMap map[string]BoilerplateTemplate

func LoadTemplates

func LoadTemplates(templateDir embed.FS, expectedAuthor string) (TemplateMap, error)

LoadTemplates attempts to read all of the templates under the given embedded filesystem and return a TemplateMap which can be used for fetching templates later.

func (TemplateMap) TemplateFor

func (tm TemplateMap) TemplateFor(path string) (BoilerplateTemplate, bool)

TemplateMap returns a template which matches the given name, if one exists in the map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL