diff --git a/rule/comment-spacings.go b/rule/comment-spacings.go index 0a29b9659..bfb7eaf23 100644 --- a/rule/comment-spacings.go +++ b/rule/comment-spacings.go @@ -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) } diff --git a/rule/utils.go b/rule/utils.go index 5778e7696..8ffded4d1 100644 --- a/rule/utils.go +++ b/rule/utils.go @@ -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) +} diff --git a/testdata/comment-spacings.go b/testdata/comment-spacings.go index 92c832c2a..da8459b14 100644 --- a/testdata/comment-spacings.go +++ b/testdata/comment-spacings.go @@ -47,3 +47,8 @@ type c struct { //+optional d *int `json:"d,omitempty"` } + +//extern open +//export MyFunction + +//nolint:gochecknoglobals