Expose license-location-threshold as config item (#34)
diff --git a/.licenserc.yaml b/.licenserc.yaml
index fbf15b1..af8bc1c 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -76,6 +76,10 @@
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.
+ # license-location-threshold specifies the index threshold where the license header can be located,
+ # after all, a "header" cannot be TOO far from the file start.
+ license-location-threshold: 80
+
dependency:
files:
- go.mod
diff --git a/pkg/header/check.go b/pkg/header/check.go
index b7b87c1..21bdb8d 100644
--- a/pkg/header/check.go
+++ b/pkg/header/check.go
@@ -31,12 +31,6 @@
"github.com/bmatcuk/doublestar/v2"
)
-var (
- // 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 = 80
-)
-
// Check checks the license headers of the specified paths/globs.
func Check(config *ConfigHeader, result *Result) error {
for _, pattern := range config.Paths {
@@ -129,7 +123,7 @@
content := lcs.NormalizeHeader(string(bs))
expected, pattern := config.NormalizedLicense(), config.NormalizedPattern()
- if satisfy(content, expected, pattern) {
+ if satisfy(content, config, expected, pattern) {
result.Succeed(file)
} else {
logger.Log.Debugln("Content is:", content)
@@ -140,9 +134,9 @@
return nil
}
-func satisfy(content, license string, pattern *regexp.Regexp) bool {
+func satisfy(content string, config *ConfigHeader, license string, pattern *regexp.Regexp) bool {
if index := strings.Index(content, license); strings.TrimSpace(license) != "" && index >= 0 {
- return index < LicenseLocationThreshold
+ return index < config.LicenseLocationThreshold
}
if pattern == nil {
@@ -150,5 +144,5 @@
}
index := pattern.FindStringIndex(content)
- return len(index) == 2 && index[0] < LicenseLocationThreshold
+ return len(index) == 2 && index[0] < config.LicenseLocationThreshold
}
diff --git a/pkg/header/config.go b/pkg/header/config.go
index b4f0700..6abb94a 100644
--- a/pkg/header/config.go
+++ b/pkg/header/config.go
@@ -56,6 +56,10 @@
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"`
}
// NormalizedLicense returns the normalized string of the license content,
@@ -120,6 +124,10 @@
logger.Log.Debugln("Pattern is:", p)
}
+ if config.LicenseLocationThreshold <= 0 {
+ config.LicenseLocationThreshold = 80
+ }
+
return nil
}