copyright

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TemplateFieldYear            = "Year"
	TemplateFieldCopyrightHolder = "CopyrightHolder"
	TemplateFieldLicense         = "License"
	TemplateFieldRestrictions    = "Restrictions"
)
View Source
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!

View Source
const DefaultNoticeTemplate = `` /* 137-byte string literal not displayed */

DefaultNoticeBodyTemplate is the default notice body template.

View Source
const DefaultOpenSourceLicense = "MIT"

DefaultOpenSourceLicense is the default open source license.

View Source
const DefaultRestrictionsTemplate = `` /* 132-byte string literal not displayed */

DefaultRestrictionsOpenSource are the default open source restrictions.

View Source
const DefaultRestrictionsTemplateInternal = "{{ if .CopyrightHolder }}{{ .CopyrightHolder }} {{ end }}Confidential - Restricted"

DefaultRestrictionsTemplateInternal are the default copyright restrictions to inject into the notice template.

Variables

View Source
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",
	}
)
View Source
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

View Source
var (
	ErrVerifyFormat = "%s: copyright header missing or invalid"
)

Error Strings

Functions

This section is empty.

Types

type Action

type Action func(path string, info os.FileInfo, file, notice []byte) error

Action is the action to run.

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

func (c Config) CopyrightHolderOrDefault() string

CopyrightHolderOrDefault returns a copyright holder or a default.

func (Config) ExtensionInjectionTemplatesOrDefault

func (c Config) ExtensionInjectionTemplatesOrDefault() map[Extension]string

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

func (c Config) LicenseOrDefault() string

LicenseOrDefault returns an open source license or a default.

func (Config) NoticeTemplateOrDefault

func (c Config) NoticeTemplateOrDefault() string

NoticeTemplateOrDefault returns the notice template or a default.

func (Config) RestrictionsOrDefault

func (c Config) RestrictionsOrDefault() string

RestrictionsOrDefault returns restrictions or a default.

func (Config) YearOrDefault

func (c Config) YearOrDefault() int

YearOrDefault returns the current year or a default.

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) Debugf

func (c Copyright) Debugf(format string, args ...interface{})

Debugf writes to stdout if the `Debug` flag is true.

func (Copyright) Errorf

func (c Copyright) Errorf(format string, args ...interface{})

Errorf writes to stderr.

func (Copyright) GetStderr

func (c Copyright) GetStderr() io.Writer

GetStderr returns standard error.

func (Copyright) GetStdout

func (c Copyright) GetStdout() io.Writer

GetStdout returns standard out.

func (Copyright) Inject

func (c Copyright) Inject(ctx context.Context, root string) error

Inject inserts the copyright header in any matching files that don't already have the copyright header.

func (Copyright) Printf

func (c Copyright) Printf(format string, args ...interface{})

Printf writes to stdout.

func (Copyright) Remove

func (c Copyright) Remove(ctx context.Context, root string) error

Remove removes the copyright header in any matching files that have the copyright header.

func (Copyright) Verbosef

func (c Copyright) Verbosef(format string, args ...interface{})

Verbosef writes to stdout if the `Verbose` flag is true.

func (Copyright) Verify

func (c Copyright) Verify(ctx context.Context, root string) error

Verify asserts that the files found during walk have the copyright header.

func (Copyright) Walk

func (c Copyright) Walk(ctx context.Context, action Action, root string) error

Walk traverses the tree recursively from the root and applies the given action.

If the root is a file, it is handled singly and then walk will return.

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

Jump to

Keyboard shortcuts

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