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:
parent
582822e60a
commit
85333f8533
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
5
testdata/comment-spacings.go
vendored
5
testdata/comment-spacings.go
vendored
@ -47,3 +47,8 @@ type c struct {
|
||||
//+optional
|
||||
d *int `json:"d,omitempty"`
|
||||
}
|
||||
|
||||
//extern open
|
||||
//export MyFunction
|
||||
|
||||
//nolint:gochecknoglobals
|
||||
|
Loading…
x
Reference in New Issue
Block a user