1
0
Fork 0
forked from forgejo/forgejo

Rename scripts to build and add revive command as a new build tool command (#10942)

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
Lunny Xiao 2020-04-04 03:29:12 +08:00 committed by GitHub
parent 4af7c47b38
commit 4f63f283c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
182 changed files with 15832 additions and 1226 deletions

69
vendor/github.com/mgechev/revive/rule/file-header.go generated vendored Normal file
View file

@ -0,0 +1,69 @@
package rule
import (
"regexp"
"github.com/mgechev/revive/lint"
)
// FileHeaderRule lints given else constructs.
type FileHeaderRule struct{}
var (
multiRegexp = regexp.MustCompile("^/\\*")
singleRegexp = regexp.MustCompile("^//")
)
// Apply applies the rule to given file.
func (r *FileHeaderRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
if len(arguments) != 1 {
panic(`invalid configuration for "file-header" rule`)
}
header, ok := arguments[0].(string)
if !ok {
panic(`invalid argument for "file-header" rule: first argument should be a string`)
}
failure := []lint.Failure{
{
Node: file.AST,
Confidence: 1,
Failure: "the file doesn't have an appropriate header",
},
}
if len(file.AST.Comments) == 0 {
return failure
}
g := file.AST.Comments[0]
if g == nil {
return failure
}
comment := ""
for _, c := range g.List {
text := c.Text
if multiRegexp.Match([]byte(text)) {
text = text[2 : len(text)-2]
} else if singleRegexp.Match([]byte(text)) {
text = text[2:]
}
comment += text
}
regex, err := regexp.Compile(header)
if err != nil {
panic(err.Error())
}
if !regex.Match([]byte(comment)) {
return failure
}
return nil
}
// Name returns the rule name.
func (r *FileHeaderRule) Name() string {
return "file-header"
}