Documentation ¶
Index ¶
- Constants
- Variables
- type Action
- type Config
- type Copyright
- func (c Copyright) Debugf(format string, args ...interface{})
- func (c Copyright) Errorf(format string, args ...interface{})
- func (c Copyright) GetStderr() io.Writer
- func (c Copyright) GetStdout() io.Writer
- func (c Copyright) Inject(ctx context.Context, root string) error
- func (c Copyright) Printf(format string, args ...interface{})
- func (c Copyright) Remove(ctx context.Context, root string) error
- func (c Copyright) Verbosef(format string, args ...interface{})
- func (c Copyright) Verify(ctx context.Context, root string) error
- func (c Copyright) Walk(ctx context.Context, action Action, root string) error
- type Extension
Constants ¶
const ( TemplateFieldYear = "Year" TemplateFieldCopyrightHolder = "CopyrightHolder" TemplateFieldLicense = "License" TemplateFieldRestrictions = "Restrictions" )
const DefaultCopyrightHolder = ""
DefaultCopyrightHolder is the default copyright holder to inject into the notice template.
As of writing, it's blank. You'll want to provide it!
const DefaultNoticeTemplate = `` /* 137-byte string literal not displayed */
DefaultNoticeBodyTemplate is the default notice body template.
const DefaultOpenSourceLicense = "MIT"
DefaultOpenSourceLicense is the default open source license.
const DefaultRestrictionsTemplate = `` /* 132-byte string literal not displayed */
DefaultRestrictionsOpenSource are the default open source restrictions.
const DefaultRestrictionsTemplateInternal = "{{ if .CopyrightHolder }}{{ .CopyrightHolder }} {{ end }}Confidential - Restricted"
DefaultRestrictionsTemplateInternal are the default copyright restrictions to inject into the notice template.
Variables ¶
var ( // KnownExtensions is a list of all the known extensions. KnownExtensions = []Extension{ ExtensionCSS, ExtensionGo, ExtensionHTML, ExtensionJS, ExtensionJSX, ExtensionPy, ExtensionSCSS, ExtensionSASS, ExtensionTS, ExtensionTSX, ExtensionYAML, ExtensionYML, ExtensionSQL, ExtensionProto, } // DefaultExtensionInjectionTemplates is a mapping between file extension (including the prefix dot) to the injection templates. DefaultExtensionInjectionTemplates = map[Extension]string{ ExtensionCSS: cssInjectionTemplate, ExtensionGo: goInjectionTemplate, ExtensionHTML: htmlInjectionTemplate, ExtensionJS: jsInjectionTemplate, ExtensionJSX: jsInjectionTemplate, ExtensionPy: pythonInjectionTemplate, ExtensionSASS: sassInjectionTemplate, ExtensionSCSS: scssInjectionTemplate, ExtensionTS: tsInjectionTemplate, ExtensionTSX: tsInjectionTemplate, ExtensionYAML: yamlInjectionTemplate, ExtensionYML: yamlInjectionTemplate, ExtensionSQL: sqlInjectionTemplate, ExtensionProto: protoInjectionTemplate, } // DefaultExcludes is the default excluded directories. DefaultExcludes = []string{ ".git/*", ".github/*", "*/_config", "*/_config/*", "*/dist/*", "*/node_modules/*", "*/testdata", "*/testdata/*", "*/vendor/*", "node_modules/*", "protogen/*", "*.pb.go", "vendor/*", "venv/*", "*/venv/*", ".vscode/*", "*/.vscode/*", "*/_nextjs/*", "*/_nextjs", "*/_public/*", "*/_public", "*/_dist/*", "*/_dist", } // DefaultIncludes is the default included files list. DefaultIncludes = []string{ "*.css", "*.go", "*.html", "*.js", "*.jsx", "*.py", "*.sass", "*.scss", "*.ts", "*.tsx", "*.yaml", "*.yml", "*.sql", "*.proto", } )
var ( ErrWalkSkip = errors.New("walk skip; we should not process this file or path") ErrFailure = errors.New("failure; one or more steps failed") )
Error sentinels
var (
ErrVerifyFormat = "%s: copyright header missing or invalid"
)
Error Strings
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // NoticeTemplate is the notice body template that will be processed and // injected to the relevant extension specific notice template. // // If omitted, a default template is used. NoticeTemplate string `yaml:"noticeBodyTemplate"` // Year is the year to insert into the templates as `{{ .Year }}` Year int `yaml:"year"` // CopyrightHolder is the company name to insert into the templates as `{{ .CopyrightHolder }}` CopyrightHolder string `yaml:"copyrightHolder"` // License is the open source license to insert into in templates as `{{ .License }}` License string `yaml:"openSourceLicense"` // Restrictions an optional template to clarify copyright restrictions or // visibility modifiers, which is available in the `NoticeBodyTemplate` as `{{ .Restrictions }}` RestrictionsTemplate string `yaml:"restrictionTemplate"` // Excludes are a list of globs to exclude, they can // match both files and directories. // // This can be populated with `.gitignore`, and `node_modules` and the like. Excludes []string `yaml:"excludes"` // Includes are a list of globs to match files to include. Includes []string `yaml:"includeFiles"` // ExtensionInjectionTemplates is a map between file extension (including dot prefix) // to the relevant full injection template for the file. It should include a template // variable reference {{ .Notice }} that will insert the compiled `NoticeTemplate`. ExtensionInjectionTemplates map[Extension]string // If we should print the intended actions but not perform them. DryRun bool `yaml:"dryRun"` // ExitFirst indicates if we should return after the first failure. ExitFirst bool `yaml:"exitFirst"` // Quiet controls whether output is suppressed. Quiet bool `yaml:"quiet"` // Verbose controls whether verbose output is shown. Verbose bool `yaml:"verbose"` // Debug controls whether debug output is shown. Debug bool `yaml:"debug"` // ShowDiff shows shows the diffs on verification failues. ShowDiff bool `yaml:"verifyDiff"` }
Config holds the runtime configuration option for the copyright engine.
func (Config) CopyrightHolderOrDefault ¶
CopyrightHolderOrDefault returns a copyright holder or a default.
func (Config) ExtensionInjectionTemplatesOrDefault ¶
ExtensionInjectionTemplatesOrDefault returns mapping between file extensions (including dot) to the notice templates (i.e. how the template should be fully formatted per file type).
func (Config) LicenseOrDefault ¶
LicenseOrDefault returns an open source license or a default.
func (Config) NoticeTemplateOrDefault ¶
NoticeTemplateOrDefault returns the notice template or a default.
func (Config) RestrictionsOrDefault ¶
RestrictionsOrDefault returns restrictions or a default.
func (Config) YearOrDefault ¶
YearOrDefault returns the current year or a default.
type Copyright ¶
type Copyright struct { // Config holds the configuration opitons. Config // Stdout is the writer for Verbose and Debug output. // If it is unset, `os.Stdout` will be used. Stdout io.Writer // Stderr is the writer for Error output. // If it is unset, `os.Stderr` will be used. Stderr io.Writer }
Copyright is the main type that injects, removes and verifies copyright headers.
func (Copyright) Inject ¶
Inject inserts the copyright header in any matching files that don't already have the copyright header.
func (Copyright) Remove ¶
Remove removes the copyright header in any matching files that have the copyright header.
type Extension ¶
type Extension string
Extension is a string enum for known extensions.
const ( ExtensionUnknown Extension = "" ExtensionCSS Extension = ".css" ExtensionGo Extension = ".go" ExtensionHTML Extension = ".html" ExtensionJS Extension = ".js" ExtensionJSX Extension = ".jsx" ExtensionPy Extension = ".py" ExtensionSASS Extension = ".sass" ExtensionSCSS Extension = ".scss" ExtensionTS Extension = ".ts" ExtensionTSX Extension = ".tsx" ExtensionYAML Extension = ".yaml" ExtensionYML Extension = ".yml" ExtensionSQL Extension = ".sql" ExtensionProto Extension = ".proto" )
Extensions