Documentation
¶
Index ¶
- func Check(config *ConfigHeader, result *Result) error
- func CheckFile(file string, config *ConfigHeader, result *Result) error
- func DiffFile(file string, config *ConfigHeader) (string, error)
- func Fix(file string, config *ConfigHeader, result *Result) error
- func GenerateLicenseHeader(style *comments.CommentStyle, config *ConfigHeader) (string, error)
- func InsertComment(file string, style *comments.CommentStyle, config *ConfigHeader, ...) error
- func MatchPaths(file string, patterns []string) bool
- type CommentOption
- type ConfigHeader
- func (config *ConfigHeader) Finalize() error
- func (config *ConfigHeader) GetLicenseContent() (c string)
- func (config *ConfigHeader) LicensePattern(style *comments.CommentStyle) *regexp.Regexp
- func (config *ConfigHeader) NormalizedLicense() string
- func (config *ConfigHeader) NormalizedPattern() *regexp.Regexp
- func (config *ConfigHeader) ShouldIgnore(path string) (bool, error)
- type LicenseConfig
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(config *ConfigHeader, result *Result) error
Check checks the license headers of the specified paths/globs.
func CheckFile ¶
func CheckFile(file string, config *ConfigHeader, result *Result) error
CheckFile checks whether the file contains the configured license header.
func DiffFile ¶ added in v0.9.0
func DiffFile(file string, config *ConfigHeader) (string, error)
DiffFile compares the license header of the file with the license configured in the config file, and returns a word-level diff of the two normalized texts, the same texts that CheckFile compares, so every difference in the diff is a real cause of the check failure.
In the diff, [-text-] marks text that is expected by the configured license but missing in the file, and {+text+} marks text that is in the file but not expected by the configured license. An empty diff is returned when the file's license header is valid.
func Fix ¶
func Fix(file string, config *ConfigHeader, result *Result) error
Fix adds the configured license header to the given file.
func GenerateLicenseHeader ¶
func GenerateLicenseHeader(style *comments.CommentStyle, config *ConfigHeader) (string, error)
func InsertComment ¶
func InsertComment(file string, style *comments.CommentStyle, config *ConfigHeader, result *Result) error
func MatchPaths ¶ added in v0.9.0
Types ¶
type CommentOption ¶
type CommentOption string
var ( Always CommentOption = "always" Never CommentOption = "never" OnFailure CommentOption = "on-failure" ASFNames = regexp.MustCompile("(?i)(the )?(Apache Software Foundation|ASF)") )
type ConfigHeader ¶
type ConfigHeader struct {
License LicenseConfig `yaml:"license"`
Paths []string `yaml:"paths"`
PathsIgnore []string `yaml:"paths-ignore"`
Comment CommentOption `yaml:"comment"`
// LicenseLocationThreshold specifies the index threshold where the license header can be located,
// after all, a "header" cannot be TOO far from the file start.
LicenseLocationThreshold int `yaml:"license-location-threshold"`
Languages map[string]comments.Language `yaml:"language"`
}
func (*ConfigHeader) Finalize ¶
func (config *ConfigHeader) Finalize() error
func (*ConfigHeader) GetLicenseContent ¶
func (config *ConfigHeader) GetLicenseContent() (c string)
func (*ConfigHeader) LicensePattern ¶ added in v0.3.0
func (config *ConfigHeader) LicensePattern(style *comments.CommentStyle) *regexp.Regexp
func (*ConfigHeader) NormalizedLicense ¶
func (config *ConfigHeader) NormalizedLicense() string
NormalizedLicense returns the normalized string of the license content, "normalized" means the linebreaks and Punctuations are all trimmed.
func (*ConfigHeader) NormalizedPattern ¶
func (config *ConfigHeader) NormalizedPattern() *regexp.Regexp
func (*ConfigHeader) ShouldIgnore ¶
func (config *ConfigHeader) ShouldIgnore(path string) (bool, error)