1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-24 03:47:45 +02:00
fix #808 by using the official regexp for directives
---------

Co-authored-by: chavacava <salvador.cavadini@gmail.com>
This commit is contained in:
chavacava 2024-05-10 12:11:05 +02:00 committed by GitHub
parent 582822e60a
commit 85333f8533
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View File

@ -20,12 +20,7 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) {
defer r.Unlock()
if r.allowList == nil {
r.allowList = []string{
"//go:",
"//revive:",
"//nolint:",
}
r.allowList = []string{}
for _, arg := range arguments {
allow, ok := arg.(string) // Alt. non panicking version
if !ok {
@ -87,5 +82,5 @@ func (r *CommentSpacingsRule) isAllowed(line string) bool {
}
}
return false
return isDirectiveComment(line)
}

View File

@ -165,3 +165,9 @@ func checkNumberOfArguments(expected int, args lint.Arguments, ruleName string)
panic(fmt.Sprintf("not enough arguments for %s rule, expected %d, got %d. Please check the rule's documentation", ruleName, expected, len(args)))
}
}
var directiveCommentRE = regexp.MustCompile("//(line |extern |export |[a-z0-9]+:[a-z0-9])") // see https://go-review.googlesource.com/c/website/+/442516/1..2/_content/doc/comment.md#494
func isDirectiveComment(line string) bool {
return directiveCommentRE.MatchString(line)
}

View File

@ -47,3 +47,8 @@ type c struct {
//+optional
d *int `json:"d,omitempty"`
}
//extern open
//export MyFunction
//nolint:gochecknoglobals